-
-
Notifications
You must be signed in to change notification settings - Fork 466
/
update_projects_jsonl.py
36 lines (29 loc) · 1.09 KB
/
update_projects_jsonl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from pathlib import Path
from weasel.cli.main import PROJECT_FILE
from weasel.util import load_project_config
from wasabi import msg
import json
import typer
def main(root: Path = typer.Argument(Path.cwd(), help="Root path to look in")):
"""
Update the projects.jsonl file for the repo.
Unlike the docs update script, this is desigend to only be run on the root
of the whole repository.
"""
msg.info(f"Updating projects.jsonl in {root}")
entries = []
# We look specifically for project directories
for path in root.glob(f"**/*/{PROJECT_FILE}"):
path = path.parent
# prep data for the json file
config = load_project_config(path)
entry = {"shortname": f"{path.parent.name}/{path.name}"}
entry["title"] = config["title"]
entry["description"] = config.get("description", "")
entries.append(entry)
with open("projects.jsonl", "w", encoding="utf-8") as jsonfile:
for entry in entries:
jsonfile.write(json.dumps(entry))
jsonfile.write("\n")
if __name__ == "__main__":
typer.run(main)