capture_cd.sh used $B inside a quoted heredoc and never exported B, so the capture shell expanded $B to empty and every C+D screenshot showed /bin/sh: 1: /<tool>: not found. Fixed capture_one.py (prepends bin/ to PATH) and capture_cd.sh (bare names + exported PATH); new tools/regen_shots.py regenerates with a verification gate that rejects shell failures and keeps the old PNG on failure. All 310 screenshots regenerated, prompts now show the command as the user types it. Also fixed netusage --today misleading message with a single snapshot (needs two for deltas) and added __pycache__/ to .gitignore. Full suite 310/310; all 311 README/article examples audited (310 ok, 1 false positive from the marker matching netusage:).
52 lines
1.8 KiB
Python
Executable File
52 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Run one util_box command in a sandbox dir, capture its real output,
|
|
and render it as a terminal screenshot PNG.
|
|
|
|
The command MUST be given as the user types it (bare tool name, bin/ on
|
|
PATH) — the prompt line in the screenshot shows the command verbatim, so
|
|
a $B variable or an absolute path in the command lands in the image.
|
|
This script prepends /root/fileutils/bin to PATH for the child shell, so
|
|
bare names always resolve; never pass $B/... or /root/fileutils/bin/...
|
|
|
|
Usage: capture_one.py <name> "<command>" <workdir> <out.png>
|
|
The command runs with a 15 s timeout; if it times out, whatever it
|
|
printed so far is used, marked as truncated.
|
|
"""
|
|
import subprocess
|
|
import sys
|
|
|
|
RENDER = "/root/fileutils/tools/render_shot.py"
|
|
|
|
|
|
def main():
|
|
name, cmd, workdir, png = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]
|
|
out = ""
|
|
env = dict(__import__("os").environ)
|
|
env["PATH"] = "/root/fileutils/bin:" + env.get("PATH", "")
|
|
try:
|
|
p = subprocess.run(
|
|
cmd, shell=True, cwd=workdir, capture_output=True,
|
|
text=True, timeout=15, env=env,
|
|
)
|
|
out = (p.stdout + p.stderr).strip()
|
|
except subprocess.TimeoutExpired as e:
|
|
so = (e.stdout or b"").decode(errors="replace")
|
|
se = (e.stderr or b"").decode(errors="replace")
|
|
out = (so + se).strip()
|
|
out += "\n[still running after 15s — output truncated]"
|
|
if not out:
|
|
out = "[no output]"
|
|
lines = out.splitlines()[:40]
|
|
session = "$ " + cmd + "\n" + "\n".join(lines) + "\n"
|
|
txt = "/tmp/shot-%s.txt" % name
|
|
with open(txt, "w", encoding="utf-8") as f:
|
|
f.write(session)
|
|
subprocess.run(
|
|
["python3", RENDER, txt, png, name], check=True,
|
|
)
|
|
print(png)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|