"""Restore the documented ancillary file tree and replay a selected section.""" from hashlib import sha256 import json from pathlib import Path import subprocess import sys from tempfile import TemporaryDirectory root = Path(__file__).resolve().parent with TemporaryDirectory(prefix="polygon-certificates-") as directory: destination = Path(directory) for volume in sorted(root.glob("materials-*.json")): for name, entry in json.loads(volume.read_text(encoding="utf-8")).items(): file = destination / name if not file.resolve().is_relative_to(destination.resolve()): raise ValueError("Invalid path: " + name) contents = entry["text"].encode("utf-8") if sha256(contents).hexdigest() != entry["sha256"]: raise ValueError("Unexpected contents: " + name) file.parent.mkdir(parents=True, exist_ok=True) file.write_bytes(contents) subprocess.run([sys.executable, str(destination / "verify.py"), *sys.argv[1:]], check=True)