63 lines
1.7 KiB
Python
Executable file
63 lines
1.7 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
|
|
|
|
def sha256_file(path: Path) -> str:
|
|
h = hashlib.sha256()
|
|
with path.open("rb") as f:
|
|
for chunk in iter(lambda: f.read(1024 * 1024), b""):
|
|
h.update(chunk)
|
|
return h.hexdigest()
|
|
|
|
|
|
def build_asl_manifest(root: Path) -> dict:
|
|
artifacts_dir = root / "artifacts"
|
|
fixtures = []
|
|
for entry in sorted(artifacts_dir.iterdir()):
|
|
if not entry.is_file() or entry.suffix != ".bin":
|
|
continue
|
|
artifact_rel = f"artifacts/{entry.name}"
|
|
fixtures.append(
|
|
{
|
|
"id": entry.stem,
|
|
"artifact": artifact_rel,
|
|
"size": str(entry.stat().st_size),
|
|
"sha256": sha256_file(entry),
|
|
}
|
|
)
|
|
return {"schema": "amduat.conformance.fixtures.v0", "fixtures": fixtures}
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(
|
|
description="Generate conformance fixture manifests."
|
|
)
|
|
parser.add_argument(
|
|
"root",
|
|
type=Path,
|
|
help="Fixture directory containing artifacts/",
|
|
)
|
|
parser.add_argument(
|
|
"--out",
|
|
type=Path,
|
|
default=None,
|
|
help="Output manifest path (defaults to <root>/manifest.json)",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
manifest = build_asl_manifest(args.root)
|
|
out_path = args.out or (args.root / "manifest.json")
|
|
out_path.parent.mkdir(parents=True, exist_ok=True)
|
|
with out_path.open("w", encoding="utf-8") as f:
|
|
json.dump(manifest, f, indent=2, sort_keys=False)
|
|
f.write("\n")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|