← Commit history

Delete tools/clips_subreadme.py

John Lauer ·9309442886 ·2d ago ·parent acc4de1
1 file changed −55
tools/clips_subreadme.pydeleted−55
@@ -1,55 +0,0 @@-#!/usr/bin/env python3-"""Rebuild docs/clips.md on the project's wiki page from the aiflow run folder and push it.-Run after EVERY step so the human can follow in a pup/webview tab (overnight runs leave a pile of clips).-Usage: clips_subreadme.py <run dir> <page owner/slug> <staging dir>-"""-import json, os, re, shutil, subprocess, sys, datetime-run, page, stage = sys.argv[1:4]-notes = json.load(open(os.path.join(run, "clip-notes.json")))-if not os.path.isdir(os.path.join(stage, ".")) or not os.listdir(stage):-    subprocess.run(["adom-wiki", "repo", "clone", page], cwd=os.path.dirname(stage), check=True, capture_output=True)-os.makedirs(os.path.join(stage, "docs", "clips"), exist_ok=True)-clips = sorted({re.sub(r"(-10x\.mp4|-sheet\.png|-action\.mp4|\.mp4)$", "", f) for f in os.listdir(run) if f.startswith("window-") and f.endswith((".mp4", ".png"))})-rows, blocks, files = [], [], []-for i, c in enumerate(clips, 1):-    n = notes.get(c, {"step": "(not yet described)", "shows": "", "state": "ok"})-    ts = re.search(r"(\d{8})-(\d{6})", c)-    when = datetime.datetime.strptime("".join(ts.groups()), "%Y%m%d%H%M%S").strftime("%Y-%m-%d %H:%M UTC") if ts else ""-    raw = os.path.join(run, c + ".mp4")-    mb = round(os.path.getsize(raw) / 1e6) if os.path.exists(raw) else None-    for suffix in ("-10x.mp4", "-sheet.png", "-action.mp4"):-        src = os.path.join(run, c + suffix)-        if os.path.exists(src):-            shutil.copyfile(src, os.path.join(stage, "docs", "clips", c + suffix)); files.append(f"docs/clips/{c}{suffix}")-    state = "ok" if n.get("state") == "ok" else "see note"-    rows.append(f"| {i} | {n['step']} | {when} | [10x cut](#clip-{i}) | {state} |")-    b = [f"### Clip {i}: {n['step']}", "", f"<a id=\"clip-{i}\"></a>", "", f"Recorded {when}. {n['shows']}", ""]-    if n.get("state") != "ok":-        b += [f"> Note: {n['state']}", ""]-    if os.path.exists(os.path.join(run, c + "-10x.mp4")):-        b += [f'<video src="docs/clips/{c}-10x.mp4" controls muted playsinline></video>', ""]-    if os.path.exists(os.path.join(run, c + "-action.mp4")):-        b += [f"Motion-only action cut: [docs/clips/{c}-action.mp4](clips/{c}-action.mp4)", ""]-    if os.path.exists(os.path.join(run, c + "-sheet.png")):-        b += [f"Contact sheet (nine frames): ![clip {i} contact sheet](docs/clips/{c}-sheet.png)", ""]-    if mb:-        b += [f"Raw recording: `{c}.mp4`, {mb} MB, kept with the run (not uploaded).", ""]-    blocks.append("\n".join(b))-md = ["# Build clips", "",-      "Every step of the adom-aiflow run records its own clip of the KiCad window on the test box. This page is appended as each clip lands, so it can stay open in a browser tab while the build runs.", "",-      f"Last updated {datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC')}. {len(clips)} clip(s).", "",-      "| # | step | recorded | clip | state |", "|---|---|---|---|---|", *rows, "", *blocks]-open(os.path.join(stage, "docs", "clips.md"), "w").write("\n".join(md) + "\n")-files.append("docs/clips.md")-readme = os.path.join(stage, "README.md")-r = open(readme).read() if os.path.exists(readme) else ""-if "docs/clips.md" not in r:-    r = r.rstrip() + "\n\n## Feature guides\n\n| guide | what it covers |\n|---|---|\n| [Build clips](docs/clips.md) | Every step's video clip from the adom-aiflow run, appended as the build goes. |\n"-    open(readme, "w").write(r); files.append("README.md")-blob = "\n".join(open(os.path.join(stage, f), errors="ignore").read() for f in files if f.endswith(".md"))-banned = os.environ.get("CLIPS_BANNED_RE")  # confidential names, kept out of the published source-if banned:-    assert not re.search(banned, blob, re.I), "a confidential name is in the payload"-assert "—" not in blob, "em-dash in the payload"-p = subprocess.run(["adom-wiki", "repo", "push", page, "--files", *files, "-m", f"clips: {len(clips)} clip(s)"], cwd=stage, capture_output=True, text=True)-print(p.stdout[-600:], p.stderr[-400:])