mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
manifestv2: drafty implementation for notifications/doc inside the manifest
This commit is contained in:
parent
3675daf26d
commit
dd6c8976f8
2 changed files with 52 additions and 1 deletions
51
src/app.py
51
src/app.py
|
@ -23,6 +23,7 @@
|
|||
|
||||
Manage apps
|
||||
"""
|
||||
import glob
|
||||
import os
|
||||
import toml
|
||||
import json
|
||||
|
@ -174,6 +175,9 @@ def app_info(app, full=False, upgradable=False):
|
|||
|
||||
ret["setting_path"] = setting_path
|
||||
ret["manifest"] = local_manifest
|
||||
|
||||
# FIXME: maybe this is not needed ? default ask questions are
|
||||
# already set during the _get_manifest_of_app earlier ?
|
||||
ret["manifest"]["install"] = _set_default_ask_questions(
|
||||
ret["manifest"].get("install", {})
|
||||
)
|
||||
|
@ -181,6 +185,13 @@ def app_info(app, full=False, upgradable=False):
|
|||
|
||||
ret["from_catalog"] = from_catalog
|
||||
|
||||
# Hydrate app notifications and doc
|
||||
for pagename, pagecontent in ret["manifest"]["doc"].items():
|
||||
ret["manifest"]["doc"][pagename] = _hydrate_app_template(pagecontent, settings)
|
||||
for step, notifications in ret["manifest"]["notifications"].items():
|
||||
for name, notification in notifications.items():
|
||||
notifications[name] = _hydrate_app_template(notification, settings)
|
||||
|
||||
ret["is_webapp"] = "domain" in settings and "path" in settings
|
||||
|
||||
if ret["is_webapp"]:
|
||||
|
@ -1954,9 +1965,49 @@ def _get_manifest_of_app(path):
|
|||
manifest = _convert_v1_manifest_to_v2(manifest)
|
||||
|
||||
manifest["install"] = _set_default_ask_questions(manifest.get("install", {}))
|
||||
manifest["doc"], manifest["notifications"] = _parse_app_doc_and_notifications(path)
|
||||
|
||||
return manifest
|
||||
|
||||
|
||||
def _parse_app_doc_and_notifications(path):
|
||||
|
||||
# FIXME: need to find a way to handle i18n in there (file named FOOBAR_fr.md etc.)
|
||||
|
||||
doc = {}
|
||||
|
||||
for pagename in glob.glob(os.path.join(path, "doc") + "/*.md"):
|
||||
name = os.path.basename(pagename)[:-len('.md')]
|
||||
doc[name] = read_file(pagename)
|
||||
|
||||
notifications = {}
|
||||
|
||||
for step in ["pre_install", "post_install", "pre_upgrade", "post_upgrade"]:
|
||||
notifications[step] = {}
|
||||
if os.path.exists(os.path.join(path, "doc", "notifications", f"{step}.md")):
|
||||
notifications[step]["main"] = read_file(os.path.join(path, "doc", "notifications", f"{step}.md"))
|
||||
else:
|
||||
for notification in glob.glob(os.path.join(path, "doc", "notifications", f"{step}.d") + "/*.md"):
|
||||
name = os.path.basename(notification)[:-len('.md')]
|
||||
notifications[step][name].append(read_file(notification))
|
||||
|
||||
return doc, notifications
|
||||
|
||||
|
||||
def _hydrate_app_template(template, data):
|
||||
|
||||
stuff_to_replace = set(re.findall(r'__[A-Z0-9]+?[A-Z0-9_]*?[A-Z0-9]*?__', template))
|
||||
|
||||
for stuff in stuff_to_replace:
|
||||
|
||||
varname = stuff.strip("_").lower()
|
||||
|
||||
if varname in data:
|
||||
template = template.replace(stuff, data[varname])
|
||||
|
||||
return template
|
||||
|
||||
|
||||
def _convert_v1_manifest_to_v2(manifest):
|
||||
|
||||
manifest = copy.deepcopy(manifest)
|
||||
|
|
|
@ -57,7 +57,7 @@ def space_used_by_directory(dirpath, follow_symlinks=True):
|
|||
return int(du_output.split()[0])
|
||||
|
||||
stat = os.statvfs(dirpath)
|
||||
return stat.f_frsize * stat.f_blocks
|
||||
return stat.f_frsize * stat.f_blocks # FIXME : this doesnt do what the function name suggest this does ...
|
||||
|
||||
|
||||
def human_to_binary(size: str) -> int:
|
||||
|
|
Loading…
Add table
Reference in a new issue