mirror of
https://github.com/Comfy-Org/ComfyUI-Manager.git
synced 2025-12-17 02:12:58 +08:00
enhance: cm-cli supports updating comfyui
This commit is contained in:
parent
4e1697d2aa
commit
a3d858dc1a
25
cm-cli.py
25
cm-cli.py
@ -325,6 +325,16 @@ def update_node(node_name, is_all=False, cnt_msg=''):
|
|||||||
print(f"ERROR: An error occurred while uninstalling '{node_name}'.")
|
print(f"ERROR: An error occurred while uninstalling '{node_name}'.")
|
||||||
|
|
||||||
|
|
||||||
|
def update_comfyui():
|
||||||
|
res = core.update_path(comfy_path, instant_execution=True)
|
||||||
|
if res == 'fail':
|
||||||
|
print("Updating ComfyUI has failed.")
|
||||||
|
elif res == 'updated':
|
||||||
|
print("ComfyUI is updated.")
|
||||||
|
else:
|
||||||
|
print("ComfyUI is already up to date.")
|
||||||
|
|
||||||
|
|
||||||
def enable_node(node_name, is_all=False, cnt_msg=''):
|
def enable_node(node_name, is_all=False, cnt_msg=''):
|
||||||
if node_name == 'ComfyUI-Manager':
|
if node_name == 'ComfyUI-Manager':
|
||||||
return
|
return
|
||||||
@ -401,9 +411,9 @@ def show_snapshot(simple_mode=False):
|
|||||||
|
|
||||||
|
|
||||||
def show_snapshot_list(simple_mode=False):
|
def show_snapshot_list(simple_mode=False):
|
||||||
path = os.path.join(comfyui_manager_path, 'snapshots')
|
snapshot_path = os.path.join(comfyui_manager_path, 'snapshots')
|
||||||
|
|
||||||
files = os.listdir(path)
|
files = os.listdir(snapshot_path)
|
||||||
json_files = [x for x in files if x.endswith('.json')]
|
json_files = [x for x in files if x.endswith('.json')]
|
||||||
for x in sorted(json_files):
|
for x in sorted(json_files):
|
||||||
print(x)
|
print(x)
|
||||||
@ -423,7 +433,9 @@ def for_each_nodes(act, allow_all=True):
|
|||||||
is_all = False
|
is_all = False
|
||||||
if allow_all and 'all' in nodes:
|
if allow_all and 'all' in nodes:
|
||||||
is_all = True
|
is_all = True
|
||||||
nodes = [x for x in custom_node_map.keys() if os.path.exists(os.path.join(custom_nodes_path, x)) or os.path.exists(os.path.join(custom_nodes_path, x)+'.disabled')]
|
nodes = [x for x in custom_node_map.keys() if os.path.exists(os.path.join(custom_nodes_path, x)) or os.path.exists(os.path.join(custom_nodes_path, x) + '.disabled')]
|
||||||
|
|
||||||
|
nodes = [x for x in nodes if x.lower() not in ['comfy', 'comfyui', 'all']]
|
||||||
|
|
||||||
total = len(nodes)
|
total = len(nodes)
|
||||||
i = 1
|
i = 1
|
||||||
@ -433,7 +445,7 @@ def for_each_nodes(act, allow_all=True):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"ERROR: {e}")
|
print(f"ERROR: {e}")
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
i+=1
|
i += 1
|
||||||
|
|
||||||
|
|
||||||
op = sys.argv[1]
|
op = sys.argv[1]
|
||||||
@ -449,6 +461,11 @@ elif op == 'uninstall':
|
|||||||
for_each_nodes(uninstall_node)
|
for_each_nodes(uninstall_node)
|
||||||
|
|
||||||
elif op == 'update':
|
elif op == 'update':
|
||||||
|
for x in nodes:
|
||||||
|
if x.lower() in ['comfyui', 'comfy', 'all']:
|
||||||
|
update_comfyui()
|
||||||
|
break
|
||||||
|
|
||||||
for_each_nodes(update_node, allow_all=True)
|
for_each_nodes(update_node, allow_all=True)
|
||||||
|
|
||||||
elif op == 'disable':
|
elif op == 'disable':
|
||||||
|
|||||||
@ -21,7 +21,7 @@ sys.path.append(glob_path)
|
|||||||
import cm_global
|
import cm_global
|
||||||
from manager_util import *
|
from manager_util import *
|
||||||
|
|
||||||
version = [2, 22, 2]
|
version = [2, 22, 3]
|
||||||
version_str = f"V{version[0]}.{version[1]}" + (f'.{version[2]}' if len(version) > 2 else '')
|
version_str = f"V{version[0]}.{version[1]}" + (f'.{version[2]}' if len(version) > 2 else '')
|
||||||
|
|
||||||
comfyui_manager_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
comfyui_manager_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
||||||
@ -809,6 +809,51 @@ def gitclone_update(files, instant_execution=False, skip_script=False, msg_prefi
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def update_path(repo_path, instant_execution=False):
|
||||||
|
if not os.path.exists(os.path.join(repo_path, '.git')):
|
||||||
|
return "fail"
|
||||||
|
|
||||||
|
# version check
|
||||||
|
repo = git.Repo(repo_path)
|
||||||
|
|
||||||
|
if repo.head.is_detached:
|
||||||
|
switch_to_default_branch(repo)
|
||||||
|
|
||||||
|
current_branch = repo.active_branch
|
||||||
|
branch_name = current_branch.name
|
||||||
|
|
||||||
|
if current_branch.tracking_branch() is None:
|
||||||
|
print(f"[ComfyUI-Manager] There is no tracking branch ({current_branch})")
|
||||||
|
remote_name = 'origin'
|
||||||
|
else:
|
||||||
|
remote_name = current_branch.tracking_branch().remote_name
|
||||||
|
remote = repo.remote(name=remote_name)
|
||||||
|
|
||||||
|
try:
|
||||||
|
remote.fetch()
|
||||||
|
except Exception as e:
|
||||||
|
if 'detected dubious' in str(e):
|
||||||
|
print(f"[ComfyUI-Manager] Try fixing 'dubious repository' error on 'ComfyUI' repository")
|
||||||
|
safedir_path = comfy_path.replace('\\', '/')
|
||||||
|
subprocess.run(['git', 'config', '--global', '--add', 'safe.directory', safedir_path])
|
||||||
|
try:
|
||||||
|
remote.fetch()
|
||||||
|
except Exception:
|
||||||
|
print(f"\n[ComfyUI-Manager] Failed to fixing repository setup. Please execute this command on cmd: \n"
|
||||||
|
f"-----------------------------------------------------------------------------------------\n"
|
||||||
|
f'git config --global --add safe.directory "{safedir_path}"\n'
|
||||||
|
f"-----------------------------------------------------------------------------------------\n")
|
||||||
|
|
||||||
|
commit_hash = repo.head.commit.hexsha
|
||||||
|
remote_commit_hash = repo.refs[f'{remote_name}/{branch_name}'].object.hexsha
|
||||||
|
|
||||||
|
if commit_hash != remote_commit_hash:
|
||||||
|
git_pull(repo_path)
|
||||||
|
execute_install_script("ComfyUI", repo_path, instant_execution=instant_execution)
|
||||||
|
return "updated"
|
||||||
|
else:
|
||||||
|
return "skipped"
|
||||||
|
|
||||||
def lookup_customnode_by_url(data, target):
|
def lookup_customnode_by_url(data, target):
|
||||||
for x in data['custom_nodes']:
|
for x in data['custom_nodes']:
|
||||||
if target in x['files']:
|
if target in x['files']:
|
||||||
|
|||||||
@ -862,50 +862,13 @@ async def update_comfyui(request):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
repo_path = os.path.dirname(folder_paths.__file__)
|
repo_path = os.path.dirname(folder_paths.__file__)
|
||||||
|
res = core.update_path(repo_path)
|
||||||
if not os.path.exists(os.path.join(repo_path, '.git')):
|
if res == "fail":
|
||||||
print(f"ComfyUI update fail: The installed ComfyUI does not have a Git repository.")
|
print(f"ComfyUI update fail: The installed ComfyUI does not have a Git repository.")
|
||||||
return web.Response(status=400)
|
return web.Response(status=400)
|
||||||
|
elif res == "updated":
|
||||||
# version check
|
|
||||||
repo = git.Repo(repo_path)
|
|
||||||
|
|
||||||
if repo.head.is_detached:
|
|
||||||
core.switch_to_default_branch(repo)
|
|
||||||
|
|
||||||
current_branch = repo.active_branch
|
|
||||||
branch_name = current_branch.name
|
|
||||||
|
|
||||||
if current_branch.tracking_branch() is None:
|
|
||||||
print(f"[ComfyUI-Manager] There is no tracking branch ({current_branch})")
|
|
||||||
remote_name = 'origin'
|
|
||||||
else:
|
|
||||||
remote_name = current_branch.tracking_branch().remote_name
|
|
||||||
remote = repo.remote(name=remote_name)
|
|
||||||
|
|
||||||
try:
|
|
||||||
remote.fetch()
|
|
||||||
except Exception as e:
|
|
||||||
if 'detected dubious' in str(e):
|
|
||||||
print(f"[ComfyUI-Manager] Try fixing 'dubious repository' error on 'ComfyUI' repository")
|
|
||||||
safedir_path = core.comfy_path.replace('\\', '/')
|
|
||||||
subprocess.run(['git', 'config', '--global', '--add', 'safe.directory', safedir_path])
|
|
||||||
try:
|
|
||||||
remote.fetch()
|
|
||||||
except Exception:
|
|
||||||
print(f"\n[ComfyUI-Manager] Failed to fixing repository setup. Please execute this command on cmd: \n"
|
|
||||||
f"-----------------------------------------------------------------------------------------\n"
|
|
||||||
f'git config --global --add safe.directory "{safedir_path}"\n'
|
|
||||||
f"-----------------------------------------------------------------------------------------\n")
|
|
||||||
|
|
||||||
commit_hash = repo.head.commit.hexsha
|
|
||||||
remote_commit_hash = repo.refs[f'{remote_name}/{branch_name}'].object.hexsha
|
|
||||||
|
|
||||||
if commit_hash != remote_commit_hash:
|
|
||||||
core.git_pull(repo_path)
|
|
||||||
core.execute_install_script("ComfyUI", repo_path)
|
|
||||||
return web.Response(status=201)
|
return web.Response(status=201)
|
||||||
else:
|
else: # skipped
|
||||||
return web.Response(status=200)
|
return web.Response(status=200)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"ComfyUI update fail: {e}", file=sys.stderr)
|
print(f"ComfyUI update fail: {e}", file=sys.stderr)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user