mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #981 from YunoHost/default_questions_for_app_args
Default 'ask' questions for common app manifest args
This commit is contained in:
commit
1ef1dbf564
3 changed files with 64 additions and 3 deletions
|
@ -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 {app:s} in the list of installed apps: {all_apps}",
|
||||
|
|
|
@ -90,6 +90,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"]:
|
||||
|
@ -109,7 +111,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")
|
||||
|
@ -169,6 +170,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, _ = _parse_app_instance_name(app)
|
||||
|
@ -2094,12 +2096,62 @@ 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"), # i18n: app_manifest_install_ask_domain
|
||||
("path", "path"), # i18n: app_manifest_install_ask_path
|
||||
("password", "password"), # i18n: app_manifest_install_ask_password
|
||||
("user", "admin"), # i18n: app_manifest_install_ask_admin
|
||||
("boolean", "is_public")] # i18n: app_manifest_install_ask_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'):
|
||||
"""
|
||||
|
|
|
@ -23,8 +23,10 @@ def find_expected_string_keys():
|
|||
# Try to find :
|
||||
# m18n.n( "foo"
|
||||
# YunohostError("foo"
|
||||
# # i18n: foo
|
||||
p1 = re.compile(r'm18n\.n\(\s*[\"\'](\w+)[\"\']')
|
||||
p2 = re.compile(r'YunohostError\([\'\"](\w+)[\'\"]')
|
||||
p3 = re.compile(r'# i18n: [\'\"]?(\w+)[\'\"]?')
|
||||
|
||||
python_files = glob.glob("src/yunohost/*.py")
|
||||
python_files.extend(glob.glob("src/yunohost/utils/*.py"))
|
||||
|
@ -42,6 +44,8 @@ def find_expected_string_keys():
|
|||
if m.endswith("_"):
|
||||
continue
|
||||
yield m
|
||||
for m in p3.findall(content):
|
||||
yield m
|
||||
|
||||
# For each diagnosis, try to find strings like "diagnosis_stuff_foo" (c.f. diagnosis summaries)
|
||||
# Also we expect to have "diagnosis_description_<name>" for each diagnosis
|
||||
|
|
Loading…
Add table
Reference in a new issue