48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
from __future__ import annotations
|
|
import glob, os, re, sys
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
import enrich_vault as E
|
|
from update_swarm.schema import write_json
|
|
|
|
WIKILINK = re.compile(r"\[\[([^\]|#]+)")
|
|
|
|
def _links(path: str) -> set[str]:
|
|
if not os.path.isfile(path):
|
|
return set()
|
|
text = open(path, encoding="utf-8").read()
|
|
return {m.strip() for m in WIKILINK.findall(text)}
|
|
|
|
def build_jobs(vault_romhacks_dir: str) -> list[dict]:
|
|
hacks = os.path.join(vault_romhacks_dir, "Hacks")
|
|
watch = _links(os.path.join(vault_romhacks_dir, "Demo Watchlist.md"))
|
|
wanted = _links(os.path.join(vault_romhacks_dir, "Wanted.md"))
|
|
jobs = []
|
|
for path in sorted(glob.glob(os.path.join(hacks, "*.md"))):
|
|
stem = os.path.splitext(os.path.basename(path))[0]
|
|
fm_text, _, _ = E.read_note(path)
|
|
fm = E.parse_fm(fm_text)
|
|
def blank(v):
|
|
return None if v in (None, "", "—") else v
|
|
jobs.append({
|
|
"stem": stem,
|
|
"title": fm.get("title") or stem,
|
|
"platform": blank(fm.get("platform")),
|
|
"library_path": blank(fm.get("library_path")),
|
|
"homepage": blank(fm.get("homepage")),
|
|
"source": blank(fm.get("source")),
|
|
"note_version": blank(fm.get("version")),
|
|
"note_status": blank(fm.get("status")),
|
|
"watchlist": stem in watch,
|
|
"wanted": stem in wanted,
|
|
})
|
|
return jobs
|
|
|
|
def init_run(run_dir: str) -> None:
|
|
os.makedirs(run_dir, exist_ok=True)
|
|
for name in ("census", "scouts", "staging"):
|
|
os.makedirs(os.path.join(run_dir, name), exist_ok=True)
|
|
jobs_path = os.path.join(run_dir, "jobs.json")
|
|
if not os.path.isfile(jobs_path):
|
|
write_json(jobs_path, {"run_date": os.path.basename(run_dir), "jobs": []})
|