common_threads.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 # pylint: disable=import-error
  22. from qubesadmin import exc
  23. # pylint: disable=too-few-public-methods
  24. class RemoveVMThread(QtCore.QThread):
  25. def __init__(self, vm):
  26. QtCore.QThread.__init__(self)
  27. self.vm = vm
  28. self.msg = None
  29. def run(self):
  30. try:
  31. del self.vm.app.domains[self.vm.name]
  32. except (exc.QubesException, KeyError) as ex:
  33. self.msg = ("Error removing qube!", str(ex))
  34. # pylint: disable=too-few-public-methods
  35. class CloneVMThread(QtCore.QThread):
  36. def __init__(self, src_vm, dst_name):
  37. QtCore.QThread.__init__(self)
  38. self.src_vm = src_vm
  39. self.dst_name = dst_name
  40. self.msg = None
  41. def run(self):
  42. try:
  43. self.src_vm.app.clone_vm(self.src_vm, self.dst_name)
  44. self.msg = ("Sucess", "The qube was cloned sucessfully.")
  45. except exc.QubesException as ex:
  46. self.msg = ("Error while cloning qube!", str(ex))