Files
aigc-home/docs/hel-892/flux2-lineart-document-evidence/acquire.py
T

122 lines
3.8 KiB
Python

"""Fetch only source text, tree and commit metadata; never import upstream."""
import concurrent.futures
import hashlib
import json
import urllib.request
from pathlib import Path
OUT = Path(__file__).resolve().parent
REF = OUT.parent / "flux2-lineart-reference"
def get(url):
with urllib.request.urlopen(url, timeout=30) as r:
return r.read()
def acquire(spec):
key, repo, ref, files = spec
commit = json.loads(get(f"https://api.github.com/repos/{repo}/commits/{ref}"))
sha = commit["sha"]
tree = json.loads(get(f"https://api.github.com/repos/{repo}/git/trees/{sha}?recursive=1"))
(REF / f"{key}-commit.json").write_text(json.dumps(commit, indent=2))
(REF / f"{key}-tree.json").write_text(json.dumps(tree, indent=2))
rows = []
for file in files:
entry = next((e for e in tree["tree"] if e["path"] == file), None)
if entry is None:
print("ABSENT", key, file)
continue
url = f"https://raw.githubusercontent.com/{repo}/{sha}/{file}"
data = get(url)
name = key + "__" + file.replace("/", "__")
blob = hashlib.sha1(b"blob " + str(len(data)).encode() + b"\0" + data).hexdigest()
assert blob == entry["sha"]
(REF / name).write_bytes(data)
rows.append(
dict(
id=key,
repo=repo,
tag=ref,
commit=sha,
tree=commit["commit"]["tree"]["sha"],
file=file,
local_file=name,
url=url,
sha256=hashlib.sha256(data).hexdigest(),
git_blob_sha1=blob,
license_file="见同id许可文本或缺失记录",
applicability="本图独立静态参考;目标安装、发布包映射及恢复未知",
)
)
print("FETCHED", key, len(rows), flush=True)
return rows
def main():
specs = [
(
"painter",
"princepainter/ComfyUI-PainterNodes",
("66eb4c6edc6dd52cd0a5f5d786caedf252ea2a87"),
["PainterFluxImageEdit.py", "__init__.py", "LICENSE", "pyproject.toml"],
),
(
"llama",
"lihaoyun6/ComfyUI-llama-cpp_vlm",
("a69be4883f98c4025915f0390a3e87aae9ea3477"),
[
"nodes.py",
"__init__.py",
"pyproject.toml",
"LICENSE",
"support/prompt_enhancer_preset.py",
],
),
(
"frontend",
"Comfy-Org/ComfyUI_frontend",
"v1.23.0",
[
"package.json",
"package-lock.json",
"src/scripts/widgets.ts",
"src/extensions/core/uploadImage.ts",
"LICENSE",
],
),
("load", "Comfy-Org/ComfyUI", "v0.3.68", ["nodes.py", "LICENSE"]),
(
"save",
"Comfy-Org/ComfyUI",
"v0.9.2",
["nodes.py", "folder_paths.py", "LICENSE"],
),
(
"aux",
"Fannovel16/comfyui_controlnet_aux",
("e8b689a513c3e6b63edc44066560ca5919c0576e"),
[
"node_wrappers/anyline.py",
"node_wrappers/canny.py",
"node_wrappers/depth_anything.py",
"node_wrappers/zoe.py",
"node_wrappers/densepose.py",
"__init__.py",
"utils.py",
"pyproject.toml",
"LICENSE.txt",
],
),
]
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as pool:
rows = [e for group in pool.map(acquire, specs) for e in group]
(REF / "sources.json").write_text(
json.dumps(dict(sources=rows), ensure_ascii=False, indent=2) + "\n"
)
if __name__ == "__main__":
main()