-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy path__init__.py
168 lines (146 loc) · 5.43 KB
/
__init__.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import inspect
import os
import re
import shutil
import subprocess
import sys
from .install import (
check_and_uninstall_websocket,
get_system_info,
init_temp,
install_llama,
install_portaudio,
manage_discord_packages,
)
from .config_update import update_config
from .llm import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
from server import PromptServer
def get_comfy_dir(subpath=None, mkdir=False):
dir = os.path.dirname(inspect.getfile(PromptServer))
if subpath is not None:
dir = os.path.join(dir, subpath)
dir = os.path.abspath(dir)
if mkdir and not os.path.exists(dir):
os.makedirs(dir)
return dir
def get_web_ext_dir(path):
dir = get_comfy_dir(path)
if not os.path.exists(dir):
os.makedirs(dir)
return dir
def copy_js_files(ext_path):
# 设置当前文件夹路径和目标文件夹路径
current_folder = os.path.dirname(os.path.abspath(__file__))
target_folder = get_web_ext_dir(ext_path) # 改为用户目录下的文件夹
# 确保目标文件夹存在
try:
os.makedirs(target_folder, exist_ok=True)
except PermissionError:
print(f"没有权限创建目录 {target_folder}")
return
# 清空目标文件夹里所有文件
for filename in os.listdir(target_folder):
file_path = os.path.join(target_folder, filename)
try:
if os.path.isfile(file_path) or os.path.islink(file_path):
os.unlink(file_path)
except Exception as e:
print(f"无法删除文件 {file_path}: {e}")
# 获取当前文件夹中web子文件夹下的所有.js文件
js_files = [f for f in os.listdir(os.path.join(current_folder, "web","js")) if f.endswith(".js")]
# 复制文件
for file_name in js_files:
source_file = os.path.join(current_folder, "web","js", file_name)
target_file = os.path.join(target_folder, file_name)
try:
shutil.copy2(source_file, target_file)
except Exception as e:
print(f"无法复制文件 {source_file} 到 {target_file}: {e}")
def get_latest_version_folder(directory):
version_pattern = re.compile(r'(\d+\.\d+\.\d+)')
latest_version = None
latest_folder = None
for folder_name in os.listdir(directory):
folder_path = os.path.join(directory, folder_name)
if os.path.isdir(folder_path):
match = version_pattern.search(folder_name)
if match:
version = match.group(1)
if latest_version is None or version > latest_version:
latest_version = version
latest_folder = folder_path
return latest_folder
def install_playwright_browsers():
python_executable = sys.executable
# 检查python版本>=3.11
if sys.version_info < (3, 11):
print("Python version must be 3.11 or higher to install browser_use.If you don't need to use browser_use, you can ignore this warning.")
return
else:
# 安装browser_use,如果已经安装就跳过
try:
result = subprocess.run(
[python_executable, "-m", "pip", "install", "browser_use"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=True
)
if "already up-to-date" in result.stderr or "already up-to-date" in result.stdout:
print("browser_use is already installed. Skipping installation.")
else:
print("browser_use installed.")
except subprocess.CalledProcessError as e:
print(f"Failed to install Playwright browsers: {e.stderr}")
try:
result = subprocess.run(
[python_executable, "-m", "playwright", "install"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=True
)
if "already up-to-date" in result.stderr or "already up-to-date" in result.stdout:
print("Playwright browsers are already installed. Skipping installation.")
else:
print("Playwright browsers installed.")
except subprocess.CalledProcessError as e:
print(f"Failed to install Playwright browsers: {e.stderr}")
try:
install_portaudio()
except Exception as e:
print(f"Error: {e}")
'''
try:
dir = get_comfy_dir("web_custom_versions/Comfy-Org_ComfyUI_frontend")
if os.path.exists(dir):
latest_folder = get_latest_version_folder(dir)
party_path= os.path.join(latest_folder,"extensions", "party")
copy_js_files(party_path)
copy_js_files("web/extensions/party")
except Exception as e:
print(f"Error: {e}")
'''
try:
system_info = get_system_info()
install_llama(system_info)
except Exception as e:
print(f"Error: {e}")
try:
check_and_uninstall_websocket()
except Exception as e:
print(f"Error: {e}")
try:
init_temp()
except Exception as e:
print(f"Error: {e}")
try:
manage_discord_packages()
except Exception as e:
print(f"Error: {e}")
try:
install_playwright_browsers()
except Exception as e:
print(f"Error: {e}")
WEB_DIRECTORY = "./web/js"
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]