diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index 807311e..edde03f 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -961,7 +961,13 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow): settings_window = settings.VMSettingsWindow( vm, self.qt_app, "basic") settings_window.exec_() - self.vms_in_table[vm.qid].update() + + # vm could be deleted on renaming + try: + self.vms_in_table[vm.qid].update() + except exc.QubesPropertyAccessError: + pass + # noinspection PyArgumentList @QtCore.pyqtSlot(name='on_action_appmenus_triggered') diff --git a/qubesmanager/table_widgets.py b/qubesmanager/table_widgets.py index 5ccdb49..a22f909 100644 --- a/qubesmanager/table_widgets.py +++ b/qubesmanager/table_widgets.py @@ -24,6 +24,8 @@ from PyQt4 import QtGui # pylint: disable=import-error from PyQt4 import QtCore # pylint: disable=import-error # pylint: disable=too-few-public-methods +from qubesadmin import exc + power_order = QtCore.Qt.DescendingOrder update_order = QtCore.Qt.AscendingOrder @@ -74,13 +76,16 @@ class VmTypeWidget(VmIconWidget): self.value = value def __lt__(self, other): - if self.vm.qid == 0: - return True - elif other.vm.qid == 0: + try: + if self.vm.qid == 0: + return True + elif other.vm.qid == 0: + return False + elif self.value == other.value: + return self.vm.name < other.vm.name + return self.value < other.value + except exc.QubesPropertyAccessError: return False - elif self.value == other.value: - return self.vm.name < other.vm.name - return self.value < other.value def __init__(self, vm, parent=None): (icon_path, tooltip) = self.get_vm_icon(vm) @@ -120,13 +125,16 @@ class VmLabelWidget(VmIconWidget): self.value = value def __lt__(self, other): - if self.vm.qid == 0: - return True - elif other.vm.qid == 0: + try: + if self.vm.qid == 0: + return True + elif other.vm.qid == 0: + return False + elif self.value == other.value: + return self.vm.name < other.vm.name + return self.value < other.value + except exc.QubesPropertyAccessError: return False - elif self.value == other.value: - return self.vm.name < other.vm.name - return self.value < other.value def __init__(self, vm, parent=None): icon_path = self.get_vm_icon_path(vm) @@ -149,11 +157,14 @@ class VmNameItem(QtGui.QTableWidgetItem): self.qid = vm.qid def __lt__(self, other): - if self.qid == 0: - return True - elif other.qid == 0: + try: + if self.qid == 0: + return True + elif other.qid == 0: + return False + return super(VmNameItem, self).__lt__(other) + except exc.QubesPropertyAccessError: return False - return super(VmNameItem, self).__lt__(other) class VmStatusIcon(QtGui.QLabel): @@ -193,9 +204,12 @@ class VmInfoWidget(QtGui.QWidget): def __lt__(self, other): # pylint: disable=too-many-return-statements - if self.vm.qid == 0: - return True - elif other.vm.qid == 0: + try: + if self.vm.qid == 0: + return True + elif other.vm.qid == 0: + return False + except exc.QubesPropertyAccessError: return False self_val = self.upd_info_item.value @@ -278,13 +292,16 @@ class VmTemplateItem(QtGui.QTableWidgetItem): self.setText(self.vm.klass) def __lt__(self, other): - if self.vm.qid == 0: - return True - elif other.vm.qid == 0: + try: + if self.vm.qid == 0: + return True + elif other.vm.qid == 0: + return False + elif self.text() == other.text(): + return self.vm.name < other.vm.name + return super(VmTemplateItem, self).__lt__(other) + except exc.QubesPropertyAccessError: return False - elif self.text() == other.text(): - return self.vm.name < other.vm.name - return super(VmTemplateItem, self).__lt__(other) class VmNetvmItem(QtGui.QTableWidgetItem): @@ -302,13 +319,16 @@ class VmNetvmItem(QtGui.QTableWidgetItem): self.setText(self.vm.netvm.name) def __lt__(self, other): - if self.vm.qid == 0: - return True - elif other.vm.qid == 0: + try: + if self.vm.qid == 0: + return True + elif other.vm.qid == 0: + return False + elif self.text() == other.text(): + return self.vm.name < other.vm.name + return super(VmNetvmItem, self).__lt__(other) + except exc.QubesPropertyAccessError: return False - elif self.text() == other.text(): - return self.vm.name < other.vm.name - return super(VmNetvmItem, self).__lt__(other) class VmInternalItem(QtGui.QTableWidgetItem): @@ -325,11 +345,14 @@ class VmInternalItem(QtGui.QTableWidgetItem): def __lt__(self, other): - if self.vm.qid == 0: - return True - elif other.vm.qid == 0: + try: + if self.vm.qid == 0: + return True + elif other.vm.qid == 0: + return False + return super(VmInternalItem, self).__lt__(other) + except exc.QubesPropertyAccessError: return False - return super(VmInternalItem, self).__lt__(other) # features man qvm-features @@ -350,13 +373,16 @@ class VmUpdateInfoWidget(QtGui.QWidget): self.value = 0 def __lt__(self, other): - if self.vm.qid == 0: - return True - elif other.vm.qid == 0: + try: + if self.vm.qid == 0: + return True + elif other.vm.qid == 0: + return False + elif self.value == other.value: + return self.vm.name < other.vm.name + return self.value < other.value + except exc.QubesPropertyAccessError: return False - elif self.value == other.value: - return self.vm.name < other.vm.name - return self.value < other.value def __init__(self, vm, show_text=True, parent=None): super(VmUpdateInfoWidget, self).__init__(parent) @@ -457,13 +483,16 @@ class VmSizeOnDiskItem(QtGui.QTableWidgetItem): self.setText(str(self.value) + " MiB") def __lt__(self, other): - if self.vm.qid == 0: - return True - elif other.vm.qid == 0: + try: + if self.vm.qid == 0: + return True + elif other.vm.qid == 0: + return False + elif self.value == other.value: + return self.vm.name < other.vm.name + return self.value < other.value + except exc.QubesPropertyAccessError: return False - elif self.value == other.value: - return self.vm.name < other.vm.name - return self.value < other.value class VmIPItem(QtGui.QTableWidgetItem): @@ -479,11 +508,14 @@ class VmIPItem(QtGui.QTableWidgetItem): self.setText(self.ip if self.ip is not None else 'n/a') def __lt__(self, other): - if self.vm.qid == 0: - return True - elif other.vm.qid == 0: + try: + if self.vm.qid == 0: + return True + elif other.vm.qid == 0: + return False + return super(VmIPItem, self).__lt__(other) + except exc.QubesPropertyAccessError: return False - return super(VmIPItem, self).__lt__(other) class VmIncludeInBackupsItem(QtGui.QTableWidgetItem): @@ -501,13 +533,16 @@ class VmIncludeInBackupsItem(QtGui.QTableWidgetItem): self.setText("") def __lt__(self, other): - if self.vm.qid == 0: - return True - elif other.vm.qid == 0: + try: + if self.vm.qid == 0: + return True + elif other.vm.qid == 0: + return False + elif self.vm.include_in_backups == other.vm.include_in_backups: + return self.vm.name < other.vm.name + return self.vm.include_in_backups < other.vm.include_in_backups + except exc.QubesPropertyAccessError: return False - elif self.vm.include_in_backups == other.vm.include_in_backups: - return self.vm.name < other.vm.name - return self.vm.include_in_backups < other.vm.include_in_backups class VmLastBackupItem(QtGui.QTableWidgetItem): @@ -528,14 +563,17 @@ class VmLastBackupItem(QtGui.QTableWidgetItem): self.setText("") def __lt__(self, other): - if self.vm.qid == 0: - return True - elif other.vm.qid == 0: + try: + if self.vm.qid == 0: + return True + elif other.vm.qid == 0: + return False + elif self.backup_timestamp == other.backup_timestamp: + return self.vm.name < other.vm.name + elif not self.backup_timestamp: + return False + elif not other.backup_timestamp: + return True + return self.backup_timestamp < other.backup_timestamp + except exc.QubesPropertyAccessError: return False - elif self.backup_timestamp == other.backup_timestamp: - return self.vm.name < other.vm.name - elif not self.backup_timestamp: - return False - elif not other.backup_timestamp: - return True - return self.backup_timestamp < other.backup_timestamp