"""Fetch a bounded template module and audio helper descriptor chain as text.""" import hashlib import io import json import zipfile from fetch_sources import REF, fetch def main(): d = json.loads((REF / "sources.json").read_bytes()) es = [ e for e in d["sources"] if not ( e["id"] == "mtb" and e["file"] in [ "nodes/graph_utils.py", "nodes/constant.py", "log.py", "web/mtb_ui.js", "web/mtb_widgets.js", "web/comfy_shared.js", "wiki/nodes/nodes-apply-text-template.md", ] ) and not ( e["id"] == "core" and e["file"] in ["comfy_api/latest/_ui.py", "comfy_api/latest/_io.py"] ) ] d["sources"] = es meta = json.loads((REF / "mtb-package-index.json").read_bytes()) raw = fetch(meta["url"]) assert hashlib.sha256(raw).hexdigest() == meta["sha256"] with zipfile.ZipFile(io.BytesIO(raw)) as z: for n in [ "nodes/graph_utils.py", "log.py", "web/mtb_ui.js", "web/mtb_widgets.js", "web/comfy_shared.js", "wiki/nodes/nodes-apply-text-template.md", ]: data = z.read(n) name = "mtb__" + n.replace("/", "__") (REF / name).write_bytes(data) es.append( dict( id="mtb", file=n, local_file=name, url=meta["url"], commit="发布包SHA256:" + meta["sha256"], sha256=hashlib.sha256(data).hexdigest(), git_commit_binding="unknown", ) ) commit = json.loads((REF / "core-tag.json").read_bytes())["object"]["sha"] tree = json.loads((REF / "core-tree.json").read_bytes()) blobs = {x["path"]: x["sha"] for x in tree["tree"] if x["type"] == "blob"} for file in ["comfy_api/latest/_ui.py", "comfy_api/latest/_io.py"]: url = f"https://raw.githubusercontent.com/Comfy-Org/ComfyUI/{commit}/{file}" raw = fetch(url) blob = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest() assert blob == blobs[file] name = "core__" + file.replace("/", "__") (REF / name).write_bytes(raw) es.append( dict( id="core", file=file, local_file=name, url=url, commit=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(es), "texts") if __name__ == "__main__": main()