common_threads.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/python3
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2018 Donoban <donoban@riseup.net>
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License
  9. # as published by the Free Software Foundation; either version 2
  10. # of the License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public License along
  18. # with this program; if not, see <http://www.gnu.org/licenses/>.
  19. #
  20. #
  21. from PyQt4 import QtCore, QtGui # pylint: disable=import-error
  22. from contextlib import contextmanager
  23. from qubesadmin import exc
  24. @contextmanager
  25. def busy_cursor():
  26. try:
  27. QtGui.QApplication.setOverrideCursor(QtCore.Qt.BusyCursor)
  28. yield
  29. finally:
  30. QtGui.QApplication.restoreOverrideCursor()
  31. # pylint: disable=too-few-public-methods
  32. class RemoveVMThread(QtCore.QThread):
  33. def __init__(self, vm):
  34. QtCore.QThread.__init__(self)
  35. self.vm = vm
  36. self.msg = None
  37. def run(self):
  38. try:
  39. del self.vm.app.domains[self.vm.name]
  40. except (exc.QubesException, KeyError) as ex:
  41. self.msg = ("Error removing qube!", str(ex))
  42. # pylint: disable=too-few-public-methods
  43. class CloneVMThread(QtCore.QThread):
  44. def __init__(self, src_vm, dst_name):
  45. QtCore.QThread.__init__(self)
  46. self.src_vm = src_vm
  47. self.dst_name = dst_name
  48. self.msg = None
  49. def run(self):
  50. try:
  51. self.src_vm.app.clone_vm(self.src_vm, self.dst_name)
  52. self.msg = ("Sucess", "The qube was cloned sucessfully.")
  53. except exc.QubesException as ex:
  54. self.msg = ("Error while cloning qube!", str(ex))