72 lines
2.3 KiB
Python
72 lines
2.3 KiB
Python
"""Independent byte/pointer inventory; no inferred widget names or execution."""
|
|
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
OUT = Path(__file__).resolve().parent
|
|
|
|
|
|
def inventory():
|
|
p = next((ROOT / "example_ComfyUI_workflows").rglob("moge3_*.json"))
|
|
raw = p.read_bytes()
|
|
g = json.loads(raw)
|
|
fields = []
|
|
notes = []
|
|
empty = []
|
|
scopes = [("root", "", g)] + [
|
|
(s["id"], f"/definitions/subgraphs/{i}", s)
|
|
for i, s in enumerate(g["definitions"]["subgraphs"])
|
|
]
|
|
for scope, base, graph in scopes:
|
|
for i, n in enumerate(graph["nodes"]):
|
|
ptr = f"{base}/nodes/{i}/widgets_values"
|
|
if "widgets_values" not in n:
|
|
empty.append({"scope": scope, "node": n["id"], "state": "missing"})
|
|
continue
|
|
w = n["widgets_values"]
|
|
if not w:
|
|
empty.append(
|
|
{"scope": scope, "node": n["id"], "state": type(w).__name__, "value": w}
|
|
)
|
|
for k in w if isinstance(w, dict) else range(len(w)):
|
|
v = w[k]
|
|
e = {
|
|
"scope": scope,
|
|
"node": n["id"],
|
|
"pointer": ptr + "/" + str(k),
|
|
"json_type": type(v).__name__,
|
|
"value": v,
|
|
}
|
|
(notes if n["type"] == "MarkdownNote" else fields).append(e)
|
|
return {
|
|
"path": str(p.relative_to(ROOT)),
|
|
"sha256": hashlib.sha256(raw).hexdigest(),
|
|
"fields": fields,
|
|
"notes": notes,
|
|
"empty": empty,
|
|
"scopes": [
|
|
{
|
|
"scope": s,
|
|
"nodes": len(gr["nodes"]),
|
|
"edges": len(gr["links"]),
|
|
"canonical_sha256": hashlib.sha256(
|
|
json.dumps(
|
|
gr, ensure_ascii=False, sort_keys=True, separators=(",", ":")
|
|
).encode()
|
|
).hexdigest(),
|
|
"modes": [{"node": n["id"], "mode": n["mode"]} for n in gr["nodes"]],
|
|
}
|
|
for s, _, gr in scopes
|
|
],
|
|
}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
x = inventory()
|
|
(OUT / "independent-inventory.json").write_text(
|
|
json.dumps(x, ensure_ascii=False, indent=2) + "\n"
|
|
)
|
|
print(len(x["fields"]), len(x["notes"]), x["scopes"])
|