From 69ac8da1506afe9cec263f51df7fab27f40e331f Mon Sep 17 00:00:00 2001
From: tituspijean <tituspijean@outlook.com>
Date: Fri, 5 Aug 2022 16:39:38 +0200
Subject: [PATCH] Fix antifeatures list generation

---
 tools/README-generator/make_readme.py         | 22 ++++++++++++++-----
 tools/README-generator/templates/README.md.j2 |  3 ++-
 .../templates/README_fr.md.j2                 |  4 +++-
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/tools/README-generator/make_readme.py b/tools/README-generator/make_readme.py
index 788b8a7..d9c03db 100755
--- a/tools/README-generator/make_readme.py
+++ b/tools/README-generator/make_readme.py
@@ -8,6 +8,15 @@ 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):
 
@@ -22,7 +31,7 @@ def generate_READMEs(app_path: str):
     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"))
+    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():
@@ -62,12 +71,12 @@ def generate_READMEs(app_path: str):
 
         # 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:
-            v['title'] = v['title'].get(lang_suffix, 'en')
-            if manifest.get("antifeatures", {}).get(k, 'en'):
-                v['description'] = manifest.get("antifeatures", {}).get(k, 'en')
+        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:
-                antifeature['description'] = antifeature['description'].get(lang_suffix, 'en')
+                antifeatures[k]['description'] = value_for_lang(antifeatures[k]['description'], lang_suffix)
 
         out = template.render(
             lang=lang,
@@ -75,6 +84,7 @@ def generate_READMEs(app_path: str):
             description=description,
             screenshots=screenshots,
             disclaimer=disclaimer,
+            antifeatures=antifeatures,
             manifest=manifest,
         )
         (app_path / f"README{lang_suffix}.md").write_text(out)
diff --git a/tools/README-generator/templates/README.md.j2 b/tools/README-generator/templates/README.md.j2
index 8713a9a..990b5e0 100644
--- a/tools/README-generator/templates/README.md.j2
+++ b/tools/README-generator/templates/README.md.j2
@@ -52,8 +52,9 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in
 {% if antifeatures -%}
 ## Antifeatures
 
-{% for antifeature in antifeatures -%}
+{% for antifeature in antifeatures.values() -%}
   - **{{ antifeature.title }}**: {{ antifeature.description }}
+
 {% endfor -%}
 {% endif -%}
 
diff --git a/tools/README-generator/templates/README_fr.md.j2 b/tools/README-generator/templates/README_fr.md.j2
index 9e89c10..864dc60 100644
--- a/tools/README-generator/templates/README_fr.md.j2
+++ b/tools/README-generator/templates/README_fr.md.j2
@@ -34,11 +34,13 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour
 {% if antifeatures -%}
 ## Fonctions indésirables
 
-{% for antifeature in antifeatures -%}
+{% for antifeature in antifeatures.values() -%}
   - **{{ antifeature.title }}**: {{ antifeature.description }}
+
 {% endfor -%}
 {% endif -%}
 
+
 ## Documentations et ressources
 
 {% if upstream.website -%}* Site officiel de l'app : {{ upstream.website }}