Files
aigc-home/docs/hel-892/zimage-hd-document-evidence/complete_sources.py
T
2026-10-31 16:53:27 +08:00

57 lines
2.0 KiB
Python

"""Select missing necessary exact text from the already pinned Git trees only."""
import datetime
import hashlib
import json
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parents[3]
REF = Path(__file__).resolve().parent.parent / "zimage-hd-reference"
def main():
rows = json.loads((REF / "sources.json").read_bytes())["sources"]
for key, files in {
"seed": [
"src/interfaces/dit_model_loader.py",
"src/interfaces/vae_model_loader.py",
"src/interfaces/__init__.py",
"src/utils/model_paths.py",
"src/utils/model_registry.py",
],
}.items():
origin = next(e for e in rows if e["id"] == key)
cache = ROOT / ".local-evidence" / ("zimage-hd-" + key + "-git")
entries = json.loads((REF / (key + "-tree.json")).read_bytes())["tree"]
for file in files:
if any(e["id"] == key and e["file"] == file for e in rows):
continue
ent = next((e for e in entries if e["path"] == file), None)
if ent is None:
continue
data = subprocess.check_output(
["git", "-C", str(cache), "show", origin["commit"] + ":" + file]
)
name = key + "__" + file.replace("/", "__")
(REF / name).write_bytes(data)
rows.append(
dict(
origin,
file=file,
local_file=name,
sha256=hashlib.sha256(data).hexdigest(),
git_blob_sha1=ent["sha"],
url=f"https://raw.githubusercontent.com/{origin['repo']}/{origin['commit']}/{file}",
acquisition_time=datetime.datetime.now(datetime.timezone.utc).isoformat(),
)
)
(REF / "sources.json").write_text(
json.dumps(dict(sources=rows), ensure_ascii=False, indent=2) + "\n"
)
print("PASS necessary text only", len(rows), "sources; no archive or assets")
if __name__ == "__main__":
main()