bootfromdevice.py 4.3 KB

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