bootfromdevice.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/python3
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. #
  19. #
  20. import subprocess
  21. from . import utils
  22. from .firewall import *
  23. from .ui_bootfromdevice import *
  24. import qubesadmin.tools.qvm_start as qvm_start
  25. class VMBootFromDeviceWindow(Ui_BootDialog, QDialog):
  26. def __init__(self, vm, qapp, parent=None):
  27. super(VMBootFromDeviceWindow, self).__init__(parent)
  28. self.vm = vm
  29. self.qapp = qapp
  30. self.setupUi(self)
  31. self.setWindowTitle(self.tr("Boot {vm} from device").format(vm=self.vm.name))
  32. self.connect(self.buttonBox, SIGNAL("accepted()"), self.save_and_apply)
  33. self.connect(self.buttonBox, SIGNAL("rejected()"), self.reject)
  34. # populate buttons and such
  35. self.__init_buttons__()
  36. def reject(self):
  37. self.done(0)
  38. def save_and_apply(self):
  39. if self.blockDeviceRadioButton.isChecked():
  40. cdrom_location = self.blockDeviceComboBox.currentText()
  41. elif self.fileRadioButton.isChecked():
  42. cdrom_location = str(self.vm_list[self.fileVM.currentIndex()]) + ":" + self.pathText.text()
  43. else:
  44. QMessageBox.warning(None,
  45. self.tr(
  46. "ERROR!"),
  47. self.tr("No file or block device selected; please select one."))
  48. return
  49. qvm_start.main(['--cdrom', cdrom_location, self.vm.name])
  50. def __init_buttons__(self):
  51. self.fileVM.setEnabled(False)
  52. self.selectFileButton.setEnabled(False)
  53. self.blockDeviceComboBox.setEnabled(False)
  54. self.blockDeviceRadioButton.clicked.connect(self.radio_button_clicked)
  55. self.fileRadioButton.clicked.connect(self.radio_button_clicked)
  56. self.selectFileButton.clicked.connect(self.select_file_dialog)
  57. self.vm_list, self.vm_idx = utils.prepare_vm_choice(
  58. self.fileVM,
  59. self.vm, None,
  60. None,
  61. None,
  62. allow_default=False, allow_none=False)
  63. self.block_list, self.block_idx = utils.prepare_choice(
  64. self.blockDeviceComboBox,
  65. self.vm,
  66. None,
  67. [device for domain in self.vm.app.domains
  68. for device in domain.devices["block"]],
  69. None,
  70. None,
  71. allow_default=False, allow_none=False
  72. )
  73. def radio_button_clicked(self):
  74. self.blockDeviceComboBox.setEnabled(self.blockDeviceRadioButton.isChecked())
  75. self.fileVM.setEnabled(self.fileRadioButton.isChecked())
  76. self.selectFileButton.setEnabled(self.fileRadioButton.isChecked())
  77. self.pathText.setEnabled(self.fileRadioButton.isChecked())
  78. def select_file_dialog(self):
  79. backend_vm = self.vm_list[self.fileVM.currentIndex()]
  80. try:
  81. new_path = utils.get_path_from_vm(backend_vm, "qubes.SelectFile")
  82. except subprocess.CalledProcessError:
  83. new_path = None
  84. if new_path:
  85. self.pathText.setText(new_path)
  86. parser = qubesadmin.tools.QubesArgumentParser(vmname_nargs=1)
  87. def main(args=None):
  88. global bootfromdevice_window
  89. args = parser.parse_args(args)
  90. vm = args.domains.pop()
  91. qapp = QApplication(sys.argv)
  92. qapp.setOrganizationName('Invisible Things Lab')
  93. qapp.setOrganizationDomain("https://www.qubes-os.org/")
  94. qapp.setApplicationName("Qubes VM Settings")
  95. # if not utils.is_debug(): #FIXME
  96. # sys.excepthook = handle_exception
  97. bootfromdevice_window = VMBootFromDeviceWindow(vm, qapp)
  98. bootfromdevice_window.show()
  99. qapp.exec_()
  100. qapp.exit()
  101. if __name__ == "__main__":
  102. main()