2018-11-18 20:22:27 +01:00
|
|
|
#!/usr/bin/python3
|
2018-10-20 18:34:15 +02:00
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
2018-11-18 20:22:27 +01:00
|
|
|
# Copyright (C) 2018 Donoban <donoban@riseup.net>
|
2018-10-20 18:34:15 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
# with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
from PyQt5 import QtCore, QtWidgets # pylint: disable=import-error
|
2019-03-31 19:56:01 +02:00
|
|
|
from contextlib import contextmanager
|
|
|
|
|
2018-10-20 18:34:15 +02:00
|
|
|
from qubesadmin import exc
|
|
|
|
|
|
|
|
|
2019-03-31 19:56:01 +02:00
|
|
|
@contextmanager
|
|
|
|
def busy_cursor():
|
|
|
|
try:
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.BusyCursor)
|
2019-03-31 19:56:01 +02:00
|
|
|
yield
|
|
|
|
finally:
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QApplication.restoreOverrideCursor()
|
2019-03-31 19:56:01 +02:00
|
|
|
|
|
|
|
|
2018-10-22 10:14:26 +02:00
|
|
|
# pylint: disable=too-few-public-methods
|
2019-04-03 20:34:01 +02:00
|
|
|
class QubesThread(QtCore.QThread):
|
2018-10-20 18:34:15 +02:00
|
|
|
def __init__(self, vm):
|
|
|
|
QtCore.QThread.__init__(self)
|
|
|
|
self.vm = vm
|
2018-10-22 20:00:37 +02:00
|
|
|
self.msg = None
|
2019-04-03 20:34:01 +02:00
|
|
|
self.msg_is_success = False
|
2018-10-20 18:34:15 +02:00
|
|
|
|
2019-04-03 20:34:01 +02:00
|
|
|
|
|
|
|
# pylint: disable=too-few-public-methods
|
|
|
|
class RemoveVMThread(QubesThread):
|
2018-10-20 18:34:15 +02:00
|
|
|
def run(self):
|
|
|
|
try:
|
|
|
|
del self.vm.app.domains[self.vm.name]
|
2018-11-18 20:23:26 +01:00
|
|
|
except (exc.QubesException, KeyError) as ex:
|
|
|
|
self.msg = ("Error removing qube!", str(ex))
|
2018-10-20 18:34:15 +02:00
|
|
|
|
|
|
|
|
2018-10-22 10:14:26 +02:00
|
|
|
# pylint: disable=too-few-public-methods
|
2019-04-03 20:34:01 +02:00
|
|
|
class CloneVMThread(QubesThread):
|
|
|
|
def __init__(self, vm, dst_name):
|
|
|
|
super(CloneVMThread, self).__init__(vm)
|
2018-10-20 18:34:15 +02:00
|
|
|
self.dst_name = dst_name
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
try:
|
2019-04-03 20:34:01 +02:00
|
|
|
self.vm.app.clone_vm(self.vm, self.dst_name)
|
2018-10-22 20:00:37 +02:00
|
|
|
self.msg = ("Sucess", "The qube was cloned sucessfully.")
|
2019-04-03 20:34:01 +02:00
|
|
|
self.msg_is_success = True
|
2018-10-20 18:34:15 +02:00
|
|
|
except exc.QubesException as ex:
|
2018-11-18 20:25:41 +01:00
|
|
|
self.msg = ("Error while cloning qube!", str(ex))
|