From e2f43b43a50924bdbf329b4462b499c497694a5c Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sun, 2 Jun 2019 04:45:49 +0200 Subject: [PATCH 1/5] [fix] make function name clearer, it's not only for actions --- src/yunohost/app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 4323a5410..38f62d51d 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -2278,7 +2278,7 @@ def _parse_args_from_manifest(manifest, action, args={}): return OrderedDict() action_args = manifest['arguments'][action] - return _parse_action_args_in_yunohost_format(args, action_args) + return _parse_args_in_yunohost_format(args, action_args) def _parse_args_for_action(action, args={}): @@ -2302,10 +2302,10 @@ def _parse_args_for_action(action, args={}): action_args = action['arguments'] - return _parse_action_args_in_yunohost_format(args, action_args) + return _parse_args_in_yunohost_format(args, action_args) -def _parse_action_args_in_yunohost_format(args, action_args): +def _parse_args_in_yunohost_format(args, action_args): """Parse arguments store in either manifest.json or actions.json """ from yunohost.domain import (domain_list, _get_maindomain, From 8027e9268373410cb11989cf21c6e37624742471 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 4 Jun 2019 19:47:16 +0200 Subject: [PATCH 2/5] [mod] using yunohost format for config-panel arguments --- src/yunohost/app.py | 56 ++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 38f62d51d..a200ecae1 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -1635,24 +1635,28 @@ def app_config_show_panel(app): for section in tab.get("sections", []): section_id = section["id"] for option in section.get("options", []): - option_id = option["id"] - generated_id = ("YNH_CONFIG_%s_%s_%s" % (tab_id, section_id, option_id)).upper() - option["id"] = generated_id - logger.debug(" * '%s'.'%s'.'%s' -> %s", tab.get("name"), section.get("name"), option.get("name"), generated_id) + option_name = option["name"] + generated_name = ("YNH_CONFIG_%s_%s_%s" % (tab_id, section_id, option_name)).upper() + option["name"] = generated_name + logger.debug(" * '%s'.'%s'.'%s' -> %s", tab.get("name"), section.get("name"), option.get("name"), generated_name) - if generated_id in parsed_values: - # XXX we should probably uses the one of install here but it's at a POC state right now - option_type = option["type"] - if option_type == "bool": - assert parsed_values[generated_id].lower() in ("true", "false") - option["value"] = True if parsed_values[generated_id].lower() == "true" else False - elif option_type == "integer": - option["value"] = int(parsed_values[generated_id]) - elif option_type == "text": - option["value"] = parsed_values[generated_id] + if generated_name in parsed_values: + # code is not adapted for that so we have to mock expected format :/ + if option.get("type") == "boolean": + if parsed_values[generated_name].lower() in ("true", "1", "y"): + option["default"] = parsed_values[generated_name] + else: + del option["default"] + + args_dict = _parse_args_in_yunohost_format( + [{option["name"]: parsed_values[generated_name]}], + [option] + ) + print("%s ----> %s ----> %s" % (option["name"], repr(option.get("default", "[removed -> false]")), args_dict[option["name"]])) + option["default"] = args_dict[option["name"]] else: - logger.debug("Variable '%s' is not declared by config script, using default", generated_id) - option["value"] = option["default"] + logger.debug("Variable '%s' is not declared by config script, using default", generated_name) + option["default"] = option["default"] return { "app_id": app_id, @@ -1685,26 +1689,29 @@ def app_config_apply(app, args): "YNH_APP_INSTANCE_NUMBER": str(app_instance_nb), } args = dict(urlparse.parse_qsl(args, keep_blank_values=True)) if args else {} + print(json.dumps(args, sort_keys=True, indent=4)) + print("------------------------------------------") for tab in config_panel.get("panel", []): tab_id = tab["id"] # this makes things easier to debug on crash for section in tab.get("sections", []): section_id = section["id"] for option in section.get("options", []): - option_id = option["id"] - generated_id = ("YNH_CONFIG_%s_%s_%s" % (tab_id, section_id, option_id)).upper() + option_name = option["name"] + generated_name = ("YNH_CONFIG_%s_%s_%s" % (tab_id, section_id, option_name)).upper() - if generated_id in args: - logger.debug("include into env %s=%s", generated_id, args[generated_id]) - env[generated_id] = args[generated_id] + if generated_name in args: + logger.debug("include into env %s=%s", generated_name, args[generated_name]) + env[generated_name] = args[generated_name] else: - logger.debug("no value for key id %s", generated_id) + logger.debug("no value for key id %s", generated_name) # for debug purpose for key in args: if key not in env: logger.warning("Ignore key '%s' from arguments because it is not in the config", key) + print(json.dumps(env, sort_keys=True, indent=4)) return_code = hook_exec(config_script, args=["apply"], env=env, @@ -1824,7 +1831,10 @@ def _get_app_config_panel(app_id): for option_key, option_value in options: option = dict(option_value) - option["id"] = option_key + option["name"] = option_key + option["ask"] = {"en": option["ask"]} + if "help" in option: + option["help"] = {"en": option["help"]} section["options"].append(option) panel["sections"].append(section) From 7db63b82218858ee4c1d27c8971129a1d971d2bb Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 25 Jun 2019 05:19:30 +0200 Subject: [PATCH 3/5] [enh] handle other kinds of type than boolean in config panel --- src/yunohost/app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index a200ecae1..8e047169c 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -1647,6 +1647,8 @@ def app_config_show_panel(app): option["default"] = parsed_values[generated_name] else: del option["default"] + else: + option["default"] = parsed_values[generated_name] args_dict = _parse_args_in_yunohost_format( [{option["name"]: parsed_values[generated_name]}], From b23296be3cbb97220e788cd5a46c662b77bb22fc Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 25 Jun 2019 05:37:12 +0200 Subject: [PATCH 4/5] [fix] remove useless line that could generate bugs --- src/yunohost/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 8e047169c..11d9b735b 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -1658,7 +1658,7 @@ def app_config_show_panel(app): option["default"] = args_dict[option["name"]] else: logger.debug("Variable '%s' is not declared by config script, using default", generated_name) - option["default"] = option["default"] + # do nothing, we'll use the default if present return { "app_id": app_id, From a18f1f784e215a24f6e99a3da6d1d5675da999d0 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sat, 29 Jun 2019 06:03:05 +0200 Subject: [PATCH 5/5] [mod] remove debug stuff --- src/yunohost/app.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 11d9b735b..cad528795 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -1654,7 +1654,6 @@ def app_config_show_panel(app): [{option["name"]: parsed_values[generated_name]}], [option] ) - print("%s ----> %s ----> %s" % (option["name"], repr(option.get("default", "[removed -> false]")), args_dict[option["name"]])) option["default"] = args_dict[option["name"]] else: logger.debug("Variable '%s' is not declared by config script, using default", generated_name) @@ -1691,8 +1690,6 @@ def app_config_apply(app, args): "YNH_APP_INSTANCE_NUMBER": str(app_instance_nb), } args = dict(urlparse.parse_qsl(args, keep_blank_values=True)) if args else {} - print(json.dumps(args, sort_keys=True, indent=4)) - print("------------------------------------------") for tab in config_panel.get("panel", []): tab_id = tab["id"] # this makes things easier to debug on crash @@ -1713,7 +1710,6 @@ def app_config_apply(app, args): if key not in env: logger.warning("Ignore key '%s' from arguments because it is not in the config", key) - print(json.dumps(env, sort_keys=True, indent=4)) return_code = hook_exec(config_script, args=["apply"], env=env,