-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.py
84 lines (72 loc) · 3.13 KB
/
install.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
import shutil
annotating_js_files = [
"../efficiency-nodes-comfyui/js/node_options/addLinks.js",
"../efficiency-nodes-comfyui/js/node_options/addScripts.js",
"../efficiency-nodes-comfyui/js/node_options/addXYinputs.js",
"../efficiency-nodes-comfyui/js/node_options/modelInfo.js",
"../efficiency-nodes-comfyui/js/node_options/setResolution.js",
"../efficiency-nodes-comfyui/js/node_options/swapLoaders.js",
"../efficiency-nodes-comfyui/js/node_options/swapSamplers.js",
"../efficiency-nodes-comfyui/js/node_options/swapScripts.js",
"../efficiency-nodes-comfyui/js/node_options/swapXYinputs.js",
"../efficiency-nodes-comfyui/js/node_options/common/modelInfoDialog.js",
]
impact_wildcard_py = "../ComfyUI-Impact-Pack/modules/impact/wildcards.py"
read_css_folder = "./user_css/"
write_css_folder = "../../web/"
user_css = "user.css"
def annotate_file(js_file):
contents = []
if os.path.isfile(js_file):
with open(js_file, 'r', encoding='UTF8') as f:
contents = f.readlines()
with open(js_file, 'w', encoding='UTF8') as f:
for c in contents:
if c[:5] == "//** ":
f.write(c)
else:
f.write("//** "+c)
def restore_annotate_file(js_file):
contents = []
if os.path.isfile(js_file):
with open(js_file, 'r', encoding='UTF8') as f:
contents = f.readlines()
with open(js_file, 'w', encoding='UTF8') as f:
for c in contents:
if c[:5] == "//** ":
f.write(c[5:])
else:
f.write(c)
def annotate_wildcard(py_file):
contents = []
if os.path.isfile(py_file):
with open(py_file, 'r', encoding='UTF8') as f:
contents = f.readlines()
with open(py_file, 'w', encoding='UTF8') as f:
for c in contents:
if 'print(f"CLIP: {str.join(' in c and not "## from ED ##" in c:
f.write("## from ED ##" + c)
else:
f.write(c)
def copy_user_css():
if os.path.isfile(write_css_folder + user_css):
os.remove(write_css_folder + user_css)
shutil.copy(read_css_folder + user_css, write_css_folder + user_css)
def restore_user_css():
if os.path.isfile(write_css_folder + user_css):
os.remove(write_css_folder + user_css)
if os.path.isfile(write_css_folder + user_css + ".old"):
os.rename(write_css_folder + user_css + ".old", write_css_folder + user_css)
else:
with open(write_css_folder + user_css, 'w', encoding='UTF8') as f:
f.write("/* Put custom styles here */")
try:
printout = "Copy user.css and Disable unnecessary js files"
for file in annotating_js_files:
annotate_file(file)
annotate_wildcard(impact_wildcard_py)
copy_user_css()
print(f"Efficiency Nodes ED: Attempting to {printout} success!")
except Exception as e:
print("[ERROR] efficiency nodes ED: An error occurred while annotating the file.")