Files
aigc-home/docs/hel-892/krea-style-document-evidence/supplement_sources.py
T
2026-10-31 21:58:16 +08:00

69 lines
2.3 KiB
Python

"Fetch only selected missing pinned text blobs; never import or execute upstream."
import datetime
import hashlib
import json
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parents[3]
REF = Path(__file__).resolve().parent.parent / "krea-style-reference"
def main():
rows = json.loads((REF / "sources.json").read_bytes())["sources"]
for key, file in [
("core0280", "comfy/samplers.py"),
(
"frontend",
("src/renderer/extensions/vueNodes/widgets/composables/useImageUploadWidget.ts"),
),
]:
if any(e["id"] == key and e["file"] == file for e in rows):
continue
parent = next(e for e in rows if e["id"] == key)
cache = ROOT / ".local-evidence" / ("krea-style-" + key + "-git")
raw = subprocess.check_output(
["git", "-C", str(cache), "show", parent["commit"] + ":" + file]
)
entry = next(
e
for e in json.loads((REF / (key + "-tree.json")).read_bytes())["tree"]
if e["path"] == file
)
e = dict(
parent,
file=file,
local_file=key + "__" + file.replace("/", "__"),
url=f"https://raw.githubusercontent.com/{parent['repo']}/{parent['commit']}/{file}",
sha256=hashlib.sha256(raw).hexdigest(),
git_blob_sha1=entry["sha"],
acquisition_time=datetime.datetime.now(datetime.timezone.utc).isoformat(),
)
(REF / e["local_file"]).write_bytes(raw)
rows.append(e)
rows = [
e
for e in rows
if not (
e["id"] == "core0250"
and e["file"] in ["comfy_extras/nodes_resolution.py", "comfy/samplers.py"]
)
]
now = datetime.datetime.now(datetime.timezone.utc).isoformat()
for e in rows:
if "reverified_at" not in e:
e["reverified_at"] = now
if e["id"] == "core0250":
e["reuse_from"] = "docs/hel-892/krea-image2-reference/" + Path(e["local_file"]).name
e["applicability"] = (
"本图独立准确声明版本静态参考;获取时间与本图复核时间分列,不执行或认证目标恢复/环境"
)
(REF / "sources.json").write_text(
json.dumps(dict(sources=rows), ensure_ascii=False, indent=2) + "\n"
)
if __name__ == "__main__":
main()