From e63510b4cf30ec9c9071b42544023feea625da7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Pierret=20=28fepitre=29?= Date: Sun, 20 Oct 2019 15:11:24 +0200 Subject: [PATCH] guivm: use getattr instead of try/except and direct property access --- qubesadmin/tools/qvm_start_gui.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/qubesadmin/tools/qvm_start_gui.py b/qubesadmin/tools/qvm_start_gui.py index bfbb567..45357d7 100644 --- a/qubesadmin/tools/qvm_start_gui.py +++ b/qubesadmin/tools/qvm_start_gui.py @@ -252,9 +252,10 @@ class GUILauncher(object): one for target AppVM is running. :param monitor_layout: monitor layout configuration """ - if vm.guivm != vm.app.get_local_name(): + guivm_name = getattr(vm, 'guivm', None) + if guivm_name != vm.app.get_local_name(): vm.log.info( - '{} has GuiVM {}. Skipping.'.format(vm.name, vm.guivm)) + '{} has GuiVM {}. Skipping.'.format(vm.name, guivm_name)) return if vm.virt_mode == 'hvm': @@ -316,7 +317,7 @@ class GUILauncher(object): """Send monitor layout to all (running) VMs""" monitor_layout = get_monitor_layout() for vm in self.app.domains: - if vm.guivm != vm.app.get_local_name(): + if getattr(vm, 'guivm', None) != vm.app.get_local_name(): continue if vm.klass == 'AdminVM': continue @@ -329,7 +330,7 @@ class GUILauncher(object): def on_domain_spawn(self, vm, _event, **kwargs): """Handler of 'domain-spawn' event, starts GUI daemon for stubdomain""" try: - if vm.guivm != vm.app.get_local_name(): + if getattr(vm, 'guivm', None) != vm.app.get_local_name(): return if not vm.features.check_with_template('gui', True): return @@ -342,7 +343,7 @@ class GUILauncher(object): def on_domain_start(self, vm, _event, **kwargs): """Handler of 'domain-start' event, starts GUI daemon for actual VM""" try: - if vm.guivm != vm.app.get_local_name(): + if getattr(vm, 'guivm', None) != vm.app.get_local_name(): return if not vm.features.check_with_template('gui', True): return @@ -360,10 +361,7 @@ class GUILauncher(object): for vm in self.app.domains: if vm.klass == 'AdminVM': continue - try: - if vm.guivm != vm.app.get_local_name(): - continue - except qubesadmin.exc.QubesPropertyAccessError: + if getattr(vm, 'guivm', None) != vm.app.get_local_name(): continue if not vm.features.check_with_template('gui', True): continue