-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclaim_workflow.py
More file actions
33 lines (25 loc) · 1012 Bytes
/
claim_workflow.py
File metadata and controls
33 lines (25 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import argparse
import re
from machineid import hashed_id
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
prog="claim_workflow",
description="make a workflow that uses ComfyUI-Execute-Python nodes usable on the current machine. "
"modifies workflow (JSON) in place",
)
parser.add_argument("input", type=str, help="path to the workflow (JSON)")
return parser.parse_args()
def main() -> None:
args = parse_args()
id_regex = re.compile('"ExecutePython([a-f0-9]{64})?"')
id_ = f'"ExecutePython{hashed_id("ComfyUI-Execute-Python")}"'
with open(args.input, "r", encoding="utf-8") as f:
content = f.read()
new_content, n_subs = id_regex.subn(id_, content)
if n_subs == 0:
raise RuntimeError("no ComfyUI-Execute-Python nodes found in the workflow")
print(f"found {n_subs} nodes")
with open(args.input, "w", encoding="utf-8") as f:
f.write(new_content)
if __name__ == "__main__":
main()