1
0
Fork 0

Merge pull request #1165 from nils-van-zuijlen/readme-venv-everywhere

Auto-update-README
This commit is contained in:
Alexandre Aubin 2021-05-26 18:58:07 +02:00 committed by GitHub
commit 5e4094a462

View file

@ -1,54 +1,65 @@
#! /usr/bin/python3 #! /usr/bin/env python3
import argparse import argparse
import json import json
import os import os
from pathlib import Path
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
def generate_READMEs(app_path): def generate_READMEs(app_path: Path):
if not os.path.exists(app_path): if not app_path.exists():
raise Exception("App path provided doesn't exists ?!") raise Exception("App path provided doesn't exists ?!")
manifest = json.load(open(os.path.join(app_path, "manifest.json"))) manifest = json.load(open(app_path / "manifest.json"))
upstream = manifest.get("upstream", {}) upstream = manifest.get("upstream", {})
if not upstream and not os.path.exists(os.path.join(app_path, "doc", "DISCLAIMER.md")): 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.") 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."
)
return return
env = Environment(loader=FileSystemLoader('./templates')) env = Environment(loader=FileSystemLoader(Path(__file__).parent / "templates"))
for lang, lang_suffix in [("en", ""), ("fr", "_fr")]: for lang, lang_suffix in [("en", ""), ("fr", "_fr")]:
template = env.get_template(f'README{lang_suffix}.md.j2') template = env.get_template(f"README{lang_suffix}.md.j2")
if os.path.exists(os.path.join(app_path, "doc", "screenshots")): if (app_path / "doc" / "screenshots").exists():
screenshots = os.listdir(os.path.join(app_path, "doc", "screenshots")) screenshots = os.listdir(os.path.join(app_path, "doc", "screenshots"))
if ".gitkeep" in screenshots: if ".gitkeep" in screenshots:
screenshots.remove(".gitkeep") screenshots.remove(".gitkeep")
else: else:
screenshots = [] screenshots = []
if os.path.exists(os.path.join(app_path, "doc", f"DISCLAIMER{lang_suffix}.md")): if (app_path / "doc" / f"DISCLAIMER{lang_suffix}.md").exists():
disclaimer = open(os.path.join(app_path, "doc", f"DISCLAIMER{lang_suffix}.md")).read() disclaimer = (app_path / "doc" / f"DISCLAIMER{lang_suffix}.md").read_text()
# Fallback to english if maintainer too lazy to translate the disclaimer idk # Fallback to english if maintainer too lazy to translate the disclaimer idk
elif os.path.exists(os.path.join(app_path, "doc", "DISCLAIMER.md")): elif (app_path / "doc" / "DISCLAIMER.md").exists():
disclaimer = open(os.path.join(app_path, "doc", "DISCLAIMER.md")).read() disclaimer = (app_path / "doc" / "DISCLAIMER.md").read_text()
else: else:
disclaimer = None disclaimer = None
out = template.render(lang=lang, upstream=upstream, screenshots=screenshots, disclaimer=disclaimer, manifest=manifest) out = template.render(
with open(os.path.join(app_path, f"README{lang_suffix}.md"), "w") as f: lang=lang,
f.write(out) upstream=upstream,
screenshots=screenshots,
disclaimer=disclaimer,
manifest=manifest,
)
(app_path / f"README{lang_suffix}.md").write_text(out)
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Automatically (re)generate README for apps') parser = argparse.ArgumentParser(
parser.add_argument('app_path', description="Automatically (re)generate README for apps"
help='Path to the app to generate/update READMEs for') )
parser.add_argument(
"app_path", help="Path to the app to generate/update READMEs for"
)
args = parser.parse_args() args = parser.parse_args()
generate_READMEs(args.app_path) generate_READMEs(Path(args.app_path))