feat: build update-swarm jobs.json from vault notes
This commit is contained in:
1 parent
299b01c4fd
commit
d91b0bc13d
7 files changed
+109
No files matched your search
@@ -0,0 +1,47 @@
|
|||||||
|
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": []})
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
import json, os
|
||||||
|
|
||||||
|
def read_json(path: str):
|
||||||
|
with open(path, encoding="utf-8") as f:
|
||||||
|
return json.load(f)
|
||||||
|
|
||||||
|
def write_json(path: str, obj) -> None:
|
||||||
|
os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
|
||||||
|
with open(path, "w", encoding="utf-8") as f:
|
||||||
|
json.dump(obj, f, indent=2, ensure_ascii=False)
|
||||||
|
f.write("\n")
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
| Hack | Vault note |
|
||||||
|
|---|---|
|
||||||
|
| **DemoOnly** | [[DemoOnly]] |
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
title: "Pokémon DemoOnly"
|
||||||
|
platform: PC
|
||||||
|
version: "0.6.2"
|
||||||
|
status: Beta
|
||||||
|
---
|
||||||
|
|
||||||
|
# Pokémon DemoOnly
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
title: "Pokémon FakeHack"
|
||||||
|
platform: GBA
|
||||||
|
version: "1.0.0"
|
||||||
|
status: Complete
|
||||||
|
library_path: "/storage1/Emulation/roms/gba/Pokemon - FakeHack [Hack].gba"
|
||||||
|
homepage: "https://example.com/fake"
|
||||||
|
source: "https://www.pokecommunity.com/threads/fake.1/"
|
||||||
|
---
|
||||||
|
|
||||||
|
# Pokémon FakeHack
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
See [[FakeHack]] still gated.
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import os, sys, tempfile, unittest
|
||||||
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
||||||
|
sys.path.insert(0, os.path.join(ROOT, "scripts"))
|
||||||
|
from update_swarm.jobs import build_jobs, init_run
|
||||||
|
|
||||||
|
FIXTURE = os.path.join(os.path.dirname(__file__), "fixtures", "vault", "Pokémon ROM Hacks")
|
||||||
|
|
||||||
|
class TestJobs(unittest.TestCase):
|
||||||
|
def test_flags_watchlist_and_wanted(self):
|
||||||
|
jobs = {j["stem"]: j for j in build_jobs(FIXTURE)}
|
||||||
|
self.assertIn("FakeHack", jobs)
|
||||||
|
self.assertTrue(jobs["FakeHack"]["wanted"])
|
||||||
|
self.assertFalse(jobs["FakeHack"]["watchlist"])
|
||||||
|
self.assertEqual(jobs["FakeHack"]["note_version"], "1.0.0")
|
||||||
|
self.assertTrue(jobs["DemoOnly"]["watchlist"])
|
||||||
|
self.assertFalse(jobs["DemoOnly"]["wanted"])
|
||||||
|
self.assertIsNone(jobs["DemoOnly"]["library_path"])
|
||||||
|
|
||||||
|
def test_init_run_creates_dirs(self):
|
||||||
|
with tempfile.TemporaryDirectory() as td:
|
||||||
|
run = os.path.join(td, "2026-08-14")
|
||||||
|
init_run(run)
|
||||||
|
for name in ("census", "scouts", "staging"):
|
||||||
|
self.assertTrue(os.path.isdir(os.path.join(run, name)))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in new issue
Block a user