From 46972788b2f4c3b3ac79e2d2fb9b8dd6a3834148 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 14 Dec 2018 15:05:56 +0100 Subject: [PATCH 1/2] Add comment about the motivation behind YunohostError --- src/yunohost/utils/error.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/yunohost/utils/error.py b/src/yunohost/utils/error.py index 7c00ee5a4..a3842547e 100644 --- a/src/yunohost/utils/error.py +++ b/src/yunohost/utils/error.py @@ -23,7 +23,12 @@ from moulinette.core import MoulinetteError from moulinette import m18n class YunohostError(MoulinetteError): - """Yunohost base exception""" + """ + Yunohost base exception + + The (only?) main difference with MoulinetteError being that keys + are translated via m18n.n (namespace) instead of m18n.g (global?) + """ def __init__(self, key, __raw_msg__=False, *args, **kwargs): if __raw_msg__: msg = key From 7e3a90232f79b576c654bf26ee001631c5ef0dee Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 14 Dec 2018 14:17:20 +0000 Subject: [PATCH 2/2] __raw_msg__ -> raw_msg --- src/yunohost/app.py | 12 ++++++------ src/yunohost/utils/error.py | 6 +++--- src/yunohost/utils/yunopaste.py | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 36a0414ec..935b1ea6b 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -183,7 +183,7 @@ def app_fetchlist(url=None, name=None): with open(list_file, "w") as f: f.write(appslist) except Exception as e: - raise YunohostError("Error while writing appslist %s: %s" % (name, str(e)), __raw_msg__=True) + raise YunohostError("Error while writing appslist %s: %s" % (name, str(e)), raw_msg=True) now = int(time.time()) appslists[name]["lastUpdate"] = now @@ -840,9 +840,9 @@ def app_install(operation_logger, auth, app, label=None, args=None, no_remove_on if install_retcode == -1: msg = m18n.n('operation_interrupted') + " " + error_msg - raise YunohostError(msg, __raw_msg__=True) + raise YunohostError(msg, raw_msg=True) msg = error_msg - raise YunohostError(msg, __raw_msg__=True) + raise YunohostError(msg, raw_msg=True) # Clean hooks and add new ones hook_remove(app_instance_name) @@ -1472,7 +1472,7 @@ def app_action_run(app, action, args=None): actions = {x["id"]: x for x in actions} 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) + raise YunohostError("action '%s' not available for app '%s', available actions are: %s" % (action, app, ", ".join(actions.keys())), raw_msg=True) action_declaration = actions[action] @@ -1510,7 +1510,7 @@ def app_action_run(app, action, args=None): ) 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) + raise YunohostError("Error while executing action '%s' of app '%s': return code %s" % (action, app, retcode), raw_msg=True) os.remove(path) @@ -2431,7 +2431,7 @@ def _write_appslist_list(appslist_lists): json.dump(appslist_lists, f) except Exception as e: raise YunohostError("Error while writing list of appslist %s: %s" % - (APPSLISTS_JSON, str(e)), __raw_msg__=True) + (APPSLISTS_JSON, str(e)), raw_msg=True) def _register_new_appslist(url, name): diff --git a/src/yunohost/utils/error.py b/src/yunohost/utils/error.py index a3842547e..74a63db7c 100644 --- a/src/yunohost/utils/error.py +++ b/src/yunohost/utils/error.py @@ -29,10 +29,10 @@ class YunohostError(MoulinetteError): The (only?) main difference with MoulinetteError being that keys are translated via m18n.n (namespace) instead of m18n.g (global?) """ - def __init__(self, key, __raw_msg__=False, *args, **kwargs): - if __raw_msg__: + def __init__(self, key, raw_msg=False, *args, **kwargs): + if raw_msg: msg = key else: msg = m18n.n(key, *args, **kwargs) - super(YunohostError, self).__init__(msg, __raw_msg__=True) + super(YunohostError, self).__init__(msg, raw_msg=True) diff --git a/src/yunohost/utils/yunopaste.py b/src/yunohost/utils/yunopaste.py index 436f94911..9226a7b12 100644 --- a/src/yunohost/utils/yunopaste.py +++ b/src/yunohost/utils/yunopaste.py @@ -12,14 +12,14 @@ def yunopaste(data): try: r = requests.post("%s/documents" % paste_server, data=data, timeout=30) except Exception as e: - raise YunohostError("Something wrong happened while trying to paste data on paste.yunohost.org : %s" % str(e), __raw_msg__=True) + raise YunohostError("Something wrong happened while trying to paste data on paste.yunohost.org : %s" % str(e), raw_msg=True) if r.status_code != 200: - raise YunohostError("Something wrong happened while trying to paste data on paste.yunohost.org : %s, %s" % (r.status_code, r.text), __raw_msg__=True) + raise YunohostError("Something wrong happened while trying to paste data on paste.yunohost.org : %s, %s" % (r.status_code, r.text), raw_msg=True) try: url = json.loads(r.text)["key"] except: - raise YunohostError("Uhoh, couldn't parse the answer from paste.yunohost.org : %s" % r.text, __raw_msg__=True) + raise YunohostError("Uhoh, couldn't parse the answer from paste.yunohost.org : %s" % r.text, raw_msg=True) return "%s/raw/%s" % (paste_server, url)