bootfromdevice.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 Lesser General Public License along
  16. # with this program; if not, see <http://www.gnu.org/licenses/>.
  17. #
  18. #
  19. import sys
  20. import subprocess
  21. from . import utils
  22. from . import ui_bootfromdevice # pylint: disable=no-name-in-module
  23. from PyQt4 import QtGui, QtCore # pylint: disable=import-error
  24. from qubesadmin import tools
  25. class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog, QtGui.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(
  32. self.tr("Boot {vm} from device").format(vm=self.vm.name))
  33. self.connect(
  34. self.buttonBox,
  35. QtCore.SIGNAL("accepted()"),
  36. self.save_and_apply)
  37. self.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject)
  38. # populate buttons and such
  39. self.__init_buttons__()
  40. def reject(self):
  41. self.done(0)
  42. def save_and_apply(self):
  43. if self.blockDeviceRadioButton.isChecked():
  44. cdrom_location = self.blockDeviceComboBox.currentText()
  45. elif self.fileRadioButton.isChecked():
  46. cdrom_location = str(
  47. self.vm_list[self.fileVM.currentIndex()]) + \
  48. ":" + self.pathText.text()
  49. else:
  50. QtGui.QMessageBox.warning(
  51. None,
  52. self.tr("ERROR!"),
  53. self.tr("No file or block device selected; please select one."))
  54. return
  55. tools.qvm_start.main(['--cdrom', cdrom_location, self.vm.name])
  56. def __init_buttons__(self):
  57. self.fileVM.setEnabled(False)
  58. self.selectFileButton.setEnabled(False)
  59. self.blockDeviceComboBox.setEnabled(False)
  60. self.blockDeviceRadioButton.clicked.connect(self.radio_button_clicked)
  61. self.fileRadioButton.clicked.connect(self.radio_button_clicked)
  62. self.selectFileButton.clicked.connect(self.select_file_dialog)
  63. self.vm_list, self.vm_idx = utils.prepare_vm_choice(
  64. self.fileVM,
  65. self.vm, None,
  66. None,
  67. None,
  68. allow_default=False, allow_none=False)
  69. self.block_list, self.block_idx = utils.prepare_choice(
  70. self.blockDeviceComboBox,
  71. self.vm,
  72. None,
  73. [device for domain in self.vm.app.domains
  74. for device in domain.devices["block"]],
  75. None,
  76. None,
  77. allow_default=False, allow_none=False
  78. )
  79. def radio_button_clicked(self):
  80. self.blockDeviceComboBox.setEnabled(
  81. self.blockDeviceRadioButton.isChecked())
  82. self.fileVM.setEnabled(self.fileRadioButton.isChecked())
  83. self.selectFileButton.setEnabled(self.fileRadioButton.isChecked())
  84. self.pathText.setEnabled(self.fileRadioButton.isChecked())
  85. def select_file_dialog(self):
  86. backend_vm = self.vm_list[self.fileVM.currentIndex()]
  87. try:
  88. new_path = utils.get_path_from_vm(backend_vm, "qubes.SelectFile")
  89. except subprocess.CalledProcessError:
  90. new_path = None
  91. if new_path:
  92. self.pathText.setText(new_path)
  93. parser = tools.QubesArgumentParser(vmname_nargs=1)
  94. def main(args=None):
  95. args = parser.parse_args(args)
  96. vm = args.domains.pop()
  97. qapp = QtGui.QApplication(sys.argv)
  98. qapp.setOrganizationName('Invisible Things Lab')
  99. qapp.setOrganizationDomain("https://www.qubes-os.org/")
  100. qapp.setApplicationName("Qubes VM Settings")
  101. # if not utils.is_debug(): #FIXME
  102. # sys.excepthook = handle_exception
  103. bootfromdevice_window = VMBootFromDeviceWindow(vm, qapp)
  104. bootfromdevice_window.show()
  105. qapp.exec_()
  106. qapp.exit()
  107. if __name__ == "__main__":
  108. main()