From 07162ba089d7daa43e707c30d6ca32894d7fe4e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 7 Oct 2017 00:22:41 +0200 Subject: [PATCH 1/2] use 'klass' property instead of actual VM object class The later is going to be generic QubesVM class, to save admin.vm.List calls. --- qubesmanager/create_new_vm.py | 2 +- qubesmanager/global_settings.py | 3 +-- qubesmanager/settings.py | 6 +++--- qubesmanager/utils.py | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/qubesmanager/create_new_vm.py b/qubesmanager/create_new_vm.py index 856bc4b..f75debc 100644 --- a/qubesmanager/create_new_vm.py +++ b/qubesmanager/create_new_vm.py @@ -63,7 +63,7 @@ class NewVmDlg(QDialog, Ui_NewVMDlg): self.template_vm, self.app, None, self.app.default_template, - (lambda vm: isinstance(vm, qubesadmin.vm.TemplateVM)), + (lambda vm: vm.klass == 'TemplateVM'), allow_internal=False, allow_default=True, allow_none=False) self.netvm_list, self.netvm_idx = utils.prepare_vm_choice( diff --git a/qubesmanager/global_settings.py b/qubesmanager/global_settings.py index 61451a9..eaf009f 100644 --- a/qubesmanager/global_settings.py +++ b/qubesmanager/global_settings.py @@ -32,7 +32,6 @@ from .ui_globalsettingsdlg import * from configparser import ConfigParser from qubesadmin.utils import parse_size, updates_vms_status -from qubesadmin.vm import TemplateVM qmemman_config_path = '/etc/qubes/qmemman.conf' @@ -104,7 +103,7 @@ class GlobalSettingsWindow(Ui_GlobalSettings, QDialog): self.default_netvm_combo.setCurrentIndex(self.netvm_idx) #default template - templates = [vm for vm in all_vms if isinstance(vm, TemplateVM)] + templates = [vm for vm in all_vms if vm.klass == 'TemplateVM'] self.template_idx = -1 current_template = self.qvm_collection.default_template diff --git a/qubesmanager/settings.py b/qubesmanager/settings.py index 79d9a18..ce4afc8 100755 --- a/qubesmanager/settings.py +++ b/qubesmanager/settings.py @@ -248,12 +248,12 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog): self.vmlabel.setVisible(True) self.vmlabel.setEnabled(not self.vm.is_running()) - if isinstance(self.vm, qubesadmin.vm.AppVM): + if self.vm.klass == 'AppVM': self.template_list, self.template_idx = utils.prepare_vm_choice( self.template_name, self.vm, 'template', self.vm.app.default_template, - (lambda vm: isinstance(vm, qubesadmin.vm.TemplateVM)), + (lambda vm: vm.klass == 'TemplateVM'), allow_default=True, allow_none=False) else: self.template_name.setEnabled(False) @@ -476,7 +476,7 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog): self.default_dispvm, self.vm, 'default_dispvm', self.vm.app.default_dispvm, - (lambda vm: isinstance(vm, qubesadmin.vm.DispVM)), + (lambda vm: vm.klass == 'DispVM'), allow_default=True, allow_none=True) def __apply_advanced_tab__(self): diff --git a/qubesmanager/utils.py b/qubesmanager/utils.py index abb0dcd..cbe8777 100644 --- a/qubesmanager/utils.py +++ b/qubesmanager/utils.py @@ -28,7 +28,7 @@ import qubesadmin from PyQt4.QtGui import QIcon def _filter_internal(vm): - return (not isinstance(vm, qubesadmin.vm.AdminVM) + return (not vm.klass == 'AdminVM' and not vm.features.get('internal', False)) def prepare_choice(widget, holder, propname, choice, default, From 4d3a992ac6373183689efed74eadd7acc7397fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 7 Oct 2017 00:23:37 +0200 Subject: [PATCH 2/2] Fix setting kernel property Fixes QubesOS/qubes-issues#3145 --- qubesmanager/settings.py | 18 +----------------- qubesmanager/utils.py | 2 +- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/qubesmanager/settings.py b/qubesmanager/settings.py index ce4afc8..629ca5b 100755 --- a/qubesmanager/settings.py +++ b/qubesmanager/settings.py @@ -504,23 +504,7 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog): if hasattr(self.vm, "kernel") and self.kernel_groupbox.isVisible(): try: if self.kernel.currentIndex() != self.kernel_idx: - new_kernel = str(self.kernel.currentText()) - new_kernel = new_kernel.split(' ')[0] - uses_default_kernel = False - - if new_kernel == "default": - kernel = self.app.get_default_kernel() - uses_default_kernel = True - elif new_kernel == "none": - kernel = None - else: - kernel = new_kernel - - self.vm.kernel = kernel - # Set self.vm.uses_default_kernel after self.vm.kernel to ensure that - # the correct value persists after QubesVm.kernel resets self.vm.uses_default_kernel - # to False. - self.vm.uses_default_kernel = uses_default_kernel + self.vm.kernel = self.kernel_list[self.kernel.currentIndex()] self.anything_changed = True except Exception as ex: msg.append(str(ex)) diff --git a/qubesmanager/utils.py b/qubesmanager/utils.py index cbe8777..cca3647 100644 --- a/qubesmanager/utils.py +++ b/qubesmanager/utils.py @@ -87,7 +87,7 @@ def prepare_choice(widget, holder, propname, choice, default, text = str(item) if item is qubesadmin.DEFAULT and is_default \ - or item is not qubesadmin.DEFAULT and item is oldvalue: + or item is not qubesadmin.DEFAULT and item == oldvalue: text += ' (current)' idx = i