Default 'ask' questions for common app manifest args

This commit is contained in:
Alexandre Aubin 2020-05-06 21:41:54 +02:00
parent 42bc8c354a
commit c7dd881774
2 changed files with 61 additions and 3 deletions

View file

@ -27,6 +27,11 @@
"app_make_default_location_already_used": "Can't make the app '{app}' the default on the domain, '{domain}' is already in use by the other app '{other_app}'",
"app_location_unavailable": "This URL is either unavailable, or conflicts with the already installed app(s):\n{apps:s}",
"app_manifest_invalid": "Something is wrong with the app manifest: {error}",
"app_manifest_install_ask_domain": "Choose the domain where this app should be installed",
"app_manifest_install_ask_path": "Choose the path where this app should be installed",
"app_manifest_install_ask_password": "Choose an administration password for this app",
"app_manifest_install_ask_admin": "Choose an administrator user for this app",
"app_manifest_install_ask_is_public": "Should this app be exposed to anonymous visitors?",
"app_not_upgraded": "The app '{failed_app}' failed to upgrade, and as a consequence the following apps' upgrades have been cancelled: {apps}",
"app_not_correctly_installed": "{app:s} seems to be incorrectly installed",
"app_not_installed": "Could not find the app '{app:s}' in the list of installed apps: {all_apps}",

View file

@ -91,6 +91,8 @@ def app_catalog(full=False, with_categories=False):
"description": infos['manifest']['description'],
"level": infos["level"],
}
else:
infos["manifest"]["arguments"] = _set_default_ask_questions(infos["manifest"]["arguments"])
# Trim info for categories if not using --full
for category in catalog["categories"]:
@ -110,7 +112,6 @@ def app_catalog(full=False, with_categories=False):
return {"apps": catalog["apps"], "categories": catalog["categories"]}
# Old legacy function...
def app_fetchlist():
logger.warning("'yunohost app fetchlist' is deprecated. Please use 'yunohost tools update --apps' instead")
@ -170,6 +171,7 @@ def app_info(app, full=False):
return ret
ret["manifest"] = local_manifest
ret["manifest"]["arguments"] = _set_default_ask_questions(ret["manifest"]["arguments"])
ret['settings'] = settings
absolute_app_name = app if "__" not in app else app[:app.index('__')] # idk this is the name of the app even for multiinstance apps (so wordpress__2 -> wordpress)
@ -2071,12 +2073,63 @@ def _get_manifest_of_app(path):
manifest["arguments"]["install"] = install_arguments
return manifest
elif os.path.exists(os.path.join(path, "manifest.json")):
return read_json(os.path.join(path, "manifest.json"))
manifest = read_json(os.path.join(path, "manifest.json"))
else:
raise YunohostError("There doesn't seem to be any manifest file in %s ... It looks like an app was not correctly installed/removed." % path, raw_msg=True)
manifest["arguments"] = _set_default_ask_questions(manifest["arguments"])
return manifest
def _set_default_ask_questions(arguments):
# arguments is something like
# { "install": [
# { "name": "domain",
# "type": "domain",
# ....
# },
# { "name": "path",
# "type": "path"
# ...
# },
# ...
# ],
# "upgrade": [ ... ]
# }
# We set a default for any question with these matching (type, name)
# type namei
# N.B. : this is only for install script ... should be reworked for other
# scripts if we supports args for other scripts in the future...
questions_with_default = [("domain", "domain"),
("path", "path"),
("password", "password"),
("user", "admin"),
("boolean", "is_public")]
for script_name, arg_list in arguments.items():
# We only support questions for install so far, and for other
if script_name != "install":
continue
for arg in arg_list:
# Do not override 'ask' field if provided by app ?... Or shall we ?
#if "ask" in arg:
# continue
# If this arg corresponds to a question with default ask message...
if any((arg.get("type"), arg["name"]) == question for question in questions_with_default):
# The key is for example "app_manifest_install_ask_domain"
key = "app_manifest_%s_ask_%s" % (script_name, arg["name"])
arg["ask"] = m18n.n(key)
return arguments
def _get_git_last_commit_hash(repository, reference='HEAD'):
"""