restore.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/usr/bin/python2.6
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2012 Agnieszka Kostrzewa <agnieszka.kostrzewa@gmail.com>
  6. # Copyright (C) 2012 Marek Marczykowski <marmarek@mimuw.edu.pl>
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. #
  22. #
  23. import sys
  24. import os
  25. from PyQt4.QtCore import *
  26. from PyQt4.QtGui import *
  27. from qubes.qubes import QubesVmCollection
  28. from qubes.qubes import QubesException
  29. from qubes.qubes import QubesDaemonPidfile
  30. from qubes.qubes import QubesHost
  31. import qubesmanager.resources_rc
  32. from pyinotify import WatchManager, Notifier, ThreadedNotifier, EventsCodes, ProcessEvent
  33. import subprocess
  34. import time
  35. import threading
  36. from operator import itemgetter
  37. from ui_restoredlg import *
  38. from multiselectwidget import *
  39. class RestoreVMsWindow(Ui_Restore, QWizard):
  40. def __init__(self, parent=None):
  41. super(RestoreVMsWindow, self).__init__(parent)
  42. self.setupUi(self)
  43. self.selectVMsWidget = MultiSelectWidget(self)
  44. self.selectVMsLayout.insertWidget(1, self.selectVMsWidget)
  45. self.selectVMsWidget.available_list.addItem("netVM1")
  46. self.selectVMsWidget.available_list.addItem("appVM1")
  47. self.selectVMsWidget.available_list.addItem("appVM2")
  48. self.selectVMsWidget.available_list.addItem("templateVM1")
  49. self.connect(self, SIGNAL("currentIdChanged(int)"), self.current_page_changed)
  50. def reject(self):
  51. self.done(0)
  52. def save_and_apply(self):
  53. pass
  54. def current_page_changed(self, id):
  55. self.button(self.CancelButton).setDisabled(id==3)
  56. @pyqtSlot(name='on_selectPathButton_clicked')
  57. def selectPathButton_clicked(self):
  58. self.path = self.pathLineEdit.text()
  59. newPath = QFileDialog.getExistingDirectory(self, 'Select backup directory.')
  60. if newPath:
  61. self.pathLineEdit.setText(newPath)
  62. self.path = newPath
  63. # Bases on the original code by:
  64. # Copyright (c) 2002-2007 Pascal Varet <p.varet@gmail.com>
  65. def handle_exception( exc_type, exc_value, exc_traceback ):
  66. import sys
  67. import os.path
  68. import traceback
  69. filename, line, dummy, dummy = traceback.extract_tb( exc_traceback ).pop()
  70. filename = os.path.basename( filename )
  71. error = "%s: %s" % ( exc_type.__name__, exc_value )
  72. QMessageBox.critical(None, "Houston, we have a problem...",
  73. "Whoops. A critical error has occured. This is most likely a bug "
  74. "in Qubes Restore VMs application.<br><br>"
  75. "<b><i>%s</i></b>" % error +
  76. "at <b>line %d</b> of file <b>%s</b>.<br/><br/>"
  77. % ( line, filename ))
  78. def main():
  79. global qubes_host
  80. qubes_host = QubesHost()
  81. global app
  82. app = QApplication(sys.argv)
  83. app.setOrganizationName("The Qubes Project")
  84. app.setOrganizationDomain("http://qubes-os.org")
  85. app.setApplicationName("Qubes Restore VMs")
  86. sys.excepthook = handle_exception
  87. qvm_collection = QubesVmCollection()
  88. qvm_collection.lock_db_for_reading()
  89. qvm_collection.load()
  90. qvm_collection.unlock_db()
  91. global restore_window
  92. restore_window = RestoreVMsWindow()
  93. restore_window.show()
  94. app.exec_()
  95. app.exit()
  96. if __name__ == "__main__":
  97. main()