Files
aigc-home/docs/hel-892/krea-turbo-document-evidence/extend_sources.py
T
2026-10-31 19:19:42 +08:00

61 lines
2.0 KiB
Python

"Fetch only necessary additional text from already pinned filtered Git trees."
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-turbo-reference"
SPECS = {
"frontend": [
"src/core/graph/widgets/dynamicWidgets.ts",
"src/core/graph/widgets/dynamicTypes.ts",
("src/lib/litegraph/src/subgraph/SubgraphNode.ts"),
],
"core0250": [
"comfy_api/latest/__init__.py",
"comfy_api/latest/_io.py",
"comfy_api/latest/_io_public.py",
],
}
def main():
rows = json.loads((REF / "sources.json").read_bytes())["sources"]
for key, files in SPECS.items():
base = next(x for x in rows if x["id"] == key)
tree = json.loads((REF / (key + "-tree.json")).read_bytes())
cache = ROOT / ".local-evidence" / ("krea-turbo-" + key + "-git")
for file in files:
ent = next(x for x in tree["tree"] if x["path"] == file)
raw = subprocess.check_output(
["git", "-C", str(cache), "show", base["commit"] + ":" + file]
)
name = key + "__" + file.replace("/", "__")
(REF / name).write_bytes(raw)
row = dict(
base,
file=file,
local_file=name,
url="https://raw.githubusercontent.com/"
+ base["repo"]
+ "/"
+ base["commit"]
+ "/"
+ file,
sha256=hashlib.sha256(raw).hexdigest(),
git_blob_sha1=ent["sha"],
acquisition_time=datetime.datetime.now(datetime.timezone.utc).isoformat(),
)
rows = [x for x in rows if (x["id"], x["file"]) != (key, file)] + [row]
(REF / "sources.json").write_text(
json.dumps({"sources": rows}, ensure_ascii=False, indent=2) + "\n"
)
print("PASS selected additional text", sum(map(len, SPECS.values())))
if __name__ == "__main__":
main()