From f33b5470022960485094d28ed33c045b5dbbb28b Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Wed, 13 Mar 2024 02:45:34 +0100 Subject: [PATCH 1/4] readme-generator: only pick files (no folder) on the root of 'screenshots' --- tools/readme_generator/make_readme.py | 8 +++++--- tools/readme_generator/templates/README.md.j2 | 2 +- tools/readme_generator/templates/README_fr.md.j2 | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/readme_generator/make_readme.py b/tools/readme_generator/make_readme.py index e7164ad58f..cbaeed04ab 100755 --- a/tools/readme_generator/make_readme.py +++ b/tools/readme_generator/make_readme.py @@ -83,11 +83,13 @@ def generate_READMEs(app_path: Path): screenshots: List[str] if (app_path / "doc" / "screenshots").exists(): - screenshots = os.listdir(os.path.join(app_path, "doc", "screenshots")) + screenshots = [] + # only pick files (no folder) on the root of 'screenshots' + for entry in os.scandir(os.path.join(app_path, "doc", "screenshots")): + if os.DirEntry.is_file(entry): + screenshots.append(os.path.relpath(entry.path, app_path)) if ".gitkeep" in screenshots: screenshots.remove(".gitkeep") - else: - screenshots = [] disclaimer: Optional[str] if (app_path / "doc" / f"DISCLAIMER{lang_suffix}.md").exists(): diff --git a/tools/readme_generator/templates/README.md.j2 b/tools/readme_generator/templates/README.md.j2 index 8f51a4185f..46f33e45eb 100644 --- a/tools/readme_generator/templates/README.md.j2 +++ b/tools/readme_generator/templates/README.md.j2 @@ -42,7 +42,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in ## Screenshots {% for screenshot in screenshots -%} - ![Screenshot of {{manifest.name}}](./doc/screenshots/{{screenshot}}) + ![Screenshot of {{manifest.name}}](./{{screenshot}}) {% endfor %} {% endif -%} diff --git a/tools/readme_generator/templates/README_fr.md.j2 b/tools/readme_generator/templates/README_fr.md.j2 index b02a7b86ab..fba3e1bec2 100644 --- a/tools/readme_generator/templates/README_fr.md.j2 +++ b/tools/readme_generator/templates/README_fr.md.j2 @@ -28,7 +28,7 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po ## Captures d’écran {% for screenshot in screenshots -%} - ![Capture d’écran de {{manifest.name}}](./doc/screenshots/{{screenshot}}) + ![Capture d’écran de {{manifest.name}}](./{{screenshot}}) {% endfor %} {% endif -%} From b50e85150c891580f4b0c0d9a6ebca370abe6658 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Wed, 13 Mar 2024 02:56:34 +0100 Subject: [PATCH 2/4] fix: referenced before assignment --- tools/readme_generator/make_readme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/readme_generator/make_readme.py b/tools/readme_generator/make_readme.py index cbaeed04ab..cfa597fa7e 100755 --- a/tools/readme_generator/make_readme.py +++ b/tools/readme_generator/make_readme.py @@ -82,8 +82,8 @@ def generate_READMEs(app_path: Path): description = None screenshots: List[str] + screenshots = [] if (app_path / "doc" / "screenshots").exists(): - screenshots = [] # only pick files (no folder) on the root of 'screenshots' for entry in os.scandir(os.path.join(app_path, "doc", "screenshots")): if os.DirEntry.is_file(entry): From 8c777e2edd8b9a4395cf0edaa7b5eaccb81f3e5b Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Wed, 13 Mar 2024 03:13:12 +0100 Subject: [PATCH 3/4] fix: ignore '.gitkeep' or any file whose name begins with a dot --- tools/readme_generator/make_readme.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/readme_generator/make_readme.py b/tools/readme_generator/make_readme.py index cfa597fa7e..574191c55e 100755 --- a/tools/readme_generator/make_readme.py +++ b/tools/readme_generator/make_readme.py @@ -87,9 +87,9 @@ def generate_READMEs(app_path: Path): # only pick files (no folder) on the root of 'screenshots' for entry in os.scandir(os.path.join(app_path, "doc", "screenshots")): if os.DirEntry.is_file(entry): - screenshots.append(os.path.relpath(entry.path, app_path)) - if ".gitkeep" in screenshots: - screenshots.remove(".gitkeep") + # ignore '.gitkeep' or any file whose name begins with a dot + if not entry.name.startswith("."): + screenshots.append(os.path.relpath(entry.path, app_path)) disclaimer: Optional[str] if (app_path / "doc" / f"DISCLAIMER{lang_suffix}.md").exists(): From f3c2b77b1f9296734205c288cfb35a46bdf6fab0 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Wed, 13 Mar 2024 03:22:39 +0100 Subject: [PATCH 4/4] move the screenshots code part to only run it once, since it do not change with language --- tools/readme_generator/make_readme.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/readme_generator/make_readme.py b/tools/readme_generator/make_readme.py index 574191c55e..07e5001145 100755 --- a/tools/readme_generator/make_readme.py +++ b/tools/readme_generator/make_readme.py @@ -51,6 +51,16 @@ def generate_READMEs(app_path: Path): env = Environment(loader=FileSystemLoader(Path(__file__).parent / "templates")) + screenshots: List[str] + screenshots = [] + if (app_path / "doc" / "screenshots").exists(): + # only pick files (no folder) on the root of 'screenshots' + for entry in os.scandir(os.path.join(app_path, "doc", "screenshots")): + if os.DirEntry.is_file(entry): + # ignore '.gitkeep' or any file whose name begins with a dot + if not entry.name.startswith("."): + screenshots.append(os.path.relpath(entry.path, app_path)) + # parse available README template and generate a list in the form of: # > [("en", ""), ("fr", "_fr"), ...] available_langs: List[Tuple[str, str]] = [("en", "")] @@ -81,16 +91,6 @@ def generate_READMEs(app_path: Path): else: description = None - screenshots: List[str] - screenshots = [] - if (app_path / "doc" / "screenshots").exists(): - # only pick files (no folder) on the root of 'screenshots' - for entry in os.scandir(os.path.join(app_path, "doc", "screenshots")): - if os.DirEntry.is_file(entry): - # ignore '.gitkeep' or any file whose name begins with a dot - if not entry.name.startswith("."): - screenshots.append(os.path.relpath(entry.path, app_path)) - disclaimer: Optional[str] if (app_path / "doc" / f"DISCLAIMER{lang_suffix}.md").exists(): disclaimer = (app_path / "doc" / f"DISCLAIMER{lang_suffix}.md").read_text()