Files
aigc-home/docs/hel-892/storyboard-document-evidence/fetch_additional.py
T

116 lines
4.4 KiB
Python

"""Bounded release members and exact core tag, no plugin execution."""
import hashlib
import io
import json
import zipfile
from fetch_sources import REF, fetch
def main():
d = json.loads((REF / "sources.json").read_bytes())
entries = d["sources"]
for id, key, words in [
("comfyui-easy-use", "easy", ["logic.py", "__init__.py", "LICENSE", "pyproject.toml"]),
("comfy-mtb", "mtb", ["text.py", "__init__.py", "LICENSE", "pyproject.toml"]),
("comfyui-videohelpersuite", "vhs", ["load_images_nodes.py"]),
]:
url = (
json.loads((REF / (id + "-version.json")).read_bytes())["downloadUrl"]
if key != "vhs"
else "https://cdn.comfy.org/kosinkadink/comfyui-videohelpersuite/1.7.7/node.zip"
)
raw = fetch(url)
digest = hashlib.sha256(raw).hexdigest()
if key == "vhs":
assert digest == "f845b43edc8342439c42809524669f8aceecfb9eca946d660e351364d341d9b1"
with zipfile.ZipFile(io.BytesIO(raw)) as z:
selected = [
n for n in z.namelist() if any(n == w or n.endswith("/" + w) for w in words)
]
# Root registration and only the chosen implementation.
selected = [
n
for n in selected
if n in words or n in ["py/nodes/logic.py", "videohelpersuite/load_images_nodes.py"]
]
(REF / (key + "-package-index.json")).write_text(
json.dumps(
dict(url=url, sha256=digest, members=z.namelist(), selected=selected),
ensure_ascii=False,
indent=2,
)
+ "\n"
)
for n in selected:
data = z.read(n)
name = key + "__" + n.replace("/", "__")
(REF / name).write_bytes(data)
entries.append(
dict(
id=key,
file=n,
local_file=name,
url=url,
commit="发布包SHA256:" + digest,
sha256=hashlib.sha256(data).hexdigest(),
git_commit_binding="unknown",
)
)
commit = json.loads((REF / "core-tag.json").read_bytes())["object"]["sha"]
repo = "Comfy-Org/ComfyUI"
raw = fetch(f"https://api.github.com/repos/{repo}/git/trees/{commit}?recursive=1")
(REF / "core-tree.json").write_bytes(raw)
blobs = {x["path"]: x["sha"] for x in json.loads(raw)["tree"] if x["type"] == "blob"}
for file in ["comfy_extras/nodes_audio.py", "nodes.py", "folder_paths.py", "LICENSE"]:
url = f"https://raw.githubusercontent.com/{repo}/{commit}/{file}"
raw = fetch(url)
name = "core__" + file.replace("/", "__")
(REF / name).write_bytes(raw)
blob = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
assert blob == blobs[file]
entries.append(
dict(
id="core",
file=file,
local_file=name,
url=url,
commit=commit,
sha256=hashlib.sha256(raw).hexdigest(),
git_blob_sha1=blob,
)
)
# necessary LayerStyle helper; never import.
e = next(e for e in entries if e["id"] == "layer")
file = "py/imagefunc.py"
url = e["url"].rsplit("/", 1)[0] + "/py/imagefunc.py" if e["file"] == "__init__.py" else ""
url = (
"https://raw.githubusercontent.com/chflame163/"
"ComfyUI_LayerStyle/3b17c7f488006c872f4cb3d6b3"
"7029a9464f1d7b/"
) + file
raw = fetch(url)
name = "layer__py__imagefunc.py"
(REF / name).write_bytes(raw)
tree = json.loads((REF / "layer-tree.json").read_bytes())
blob = next(x["sha"] for x in tree["tree"] if x["path"] == file)
assert hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest() == blob
entries.append(
dict(
id="layer",
file=file,
local_file=name,
url=url,
commit=e["commit"],
sha256=hashlib.sha256(raw).hexdigest(),
git_blob_sha1=blob,
)
)
(REF / "sources.json").write_text(json.dumps(d, ensure_ascii=False, indent=2) + "\n")
print("PASS", len(entries), "exact texts; package Git bindings unknown")
if __name__ == "__main__":
main()