mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
appv2: simplify the expected notification file/folder structure in apps
This commit is contained in:
parent
eacb1dc0e6
commit
2f1ddb1edf
2 changed files with 30 additions and 24 deletions
34
src/app.py
34
src/app.py
|
@ -607,12 +607,12 @@ def app_upgrade(app=[], url=None, file=None, force=False, no_safety_backup=False
|
||||||
|
|
||||||
# Display pre-upgrade notifications and ask for simple confirm
|
# Display pre-upgrade notifications and ask for simple confirm
|
||||||
if (
|
if (
|
||||||
manifest["notifications"]["pre_upgrade"]
|
manifest["notifications"]["PRE_UPGRADE"]
|
||||||
and Moulinette.interface.type == "cli"
|
and Moulinette.interface.type == "cli"
|
||||||
):
|
):
|
||||||
settings = _get_app_settings(app_instance_name)
|
settings = _get_app_settings(app_instance_name)
|
||||||
notifications = _filter_and_hydrate_notifications(
|
notifications = _filter_and_hydrate_notifications(
|
||||||
manifest["notifications"]["pre_upgrade"],
|
manifest["notifications"]["PRE_UPGRADE"],
|
||||||
current_version=app_current_version,
|
current_version=app_current_version,
|
||||||
data=settings,
|
data=settings,
|
||||||
)
|
)
|
||||||
|
@ -797,11 +797,11 @@ def app_upgrade(app=[], url=None, file=None, force=False, no_safety_backup=False
|
||||||
logger.success(m18n.n("app_upgraded", app=app_instance_name))
|
logger.success(m18n.n("app_upgraded", app=app_instance_name))
|
||||||
|
|
||||||
# Format post-upgrade notifications
|
# Format post-upgrade notifications
|
||||||
if manifest["notifications"]["post_upgrade"]:
|
if manifest["notifications"]["POST_UPGRADE"]:
|
||||||
# Get updated settings to hydrate notifications
|
# Get updated settings to hydrate notifications
|
||||||
settings = _get_app_settings(app_instance_name)
|
settings = _get_app_settings(app_instance_name)
|
||||||
notifications = _filter_and_hydrate_notifications(
|
notifications = _filter_and_hydrate_notifications(
|
||||||
manifest["notifications"]["post_upgrade"],
|
manifest["notifications"]["POST_UPGRADE"],
|
||||||
current_version=app_current_version,
|
current_version=app_current_version,
|
||||||
data=settings,
|
data=settings,
|
||||||
)
|
)
|
||||||
|
@ -817,7 +817,7 @@ def app_upgrade(app=[], url=None, file=None, force=False, no_safety_backup=False
|
||||||
logger.success(m18n.n("upgrade_complete"))
|
logger.success(m18n.n("upgrade_complete"))
|
||||||
|
|
||||||
if Moulinette.interface.type == "api":
|
if Moulinette.interface.type == "api":
|
||||||
return {"notifications": {"post_upgrade": notifications}}
|
return {"notifications": {"POST_UPGRADE": notifications}}
|
||||||
|
|
||||||
|
|
||||||
def app_manifest(app, with_screenshot=False):
|
def app_manifest(app, with_screenshot=False):
|
||||||
|
@ -927,9 +927,9 @@ def app_install(
|
||||||
manifest, extracted_app_folder = _extract_app(app)
|
manifest, extracted_app_folder = _extract_app(app)
|
||||||
|
|
||||||
# Display pre_install notices in cli mode
|
# Display pre_install notices in cli mode
|
||||||
if manifest["notifications"]["pre_install"] and Moulinette.interface.type == "cli":
|
if manifest["notifications"]["PRE_INSTALL"] and Moulinette.interface.type == "cli":
|
||||||
notifications = _filter_and_hydrate_notifications(
|
notifications = _filter_and_hydrate_notifications(
|
||||||
manifest["notifications"]["pre_install"]
|
manifest["notifications"]["PRE_INSTALL"]
|
||||||
)
|
)
|
||||||
_display_notifications(notifications, force=force)
|
_display_notifications(notifications, force=force)
|
||||||
|
|
||||||
|
@ -1202,7 +1202,7 @@ def app_install(
|
||||||
# Get the generated settings to hydrate notifications
|
# Get the generated settings to hydrate notifications
|
||||||
settings = _get_app_settings(app_instance_name)
|
settings = _get_app_settings(app_instance_name)
|
||||||
notifications = _filter_and_hydrate_notifications(
|
notifications = _filter_and_hydrate_notifications(
|
||||||
manifest["notifications"]["post_install"], data=settings
|
manifest["notifications"]["POST_INSTALL"], data=settings
|
||||||
)
|
)
|
||||||
|
|
||||||
# Display post_install notices in cli mode
|
# Display post_install notices in cli mode
|
||||||
|
@ -2001,6 +2001,7 @@ def _get_manifest_of_app(path):
|
||||||
def _parse_app_doc_and_notifications(path):
|
def _parse_app_doc_and_notifications(path):
|
||||||
|
|
||||||
doc = {}
|
doc = {}
|
||||||
|
notification_names = ["PRE_INSTALL", "POST_INSTALL", "PRE_UPGRADE", "POST_UPGRADE"]
|
||||||
|
|
||||||
for filepath in glob.glob(os.path.join(path, "doc") + "/*.md"):
|
for filepath in glob.glob(os.path.join(path, "doc") + "/*.md"):
|
||||||
|
|
||||||
|
@ -2011,7 +2012,12 @@ def _parse_app_doc_and_notifications(path):
|
||||||
if not m:
|
if not m:
|
||||||
# FIXME: shall we display a warning ? idk
|
# FIXME: shall we display a warning ? idk
|
||||||
continue
|
continue
|
||||||
|
|
||||||
pagename, lang = m.groups()
|
pagename, lang = m.groups()
|
||||||
|
|
||||||
|
if pagename in notification_names:
|
||||||
|
continue
|
||||||
|
|
||||||
lang = lang.strip("_") if lang else "en"
|
lang = lang.strip("_") if lang else "en"
|
||||||
|
|
||||||
if pagename not in doc:
|
if pagename not in doc:
|
||||||
|
@ -2020,10 +2026,10 @@ def _parse_app_doc_and_notifications(path):
|
||||||
|
|
||||||
notifications = {}
|
notifications = {}
|
||||||
|
|
||||||
for step in ["pre_install", "post_install", "pre_upgrade", "post_upgrade"]:
|
for step in notification_names:
|
||||||
notifications[step] = {}
|
notifications[step] = {}
|
||||||
for filepath in glob.glob(
|
for filepath in glob.glob(
|
||||||
os.path.join(path, "doc", "notifications", f"{step}*.md")
|
os.path.join(path, "doc", f"{step}*.md")
|
||||||
):
|
):
|
||||||
m = re.match(step + "(_[a-z]{2,3})?.md", filepath.split("/")[-1])
|
m = re.match(step + "(_[a-z]{2,3})?.md", filepath.split("/")[-1])
|
||||||
if not m:
|
if not m:
|
||||||
|
@ -2035,7 +2041,7 @@ def _parse_app_doc_and_notifications(path):
|
||||||
notifications[step][pagename][lang] = read_file(filepath).strip()
|
notifications[step][pagename][lang] = read_file(filepath).strip()
|
||||||
|
|
||||||
for filepath in glob.glob(
|
for filepath in glob.glob(
|
||||||
os.path.join(path, "doc", "notifications", f"{step}.d") + "/*.md"
|
os.path.join(path, "doc", f"{step}.d") + "/*.md"
|
||||||
):
|
):
|
||||||
m = re.match(
|
m = re.match(
|
||||||
r"([A-Za-z0-9\.\~]*)(_[a-z]{2,3})?.md", filepath.split("/")[-1]
|
r"([A-Za-z0-9\.\~]*)(_[a-z]{2,3})?.md", filepath.split("/")[-1]
|
||||||
|
@ -2403,9 +2409,9 @@ def _list_upgradable_apps():
|
||||||
manifest, extracted_app_folder = _extract_app(absolute_app_name)
|
manifest, extracted_app_folder = _extract_app(absolute_app_name)
|
||||||
current_version = version.parse(app["current_version"])
|
current_version = version.parse(app["current_version"])
|
||||||
app["notifications"] = {}
|
app["notifications"] = {}
|
||||||
if manifest["notifications"]["pre_upgrade"]:
|
if manifest["notifications"]["PRE_UPGRADE"]:
|
||||||
app["notifications"]["pre_upgrade"] = _filter_and_hydrate_notifications(
|
app["notifications"]["PRE_UPGRADE"] = _filter_and_hydrate_notifications(
|
||||||
manifest["notifications"]["pre_upgrade"],
|
manifest["notifications"]["PRE_UPGRADE"],
|
||||||
current_version,
|
current_version,
|
||||||
app["settings"],
|
app["settings"],
|
||||||
)
|
)
|
||||||
|
|
|
@ -223,10 +223,10 @@ def test_legacy_app_manifest_preinstall():
|
||||||
assert "install" in m
|
assert "install" in m
|
||||||
assert m["doc"] == {}
|
assert m["doc"] == {}
|
||||||
assert m["notifications"] == {
|
assert m["notifications"] == {
|
||||||
"pre_install": {},
|
"PRE_INSTALL": {},
|
||||||
"pre_upgrade": {},
|
"PRE_UPGRADE": {},
|
||||||
"post_install": {},
|
"POST_INSTALL": {},
|
||||||
"post_upgrade": {},
|
"POST_UPGRADE": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -249,11 +249,11 @@ def test_manifestv2_app_manifest_preinstall():
|
||||||
assert "notifications" in m
|
assert "notifications" in m
|
||||||
assert (
|
assert (
|
||||||
"This is a dummy disclaimer to display prior to the install"
|
"This is a dummy disclaimer to display prior to the install"
|
||||||
in m["notifications"]["pre_install"]["main"]["en"]
|
in m["notifications"]["PRE_INSTALL"]["main"]["en"]
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
"Ceci est un faux disclaimer à présenter avant l'installation"
|
"Ceci est un faux disclaimer à présenter avant l'installation"
|
||||||
in m["notifications"]["pre_install"]["main"]["fr"]
|
in m["notifications"]["PRE_INSTALL"]["main"]["fr"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -295,15 +295,15 @@ def test_manifestv2_app_info_postinstall():
|
||||||
assert "notifications" in m
|
assert "notifications" in m
|
||||||
assert (
|
assert (
|
||||||
"The app install dir is /var/www/manifestv2_app"
|
"The app install dir is /var/www/manifestv2_app"
|
||||||
in m["notifications"]["post_install"]["main"]["en"]
|
in m["notifications"]["POST_INSTALL"]["main"]["en"]
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
"The app id is manifestv2_app"
|
"The app id is manifestv2_app"
|
||||||
in m["notifications"]["post_install"]["main"]["en"]
|
in m["notifications"]["POST_INSTALL"]["main"]["en"]
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
f"The app url is {main_domain}/manifestv2"
|
f"The app url is {main_domain}/manifestv2"
|
||||||
in m["notifications"]["post_install"]["main"]["en"]
|
in m["notifications"]["POST_INSTALL"]["main"]["en"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -341,7 +341,7 @@ def test_manifestv2_app_info_preupgrade(monkeypatch):
|
||||||
# should parse the files in the original app repo, possibly with proper i18n etc
|
# should parse the files in the original app repo, possibly with proper i18n etc
|
||||||
assert (
|
assert (
|
||||||
"This is a dummy disclaimer to display prior to any upgrade"
|
"This is a dummy disclaimer to display prior to any upgrade"
|
||||||
in i["from_catalog"]["manifest"]["notifications"]["pre_upgrade"]["main"]["en"]
|
in i["from_catalog"]["manifest"]["notifications"]["PRE_UPGRADE"]["main"]["en"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue