setup: Implement operation to uninstall an app

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2022-08-18 22:10:30 -07:00 committed by James Valleroy
parent a1c6c7b6a7
commit 811e95f561
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -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