mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[mod] using yunohost format for config-panel arguments
This commit is contained in:
parent
e2f43b43a5
commit
8027e92683
1 changed files with 33 additions and 23 deletions
|
@ -1635,24 +1635,28 @@ def app_config_show_panel(app):
|
||||||
for section in tab.get("sections", []):
|
for section in tab.get("sections", []):
|
||||||
section_id = section["id"]
|
section_id = section["id"]
|
||||||
for option in section.get("options", []):
|
for option in section.get("options", []):
|
||||||
option_id = option["id"]
|
option_name = option["name"]
|
||||||
generated_id = ("YNH_CONFIG_%s_%s_%s" % (tab_id, section_id, option_id)).upper()
|
generated_name = ("YNH_CONFIG_%s_%s_%s" % (tab_id, section_id, option_name)).upper()
|
||||||
option["id"] = generated_id
|
option["name"] = generated_name
|
||||||
logger.debug(" * '%s'.'%s'.'%s' -> %s", tab.get("name"), section.get("name"), option.get("name"), generated_id)
|
logger.debug(" * '%s'.'%s'.'%s' -> %s", tab.get("name"), section.get("name"), option.get("name"), generated_name)
|
||||||
|
|
||||||
if generated_id in parsed_values:
|
if generated_name in parsed_values:
|
||||||
# XXX we should probably uses the one of install here but it's at a POC state right now
|
# code is not adapted for that so we have to mock expected format :/
|
||||||
option_type = option["type"]
|
if option.get("type") == "boolean":
|
||||||
if option_type == "bool":
|
if parsed_values[generated_name].lower() in ("true", "1", "y"):
|
||||||
assert parsed_values[generated_id].lower() in ("true", "false")
|
option["default"] = parsed_values[generated_name]
|
||||||
option["value"] = True if parsed_values[generated_id].lower() == "true" else False
|
else:
|
||||||
elif option_type == "integer":
|
del option["default"]
|
||||||
option["value"] = int(parsed_values[generated_id])
|
|
||||||
elif option_type == "text":
|
args_dict = _parse_args_in_yunohost_format(
|
||||||
option["value"] = parsed_values[generated_id]
|
[{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:
|
else:
|
||||||
logger.debug("Variable '%s' is not declared by config script, using default", generated_id)
|
logger.debug("Variable '%s' is not declared by config script, using default", generated_name)
|
||||||
option["value"] = option["default"]
|
option["default"] = option["default"]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"app_id": app_id,
|
"app_id": app_id,
|
||||||
|
@ -1685,26 +1689,29 @@ def app_config_apply(app, args):
|
||||||
"YNH_APP_INSTANCE_NUMBER": str(app_instance_nb),
|
"YNH_APP_INSTANCE_NUMBER": str(app_instance_nb),
|
||||||
}
|
}
|
||||||
args = dict(urlparse.parse_qsl(args, keep_blank_values=True)) if args else {}
|
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", []):
|
for tab in config_panel.get("panel", []):
|
||||||
tab_id = tab["id"] # this makes things easier to debug on crash
|
tab_id = tab["id"] # this makes things easier to debug on crash
|
||||||
for section in tab.get("sections", []):
|
for section in tab.get("sections", []):
|
||||||
section_id = section["id"]
|
section_id = section["id"]
|
||||||
for option in section.get("options", []):
|
for option in section.get("options", []):
|
||||||
option_id = option["id"]
|
option_name = option["name"]
|
||||||
generated_id = ("YNH_CONFIG_%s_%s_%s" % (tab_id, section_id, option_id)).upper()
|
generated_name = ("YNH_CONFIG_%s_%s_%s" % (tab_id, section_id, option_name)).upper()
|
||||||
|
|
||||||
if generated_id in args:
|
if generated_name in args:
|
||||||
logger.debug("include into env %s=%s", generated_id, args[generated_id])
|
logger.debug("include into env %s=%s", generated_name, args[generated_name])
|
||||||
env[generated_id] = args[generated_id]
|
env[generated_name] = args[generated_name]
|
||||||
else:
|
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 debug purpose
|
||||||
for key in args:
|
for key in args:
|
||||||
if key not in env:
|
if key not in env:
|
||||||
logger.warning("Ignore key '%s' from arguments because it is not in the config", key)
|
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,
|
return_code = hook_exec(config_script,
|
||||||
args=["apply"],
|
args=["apply"],
|
||||||
env=env,
|
env=env,
|
||||||
|
@ -1824,7 +1831,10 @@ def _get_app_config_panel(app_id):
|
||||||
|
|
||||||
for option_key, option_value in options:
|
for option_key, option_value in options:
|
||||||
option = dict(option_value)
|
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)
|
section["options"].append(option)
|
||||||
|
|
||||||
panel["sections"].append(section)
|
panel["sections"].append(section)
|
||||||
|
|
Loading…
Add table
Reference in a new issue