From a42602f740a6f4bf3d750ee8b6641e4545929f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 15 May 2024 16:07:38 +0200 Subject: [PATCH 1/2] Do not react to events when running in "offline mode" In practice, do not modify system state when running unit tests. --- qubesappmenusext/__init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/qubesappmenusext/__init__.py b/qubesappmenusext/__init__.py index edcf55a..0254291 100644 --- a/qubesappmenusext/__init__.py +++ b/qubesappmenusext/__init__.py @@ -157,18 +157,24 @@ async def remove_from_disk(self, vm, event): @qubes.ext.handler('property-set:label') def label_setter(self, vm, event, **kwargs): + if vm.app.vmm.offline_mode: + return self.collect_done_tasks(vm) self.vm_tasks[vm.name].append( asyncio.ensure_future(self.update_appmenus(vm))) @qubes.ext.handler('property-set:provides_network') def provides_network_setter(self, vm, event, **kwargs): + if vm.app.vmm.offline_mode: + return self.collect_done_tasks(vm) self.vm_tasks[vm.name].append( asyncio.ensure_future(self.update_appmenus(vm))) @qubes.ext.handler('property-set:guivm') def provides_network_setter(self, vm, event, name, newvalue, oldvalue=None): + if vm.app.vmm.offline_mode: + return self.collect_done_tasks(vm) if oldvalue and oldvalue != newvalue: self.vm_tasks[vm.name].append( @@ -178,6 +184,8 @@ def provides_network_setter(self, vm, event, name, newvalue, oldvalue=None): @qubes.ext.handler('domain-feature-delete:appmenus-dispvm') def on_feature_del_appmenus_dispvm(self, vm, event, feature): + if vm.app.vmm.offline_mode: + return self.collect_done_tasks(vm) self.vm_tasks[vm.name].append( asyncio.ensure_future(self.update_appmenus(vm))) @@ -185,6 +193,8 @@ def on_feature_del_appmenus_dispvm(self, vm, event, feature): @qubes.ext.handler('domain-feature-set:appmenus-dispvm') def on_feature_set_appmenus_dispvm(self, vm, event, feature, value, oldvalue=None): + if vm.app.vmm.offline_mode: + return self.collect_done_tasks(vm) self.vm_tasks[vm.name].append( asyncio.ensure_future(self.update_appmenus(vm))) @@ -192,12 +202,16 @@ def on_feature_set_appmenus_dispvm(self, vm, event, feature, @qubes.ext.handler('domain-feature-set:menu-items') def on_feature_set_appmenus_dispvm(self, vm, event, feature, value, oldvalue=None): + if vm.app.vmm.offline_mode: + return self.collect_done_tasks(vm) self.vm_tasks[vm.name].append( asyncio.ensure_future(self.update_appmenus(vm))) @qubes.ext.handler('domain-feature-delete:internal') def on_feature_del_internal(self, vm, event, feature): + if vm.app.vmm.offline_mode: + return self.collect_done_tasks(vm) self.vm_tasks[vm.name].append( asyncio.ensure_future(self.update_appmenus(vm))) @@ -205,6 +219,8 @@ def on_feature_del_internal(self, vm, event, feature): @qubes.ext.handler('domain-feature-set:internal') def on_feature_set_internal(self, vm, event, feature, value, oldvalue=None): + if vm.app.vmm.offline_mode: + return self.collect_done_tasks(vm) if value: self.vm_tasks[vm.name].append( From 1b1bba143fc7386959203e3515ec6793494ba176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 15 May 2024 18:26:42 +0200 Subject: [PATCH 2/2] Make pylint happy Make it clearer about unreachable state - parser.error() raises an exception. --- qubesappmenus/receive.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qubesappmenus/receive.py b/qubesappmenus/receive.py index 4037b7a..e7ef4ef 100755 --- a/qubesappmenus/receive.py +++ b/qubesappmenus/receive.py @@ -392,6 +392,8 @@ def main(args=None): vm = args.app.domains[env_vmname] elif not args.domains: parser.error("You must specify at least the VM name!") + # pylint doesn't know parser.error doesn't return + assert False else: vm = args.domains[0]