formatting

This commit is contained in:
Marek Marczykowski-Górecki 2016-07-01 03:09:27 +02:00
parent ff72077674
commit f7b558c55e
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -256,12 +256,14 @@ class VmShutdownMonitor(QObject):
def check_if_vm_has_shutdown(self): def check_if_vm_has_shutdown(self):
vm = self.vm vm = self.vm
vm_start_time = vm.get_start_time() vm_start_time = vm.get_start_time()
if vm.is_running() and vm_start_time and vm_start_time < self.shutdown_started: if vm.is_running() and vm_start_time and \
if (datetime.now()-self.shutdown_started) > timedelta(milliseconds=self.shutdown_time): vm_start_time < self.shutdown_started:
if (datetime.now() - self.shutdown_started) > \
timedelta(milliseconds=self.shutdown_time):
reply = QMessageBox.question( reply = QMessageBox.question(
None, "VM Shutdown", None, "VM Shutdown",
"The VM <b>'{0}'</b> hasn't shutdown within the last {1} seconds, " "The VM <b>'{0}'</b> hasn't shutdown within the last "
"do you want to kill it?<br>".format( "{1} seconds, do you want to kill it?<br>".format(
vm.name, self.shutdown_time / 1000), vm.name, self.shutdown_time / 1000),
"Kill it!", "Kill it!",
"Wait another {0} seconds...".format( "Wait another {0} seconds...".format(
@ -274,9 +276,11 @@ class VmShutdownMonitor(QObject):
else: else:
# noinspection PyTypeChecker,PyCallByClass # noinspection PyTypeChecker,PyCallByClass
self.shutdown_started = datetime.now() self.shutdown_started = datetime.now()
QTimer.singleShot(self.check_time, self.check_if_vm_has_shutdown) QTimer.singleShot(self.check_time,
self.check_if_vm_has_shutdown)
else: else:
QTimer.singleShot(self.check_time, self.check_if_vm_has_shutdown) QTimer.singleShot(self.check_time,
self.check_if_vm_has_shutdown)
else: else:
if self.and_restart: if self.and_restart:
@ -1270,7 +1274,8 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow):
if reply == QMessageBox.Yes: if reply == QMessageBox.Yes:
self.shutdown_vm(vm) self.shutdown_vm(vm)
def shutdown_vm(self, vm, shutdown_time=vm_shutdown_timeout, check_time=vm_restart_check_timeout, and_restart=False): def shutdown_vm(self, vm, shutdown_time=vm_shutdown_timeout,
check_time=vm_restart_check_timeout, and_restart=False):
try: try:
vm.shutdown() vm.shutdown()
except Exception as ex: except Exception as ex:
@ -1281,12 +1286,12 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow):
trayIcon.showMessage("VM '{0}' is shutting down...".format(vm.name), trayIcon.showMessage("VM '{0}' is shutting down...".format(vm.name),
msecs=3000) msecs=3000)
self.shutdown_monitor[vm.qid] = VmShutdownMonitor(vm, shutdown_time, check_time, and_restart, self) self.shutdown_monitor[vm.qid] = VmShutdownMonitor(vm, shutdown_time,
check_time, and_restart, self)
# noinspection PyCallByClass,PyTypeChecker # noinspection PyCallByClass,PyTypeChecker
QTimer.singleShot(check_time, self.shutdown_monitor[ QTimer.singleShot(check_time, self.shutdown_monitor[
vm.qid].check_if_vm_has_shutdown) vm.qid].check_if_vm_has_shutdown)
@pyqtSlot(name='on_action_restartvm_triggered') @pyqtSlot(name='on_action_restartvm_triggered')
def action_restartvm_triggered(self): def action_restartvm_triggered(self):
vm = self.get_selected_vm() vm = self.get_selected_vm()