Browse Source

feat: tqdm for clone

fix: snapshot restore proper working directory
pull/175/head
Dr.Lt.Data 1 year ago
parent
commit
e497b8321f
  1. 19
      __init__.py
  2. 16
      git_helper.py
  3. 2
      prestartup_script.py

19
__init__.py

@ -6,7 +6,8 @@ import sys
import threading
import datetime
import re
from tqdm.auto import tqdm
from git.remote import RemoteProgress
def handle_stream(stream, prefix):
for line in stream:
@ -57,7 +58,7 @@ sys.path.append('../..')
from torchvision.datasets.utils import download_url
# ensure .js
print("### Loading: ComfyUI-Manager (V0.37)")
print("### Loading: ComfyUI-Manager (V0.38)")
comfy_ui_required_revision = 1240
comfy_ui_revision = "Unknown"
@ -952,6 +953,18 @@ def execute_install_script(url, repo_path):
return True
class GitProgress(RemoteProgress):
def __init__(self):
super().__init__()
self.pbar = tqdm()
def update(self, op_code, cur_count, max_count=None, message=''):
self.pbar.total = max_count
self.pbar.n = cur_count
self.pbar.pos = 0
self.pbar.refresh()
def gitclone_install(files):
print(f"install: {files}")
for url in files:
@ -966,7 +979,7 @@ def gitclone_install(files):
if platform.system() == 'Windows':
run_script([sys.executable, git_script_path, "--clone", custom_nodes_path, url])
else:
repo = git.Repo.clone_from(url, repo_path, recursive=True)
repo = git.Repo.clone_from(url, repo_path, recursive=True, progress=GitProgress())
repo.git.clear_cache()
repo.close()

16
git_helper.py

@ -5,18 +5,32 @@ import configparser
import re
import json
from torchvision.datasets.utils import download_url
from tqdm.auto import tqdm
from git.remote import RemoteProgress
config_path = os.path.join(os.path.dirname(__file__), "config.ini")
nodelist_path = os.path.join(os.path.dirname(__file__), "custom-node-list.json")
working_directory = os.getcwd()
class GitProgress(RemoteProgress):
def __init__(self):
super().__init__()
self.pbar = tqdm()
def update(self, op_code, cur_count, max_count=None, message=''):
self.pbar.total = max_count
self.pbar.n = cur_count
self.pbar.pos = 0
self.pbar.refresh()
def gitclone(custom_nodes_path, url, target_hash=None):
repo_name = os.path.splitext(os.path.basename(url))[0]
repo_path = os.path.join(custom_nodes_path, repo_name)
# Clone the repository from the remote URL
repo = git.Repo.clone_from(url, repo_path, recursive=True)
repo = git.Repo.clone_from(url, repo_path, recursive=True, progress=GitProgress())
if target_hash is not None:
print(f"CHECKOUT: {repo_name} [{target_hash}]")

2
prestartup_script.py

@ -163,6 +163,7 @@ if os.path.exists(restore_snapshot_path):
try:
repository_name = url.split("/")[-1].strip()
repo_path = os.path.join(custom_nodes_path, repository_name)
repo_path = os.path.abspath(repo_path)
requirements_path = os.path.join(repo_path, 'requirements.txt')
install_script_path = os.path.join(repo_path, 'install.py')
@ -179,6 +180,7 @@ if os.path.exists(restore_snapshot_path):
if os.path.exists(install_script_path):
install_cmd = [sys.executable, install_script_path]
print(f">>> {install_cmd} / {repo_path}")
this_exit_code += process_wrap(install_cmd, repo_path)
if this_exit_code != 0:

Loading…
Cancel
Save