2021-04-28 20:11:42 +02:00
|
|
|
import argparse
|
2021-04-23 20:01:40 +02:00
|
|
|
import json
|
|
|
|
import os
|
|
|
|
|
2021-04-28 20:11:42 +02:00
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='Automatically (re)generate README for apps')
|
|
|
|
parser.add_argument('app_path',
|
|
|
|
help='Path to the app to generate/update READMEs for')
|
2021-04-23 20:01:40 +02:00
|
|
|
|
2021-04-28 20:11:42 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
app_path = args.app_path
|
2021-04-23 20:01:40 +02:00
|
|
|
|
2021-04-28 20:11:42 +02:00
|
|
|
if not os.path.exists(app_path):
|
2021-04-23 20:01:40 +02:00
|
|
|
raise Exception("App path provided doesn't exists ?!")
|
|
|
|
|
|
|
|
env = Environment(loader=FileSystemLoader('./templates'))
|
|
|
|
|
|
|
|
for lang, lang_suffix in [("en", ""), ("fr", "_fr")]:
|
|
|
|
|
|
|
|
template = env.get_template(f'README{lang_suffix}.md.j2')
|
|
|
|
|
2021-04-28 20:11:42 +02:00
|
|
|
manifest = json.load(open(os.path.join(app_path, "manifest.json")))
|
2021-04-23 20:01:40 +02:00
|
|
|
upstream = manifest.get("upstream", {})
|
|
|
|
|
2021-04-28 20:11:42 +02:00
|
|
|
if os.path.exists(os.path.join(app_path, "doc", "screenshots")):
|
|
|
|
screenshots = os.listdir(os.path.join(app_path, "doc", "screenshots"))
|
2021-04-23 20:01:40 +02:00
|
|
|
if ".gitkeep" in screenshots:
|
|
|
|
screenshots.remove(".gitkeep")
|
|
|
|
else:
|
|
|
|
screenshots = []
|
|
|
|
|
2021-04-28 20:11:42 +02:00
|
|
|
if os.path.exists(os.path.join(app_path, "doc", f"DISCLAIMER{lang_suffix}.md")):
|
|
|
|
disclaimer = open(os.path.join(app_path, "doc", f"DISCLAIMER{lang_suffix}.md")).read()
|
2021-04-23 20:01:40 +02:00
|
|
|
# Fallback to english if maintainer too lazy to translate the disclaimer idk
|
2021-04-28 20:11:42 +02:00
|
|
|
elif os.path.exists(os.path.join(app_path, "doc", "DISCLAIMER.md")):
|
|
|
|
disclaimer = open(os.path.join(app_path, "doc", "DISCLAIMER.md")).read()
|
2021-04-23 20:01:40 +02:00
|
|
|
else:
|
|
|
|
disclaimer = None
|
|
|
|
|
|
|
|
out = template.render(lang=lang, upstream=upstream, screenshots=screenshots, disclaimer=disclaimer, manifest=manifest)
|
2021-04-28 20:11:42 +02:00
|
|
|
with open(os.path.join(app_path, f"README{lang_suffix}.md"), "w") as f:
|
2021-04-23 20:01:40 +02:00
|
|
|
f.write(out)
|