Files
aigc-home/docs/hel-892/zimage-style-document-evidence/source_closure.py
T
2026-10-31 16:13:50 +08:00

54 lines
1.7 KiB
Python

"List source texts and their identity/permission evidence, without self hashing."
import hashlib
import json
from build_definition import OUT, REF, REPO
def main():
rows = json.loads((REF / "sources.json").read_bytes())["sources"]
paths = {p.resolve() for p in REF.iterdir() if p.is_file()}
for e in rows:
paths.add((REF / e["local_file"]).resolve())
if not e["license_file"].startswith("未知"):
paths.add((REF / e["license_file"]).resolve())
base = REF / e["identity_root"]
paths.update(
(base / (e["identity_key"] + suffix)).resolve()
for suffix in ["-commit.txt", "-tag.txt", "-tag.json", "-tree.json"]
)
paths.update(p.resolve() for p in REF.glob("*registry*.json"))
result = []
for p in sorted(paths):
raw = p.read_bytes()
result.append(
dict(
path=str(p.relative_to(REPO)),
sha256=hashlib.sha256(raw).hexdigest(),
purpose="准确来源原文、许可或Git对象绑定;静态读取未执行",
)
)
(OUT / "source-closure.json").write_text(
json.dumps(
dict(
files=result,
count=len(result),
upstream_executed=False,
note=(
"commit/tag字节和选定blob已重算;tree列表非完整树对象"
"重哈希。本批只有选定Git文本与元数据,没有整包获取;未安"
"装。"
),
),
ensure_ascii=False,
indent=2,
)
+ "\n"
)
print("PASS source closure", len(result))
if __name__ == "__main__":
main()