66 lines
2.3 KiB
Python
66 lines
2.3 KiB
Python
"Independent physical saved-position inventory; never infer widgets from position."
|
|
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
OUT = Path(__file__).resolve().parent
|
|
|
|
|
|
def inventory():
|
|
path = next((ROOT / "example_ComfyUI_workflows").rglob("VOSR2_视频放大_分批循环长视频.json"))
|
|
raw = path.read_bytes()
|
|
g = json.loads(raw)
|
|
d = g["definitions"]["subgraphs"][0]
|
|
fields = []
|
|
notes = []
|
|
empty = []
|
|
for scope, base, nodes in [
|
|
("root", "", g["nodes"]),
|
|
(d["id"], "/definitions/subgraphs/0", d["nodes"]),
|
|
]:
|
|
for i, n in enumerate(nodes):
|
|
pointer = f"{base}/nodes/{i}/widgets_values"
|
|
if "widgets_values" not in n:
|
|
empty.append(dict(node=n["id"], scope=scope, state="missing"))
|
|
continue
|
|
w = n["widgets_values"]
|
|
for k in w if isinstance(w, dict) else range(len(w)):
|
|
v = w[k]
|
|
e = dict(
|
|
pointer=pointer + "/" + str(k),
|
|
node=n["id"],
|
|
scope=scope,
|
|
json_type=type(v).__name__,
|
|
value=v,
|
|
)
|
|
(notes if n["type"] == "MarkdownNote" else fields).append(e)
|
|
if not w:
|
|
empty.append(dict(node=n["id"], scope=scope, state=type(w).__name__, value=w))
|
|
return dict(
|
|
path=str(path.relative_to(ROOT)),
|
|
sha256=hashlib.sha256(raw).hexdigest(),
|
|
canonical_subgraph_sha256=hashlib.sha256(
|
|
json.dumps(d, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode()
|
|
).hexdigest(),
|
|
root_nodes=len(g["nodes"]),
|
|
root_edges=len(g["links"]),
|
|
internal_nodes=len(d["nodes"]),
|
|
internal_edges=len(d["links"]),
|
|
fields=fields,
|
|
notes=notes,
|
|
empty=empty,
|
|
boundary_inputs=d["inputs"],
|
|
boundary_outputs=d["outputs"],
|
|
special_edge=next(e for e in d["links"] if e["id"] == 143),
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
x = inventory()
|
|
(OUT / "independent-inventory.json").write_text(
|
|
json.dumps(x, ensure_ascii=False, indent=2) + "\n"
|
|
)
|
|
print("Independent:", len(x["fields"]), "saved positions,", len(x["notes"]), "notes")
|