From 775c6ef6274b94d0a21b7dc7792ee057b8ed8dfd 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' --- readme_generator/make_readme.py | 8 +++++--- readme_generator/templates/README.md.j2 | 2 +- readme_generator/templates/README_fr.md.j2 | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/readme_generator/make_readme.py b/readme_generator/make_readme.py index e7164ad..cbaeed0 100755 --- a/readme_generator/make_readme.py +++ b/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/readme_generator/templates/README.md.j2 b/readme_generator/templates/README.md.j2 index 8f51a41..46f33e4 100644 --- a/readme_generator/templates/README.md.j2 +++ b/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/readme_generator/templates/README_fr.md.j2 b/readme_generator/templates/README_fr.md.j2 index b02a7b8..fba3e1b 100644 --- a/readme_generator/templates/README_fr.md.j2 +++ b/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 1f2d5f2418869f91e6921e82c6e13052ab1522ea 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 --- readme_generator/make_readme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme_generator/make_readme.py b/readme_generator/make_readme.py index cbaeed0..cfa597f 100755 --- a/readme_generator/make_readme.py +++ b/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 12f5aebd630e35f9d16edccd4e3c1d000a0bc4ad 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 --- readme_generator/make_readme.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme_generator/make_readme.py b/readme_generator/make_readme.py index cfa597f..574191c 100755 --- a/readme_generator/make_readme.py +++ b/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 41415c26a018634508170b3ab6f3ddf7ac071c22 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 --- readme_generator/make_readme.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/readme_generator/make_readme.py b/readme_generator/make_readme.py index 574191c..07e5001 100755 --- a/readme_generator/make_readme.py +++ b/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()