From 2978df56fb0d93ea6f00048c690ad9ecf7adef10 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Mon, 29 Jul 2019 22:58:05 +0200 Subject: [PATCH] [enh] integrate actions/config-panel into operation_logs --- src/yunohost/app.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 73ec43adb..649955e9f 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -1466,7 +1466,8 @@ def app_action_list(app): } -def app_action_run(app, action, args=None): +@is_unit_operation() +def app_action_run(operation_logger, app, action, args=None): logger.warning(m18n.n('experimental_feature')) from yunohost.hook import hook_exec @@ -1479,6 +1480,8 @@ def app_action_run(app, action, args=None): if action not in actions: raise YunohostError("action '%s' not available for app '%s', available actions are: %s" % (action, app, ", ".join(actions.keys())), raw_msg=True) + operation_logger.start() + action_declaration = actions[action] # Retrieve arguments list for install script @@ -1515,17 +1518,21 @@ def app_action_run(app, action, args=None): )[0] if retcode not in action_declaration.get("accepted_return_codes", [0]): - raise YunohostError("Error while executing action '%s' of app '%s': return code %s" % (action, app, retcode), raw_msg=True) + msg = "Error while executing action '%s' of app '%s': return code %s" % (action, app, retcode) + operation_logger.error(msg) + raise YunohostError(msg, raw_msg=True) os.remove(path) + operation_logger.success() return logger.success("Action successed!") # Config panel todo list: # * docstrings # * merge translations on the json once the workflow is in place -def app_config_show_panel(app): +@is_unit_operation() +def app_config_show_panel(operation_logger, app): logger.warning(m18n.n('experimental_feature')) from yunohost.hook import hook_exec @@ -1533,6 +1540,7 @@ def app_config_show_panel(app): # this will take care of checking if the app is installed app_info_dict = app_info(app) + operation_logger.start() config_panel = _get_app_config_panel(app) config_script = os.path.join(APPS_SETTING_PATH, app, 'scripts', 'config') @@ -1596,10 +1604,12 @@ def app_config_show_panel(app): "app": app, "app_name": app_info_dict["name"], "config_panel": config_panel, + "logs": operation_logger.success(), } -def app_config_apply(app, args): +@is_unit_operation() +def app_config_apply(operation_logger, app, args): logger.warning(m18n.n('experimental_feature')) from yunohost.hook import hook_exec @@ -1615,6 +1625,7 @@ def app_config_apply(app, args): # XXX real exception raise Exception("Not config-panel.json nor scripts/config") + operation_logger.start() app_id, app_instance_nb = _parse_app_instance_name(app) env = { "YNH_APP_ID": app_id, @@ -1648,9 +1659,14 @@ def app_config_apply(app, args): )[0] if return_code != 0: - raise Exception("'script/config apply' return value code: %s (considered as an error)", return_code) + msg = "'script/config apply' return value code: %s (considered as an error)" % return_code + operation_logger.error(msg) + raise Exception(msg) logger.success("Config updated as expected") + return { + "logs": operation_logger.success(), + } def _get_app_actions(app_id):