From 811e95f5611f4c7a2d23fffee2de58a09d997657 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 18 Aug 2022 22:10:30 -0700 Subject: [PATCH] setup: Implement operation to uninstall an app Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/setup.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/plinth/setup.py b/plinth/setup.py index d303e63a2..0a9449377 100644 --- a/plinth/setup.py +++ b/plinth/setup.py @@ -92,6 +92,50 @@ def _run_setup_on_app(app, current_version): operation.on_update(message, exception_to_update) +def run_uninstall_on_app(app_id): + """Execute the uninstall process in a thread.""" + # App is already uninstalled + app = app_module.App.get(app_id) + if not app.get_setup_version(): + return + + logger.debug('Creating operation to uninstall app: %s', app_id) + return operation_module.manager.new(app_id, + gettext_noop('Uninstalling app'), + _run_uninstall_on_app, [app], + show_notification=True) + + +def _run_uninstall_on_app(app): + """Execute the uninstall process.""" + logger.info('Uninstall run: %s', app.app_id) + exception_to_update = None + message = None + try: + app.disable() + app.uninstall() + app.set_setup_version(0) + except PackageException as exception: + exception_to_update = exception + error_string = getattr(exception, 'error_string', str(exception)) + error_details = getattr(exception, 'error_details', '') + message = gettext_noop('Error uninstalling app: {string} ' + '{details}').format(string=error_string, + details=error_details) + + except Exception as exception: + exception_to_update = exception + message = gettext_noop('Error uninstalling app: {error}').format( + error=exception) + else: + message = gettext_noop('App uninstalled.') + + logger.info('Uninstall completed: %s: %s %s', app.app_id, message, + exception_to_update) + operation = operation_module.Operation.get_operation() + operation.on_update(message, exception_to_update) + + def stop(): """Set a flag to indicate that the setup process must stop.""" global _is_shutting_down