mirror of
https://github.com/Comfy-Org/ComfyUI-Manager.git
synced 2025-12-16 01:57:04 +08:00
feat: support .yaml snapshot
This commit is contained in:
parent
761459007f
commit
09422da704
15
cm-cli.py
15
cm-cli.py
@ -108,7 +108,9 @@ def restore_dependencies():
|
||||
def restore_snapshot(snapshot_name):
|
||||
global processed_install
|
||||
|
||||
if not os.path.exists(snapshot_name):
|
||||
if os.path.exists(snapshot_name):
|
||||
snapshot_path = os.path.abspath(snapshot_name)
|
||||
else:
|
||||
snapshot_path = os.path.join(core.comfyui_manager_path, 'snapshots', snapshot_name)
|
||||
if not os.path.exists(snapshot_path):
|
||||
print(f"ERROR: `{snapshot_path}` is not exists.")
|
||||
@ -486,6 +488,15 @@ def cancel():
|
||||
os.remove(restore_snapshot_path)
|
||||
|
||||
|
||||
def save_snapshot():
|
||||
output_path = None
|
||||
for i in range(len(sys.argv)):
|
||||
if sys.argv[i] == '--output':
|
||||
if len(sys.argv) >= i:
|
||||
output_path = sys.argv[i+1]
|
||||
|
||||
return core.save_snapshot_with_postfix('snapshot', output_path)
|
||||
|
||||
def for_each_nodes(act, allow_all=True):
|
||||
global nodes
|
||||
|
||||
@ -566,7 +577,7 @@ elif op == 'cli-only-mode':
|
||||
print(f"\ninvalid value for cli-only-mode: {sys.argv[2]}\n")
|
||||
|
||||
elif op == 'save-snapshot':
|
||||
path = core.save_snapshot_with_postfix('snapshot')
|
||||
path = save_snapshot()
|
||||
print(f"Current snapshot is saved as `{path}`")
|
||||
|
||||
elif op == 'restore-snapshot':
|
||||
|
||||
@ -4,6 +4,7 @@ import git
|
||||
import configparser
|
||||
import re
|
||||
import json
|
||||
import yaml
|
||||
from torchvision.datasets.utils import download_url
|
||||
from tqdm.auto import tqdm
|
||||
from git.remote import RemoteProgress
|
||||
@ -278,8 +279,21 @@ def apply_snapshot(target):
|
||||
try:
|
||||
path = os.path.join(os.path.dirname(__file__), 'snapshots', f"{target}")
|
||||
if os.path.exists(path):
|
||||
with open(path, 'r', encoding="UTF-8") as json_file:
|
||||
info = json.load(json_file)
|
||||
if not target.endswith('.json') and not target.endswith('.yaml'):
|
||||
print(f"Snapshot file not found: `{path}`")
|
||||
print("APPLY SNAPSHOT: False")
|
||||
return
|
||||
|
||||
with open(path, 'r', encoding="UTF-8") as snapshot_file:
|
||||
if target.endswith('.json'):
|
||||
info = json.load(snapshot_file)
|
||||
elif target.endswith('.yaml'):
|
||||
info = yaml.load(snapshot_file, Loader=yaml.SafeLoader)
|
||||
info = info['custom_nodes']
|
||||
else:
|
||||
# impossible case
|
||||
print("APPLY SNAPSHOT: False")
|
||||
return
|
||||
|
||||
comfyui_hash = info['comfyui']
|
||||
git_custom_node_infos = info['git_custom_nodes']
|
||||
|
||||
@ -14,6 +14,7 @@ import aiohttp
|
||||
import threading
|
||||
import json
|
||||
import time
|
||||
import yaml
|
||||
|
||||
glob_path = os.path.join(os.path.dirname(__file__)) # ComfyUI-Manager/glob
|
||||
sys.path.append(glob_path)
|
||||
@ -21,7 +22,7 @@ sys.path.append(glob_path)
|
||||
import cm_global
|
||||
from manager_util import *
|
||||
|
||||
version = [2, 23, 1]
|
||||
version = [2, 24]
|
||||
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__), '..'))
|
||||
@ -982,15 +983,29 @@ def get_current_snapshot():
|
||||
}
|
||||
|
||||
|
||||
def save_snapshot_with_postfix(postfix):
|
||||
def save_snapshot_with_postfix(postfix, path=None):
|
||||
if path is None:
|
||||
now = datetime.now()
|
||||
|
||||
date_time_format = now.strftime("%Y-%m-%d_%H-%M-%S")
|
||||
file_name = f"{date_time_format}_{postfix}"
|
||||
|
||||
path = os.path.join(comfyui_manager_path, 'snapshots', f"{file_name}.json")
|
||||
else:
|
||||
file_name = path.replace('\\', '/').split('/')[-1]
|
||||
file_name = file_name.split('.')[-2]
|
||||
|
||||
snapshot = get_current_snapshot()
|
||||
if path.endswith('.json'):
|
||||
with open(path, "w") as json_file:
|
||||
json.dump(get_current_snapshot(), json_file, indent=4)
|
||||
json.dump(snapshot, json_file, indent=4)
|
||||
|
||||
return file_name+'.json'
|
||||
return file_name + '.json'
|
||||
|
||||
elif path.endswith('.yaml'):
|
||||
with open(path, "w") as yaml_file:
|
||||
snapshot = {'custom_nodes': snapshot}
|
||||
yaml.dump(snapshot, yaml_file, allow_unicode=True)
|
||||
|
||||
return path
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user