diff --git a/README-generator/make_readme.py b/README-generator/make_readme.py index ddcc3d2..d9c03db 100755 --- a/README-generator/make_readme.py +++ b/README-generator/make_readme.py @@ -3,10 +3,20 @@ import argparse import json import os +import yaml from pathlib import Path from jinja2 import Environment, FileSystemLoader +def value_for_lang(values, lang): + if not isinstance(values, dict): + return values + if lang in values: + return values[lang] + elif "en" in values: + return values["en"] + else: + return list(values.values())[0] def generate_READMEs(app_path: str): @@ -18,6 +28,12 @@ def generate_READMEs(app_path: str): manifest = json.load(open(app_path / "manifest.json")) upstream = manifest.get("upstream", {}) + catalog = json.load(open(Path(os.path.abspath(__file__)).parent.parent.parent / "apps.json")) + from_catalog = catalog.get(manifest['id'], {}) + + antifeatures_list = yaml.load(open(Path(os.path.abspath(__file__)).parent.parent.parent / "antifeatures.yml"), Loader=yaml.SafeLoader) + antifeatures_list = { e['id']: e for e in antifeatures_list } + if not upstream and not (app_path / "doc" / "DISCLAIMER.md").exists(): print( "There's no 'upstream' key in the manifest, and doc/DISCLAIMER.md doesn't exists - therefore assuming that we shall not auto-update the README.md for this app yet." @@ -53,12 +69,22 @@ def generate_READMEs(app_path: str): else: disclaimer = None + # TODO: Add url to the documentation... and actually create that documentation :D + antifeatures = { a: antifeatures_list[a] for a in from_catalog.get('antifeatures', [])} + for k, v in antifeatures.items(): + antifeatures[k]['title'] = value_for_lang(v['title'], lang_suffix) + if manifest.get("antifeatures", {}).get(k, None): + antifeatures[k]['description'] = value_for_lang(manifest.get("antifeatures", {}).get(k, None), lang_suffix) + else: + antifeatures[k]['description'] = value_for_lang(antifeatures[k]['description'], lang_suffix) + out = template.render( lang=lang, upstream=upstream, description=description, screenshots=screenshots, disclaimer=disclaimer, + antifeatures=antifeatures, manifest=manifest, ) (app_path / f"README{lang_suffix}.md").write_text(out) diff --git a/README-generator/requirements.txt b/README-generator/requirements.txt index 88cd6e2..33fe25a 100644 --- a/README-generator/requirements.txt +++ b/README-generator/requirements.txt @@ -1,2 +1,3 @@ jinja2 sanic +pyyaml diff --git a/README-generator/templates/README.md.j2 b/README-generator/templates/README.md.j2 index d04393b..e2d428f 100644 --- a/README-generator/templates/README.md.j2 +++ b/README-generator/templates/README.md.j2 @@ -52,6 +52,15 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in {{ disclaimer }} {% endif -%} +{% if antifeatures -%} +## :red_circle: Antifeatures + +{% for antifeature in antifeatures.values() -%} + - **{{ antifeature.title }}**: {{ antifeature.description }} + +{% endfor -%} +{% endif -%} + ## Documentation and resources {% if upstream.website -%}* Official app website: <{{ upstream.website }}> diff --git a/README-generator/templates/README_fr.md.j2 b/README-generator/templates/README_fr.md.j2 index ae51374..95fb8f4 100644 --- a/README-generator/templates/README_fr.md.j2 +++ b/README-generator/templates/README_fr.md.j2 @@ -38,6 +38,16 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour {{ disclaimer }} {% endif -%} +{% if antifeatures -%} +## :red_circle: Fonctions indésirables + +{% for antifeature in antifeatures.values() -%} + - **{{ antifeature.title }}**: {{ antifeature.description }} + +{% endfor -%} +{% endif -%} + + ## Documentations et ressources {% if upstream.website -%}* Site officiel de l'app : <{{ upstream.website }}>