Files
aigc-home/docs/hel-892/zimage-document-evidence/fetch_sources.py
T
2026-10-31 08:35:25 +08:00

134 lines
4.6 KiB
Python

"Acquire necessary pinned text only; no upstream imports or execution."
import datetime
import hashlib
import json
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parents[3]
OUT = Path(__file__).resolve().parent
REF = OUT.parent / "zimage-reference"
def main():
rows = []
specs = [
(
"core",
"Comfy-Org/ComfyUI",
"v0.3.75",
[
"nodes.py",
"folder_paths.py",
"comfy_extras/nodes_primitive.py",
"comfy_extras/nodes_sd3.py",
"comfy/samplers.py",
"comfy/sample.py",
"comfy/cli_args.py",
"comfy_api/latest/_io.py",
"LICENSE",
],
),
("lora", "Comfy-Org/ComfyUI", "v0.5.1", ["nodes.py", "LICENSE"]),
(
"frontend",
"Comfy-Org/ComfyUI_frontend",
"v1.23.0",
[
"package.json",
"package-lock.json",
"src/scripts/widgets.ts",
"src/scripts/app.ts",
"src/extensions/core/widgetInputs.ts",
"src/extensions/core/rerouteNode.ts",
"LICENSE",
],
),
(
"tt",
"AICoderTudou/ComfyUI-TT-Resolution_selector-Node",
"b69cf75c2ce5f864e3db5301dba46a6b5eeaa8fb",
["__init__.py", "nodes/resolution_selector.py", "LICENSE"],
),
]
for key, repo, tag, files in specs:
cache = ROOT / ".local-evidence" / ("zimage-" + key + "-git")
cache.mkdir(parents=True, exist_ok=True)
subprocess.run(["git", "init", "--bare", str(cache)], check=True, stdout=subprocess.DEVNULL)
subprocess.run(
[
"git",
"-C",
str(cache),
"fetch",
"--filter=blob:none",
"--depth=1",
"https://github.com/" + repo + ".git",
("refs/tags/" + tag) if tag.startswith("v") else tag,
],
check=True,
)
def git(*args):
return subprocess.check_output(["git", "-C", str(cache), *args])
rev = git("rev-parse", "FETCH_HEAD^{commit}").decode().strip()
tree = git("rev-parse", rev + "^{tree}").decode().strip()
(REF / (key + "-commit.txt")).write_bytes(git("cat-file", "commit", rev))
(REF / (key + "-tag.txt")).write_bytes(git("cat-file", "-p", "FETCH_HEAD"))
(REF / (key + "-tag.json")).write_text(
json.dumps(
dict(
ref=("refs/tags/" + tag) if tag.startswith("v") else tag,
commit=rev,
object=git("rev-parse", "FETCH_HEAD").decode().strip(),
),
indent=2,
)
+ "\n"
)
entries = []
for line in git("ls-tree", "-r", rev).decode().splitlines():
head, path = line.split("\t", 1)
mode, kind, sha = head.split()
entries.append(dict(path=path, mode=mode, type=kind, sha=sha))
(REF / (key + "-tree.json")).write_text(
json.dumps(dict(sha=tree, truncated=False, tree=entries), indent=2) + "\n"
)
missing = []
for f in files:
ent = next((x for x in entries if x["path"] == f), None)
if ent is None:
missing.append(f)
continue
raw = git("show", rev + ":" + f)
name = key + "__" + f.replace("/", "__")
(REF / name).write_bytes(raw)
rows.append(
dict(
id=key,
repo=repo,
file=f,
local_file=name,
commit=rev,
tree=tree,
tag=tag,
url=f"https://raw.githubusercontent.com/{repo}/{rev}/{f}",
sha256=hashlib.sha256(raw).hexdigest(),
git_blob_sha1=ent["sha"],
acquisition_time=datetime.datetime.now(datetime.timezone.utc).isoformat(),
license_file=key + ("__LICENSE.txt" if key == "dw" else "__LICENSE"),
transport="filtered git; selected text blobs only",
applicability="本图独立声明版本;UE/tab/宿主恢复未知",
)
)
(REF / (key + "-absent.json")).write_text(json.dumps(missing, indent=2) + "\n")
(REF / "new-sources.json").write_text(
json.dumps(dict(sources=rows), ensure_ascii=False, indent=2) + "\n"
)
if __name__ == "__main__":
main()