48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
"""Exclusive foreground batch179 logs; no background work or cross-batch glob."""
|
|
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
LOCAL = ROOT / ".local-evidence/batch180-exact-engine"
|
|
|
|
|
|
def main():
|
|
key, *command = sys.argv[1:]
|
|
assert key.replace("-", "").isalnum() and command
|
|
paths = [LOCAL / "logs" / f"batch180-exact-engine-{key}.{s}.txt" for s in ("stdout", "stderr")]
|
|
record = LOCAL / "records" / (key + ".json")
|
|
assert not record.exists() and not any(p.exists() for p in paths)
|
|
with paths[0].open("xb") as stdout, paths[1].open("xb") as stderr:
|
|
result = subprocess.run(command, cwd=ROOT, stdout=stdout, stderr=stderr)
|
|
with record.open("x") as f:
|
|
json.dump(
|
|
dict(
|
|
key=key,
|
|
command=command,
|
|
cwd="repository root",
|
|
returncode=result.returncode,
|
|
logs=[
|
|
dict(
|
|
path=str(p.relative_to(ROOT)),
|
|
bytes=p.stat().st_size,
|
|
sha256=hashlib.sha256(p.read_bytes()).hexdigest(),
|
|
)
|
|
for p in paths
|
|
],
|
|
),
|
|
f,
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
f.write("\n")
|
|
print(key, "exit", result.returncode)
|
|
raise SystemExit(result.returncode)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|