From f30c0282892c87d7fe61c84bf03b0b5f5dd0796c Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 28 Apr 2023 15:09:51 -0700 Subject: [PATCH] zoph: Don't fail at showing app view during uninstall During uninstall step, zoph command may not be available and is_configured() may error out. In such cases, let the base class AppView show the operations view. Tests: - Introduce a sleep in overridden uninstall() method for zoph. Notice that there is an error showing the view during uninstall. Apply patch and the error is no longer shown. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/zoph/privileged.py | 12 ++++++++---- plinth/modules/zoph/views.py | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/plinth/modules/zoph/privileged.py b/plinth/modules/zoph/privileged.py index eb555f44b..65f342281 100644 --- a/plinth/modules/zoph/privileged.py +++ b/plinth/modules/zoph/privileged.py @@ -90,11 +90,15 @@ def set_configuration(enable_osm: Optional[bool] = None, @privileged -def is_configured() -> bool: +def is_configured() -> Optional[bool]: """Return whether zoph app is configured.""" - process = subprocess.run(['zoph', '--get-config', 'interface.user.remote'], - stdout=subprocess.PIPE, check=True) - return process.stdout.decode().strip() == 'true' + try: + process = subprocess.run( + ['zoph', '--get-config', 'interface.user.remote'], + stdout=subprocess.PIPE, check=True) + return process.stdout.decode().strip() == 'true' + except FileNotFoundError: + return None @privileged diff --git a/plinth/modules/zoph/views.py b/plinth/modules/zoph/views.py index f7689de9e..f646f5de6 100644 --- a/plinth/modules/zoph/views.py +++ b/plinth/modules/zoph/views.py @@ -48,9 +48,12 @@ class ZophAppView(views.AppView): def dispatch(self, request, *args, **kwargs): """Redirect to setup page if setup is not done yet.""" - if not privileged.is_configured(): + is_configured = privileged.is_configured() + if is_configured is False: return redirect('zoph:setup') + # During operations such as uninstall, zoph command may not be + # available, let the base class show operations view instead. return super().dispatch(request, *args, **kwargs) def get_initial(self):