feat: tqdm for clone

fix: snapshot restore proper working directory
This commit is contained in:
Dr.Lt.Data 2023-11-04 21:23:29 +09:00
parent 7fbe34f8db
commit e497b8321f
3 changed files with 33 additions and 4 deletions

View File

@ -6,7 +6,8 @@ import sys
import threading import threading
import datetime import datetime
import re import re
from tqdm.auto import tqdm
from git.remote import RemoteProgress
def handle_stream(stream, prefix): def handle_stream(stream, prefix):
for line in stream: for line in stream:
@ -57,7 +58,7 @@ sys.path.append('../..')
from torchvision.datasets.utils import download_url from torchvision.datasets.utils import download_url
# ensure .js # ensure .js
print("### Loading: ComfyUI-Manager (V0.37)") print("### Loading: ComfyUI-Manager (V0.38)")
comfy_ui_required_revision = 1240 comfy_ui_required_revision = 1240
comfy_ui_revision = "Unknown" comfy_ui_revision = "Unknown"
@ -952,6 +953,18 @@ def execute_install_script(url, repo_path):
return True 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): def gitclone_install(files):
print(f"install: {files}") print(f"install: {files}")
for url in files: for url in files:
@ -966,7 +979,7 @@ def gitclone_install(files):
if platform.system() == 'Windows': if platform.system() == 'Windows':
run_script([sys.executable, git_script_path, "--clone", custom_nodes_path, url]) run_script([sys.executable, git_script_path, "--clone", custom_nodes_path, url])
else: 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.git.clear_cache()
repo.close() repo.close()

View File

@ -5,18 +5,32 @@ import configparser
import re import re
import json import json
from torchvision.datasets.utils import download_url 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") config_path = os.path.join(os.path.dirname(__file__), "config.ini")
nodelist_path = os.path.join(os.path.dirname(__file__), "custom-node-list.json") nodelist_path = os.path.join(os.path.dirname(__file__), "custom-node-list.json")
working_directory = os.getcwd() 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): def gitclone(custom_nodes_path, url, target_hash=None):
repo_name = os.path.splitext(os.path.basename(url))[0] repo_name = os.path.splitext(os.path.basename(url))[0]
repo_path = os.path.join(custom_nodes_path, repo_name) repo_path = os.path.join(custom_nodes_path, repo_name)
# Clone the repository from the remote URL # 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: if target_hash is not None:
print(f"CHECKOUT: {repo_name} [{target_hash}]") print(f"CHECKOUT: {repo_name} [{target_hash}]")

View File

@ -163,6 +163,7 @@ if os.path.exists(restore_snapshot_path):
try: try:
repository_name = url.split("/")[-1].strip() repository_name = url.split("/")[-1].strip()
repo_path = os.path.join(custom_nodes_path, repository_name) 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') requirements_path = os.path.join(repo_path, 'requirements.txt')
install_script_path = os.path.join(repo_path, 'install.py') 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): if os.path.exists(install_script_path):
install_cmd = [sys.executable, 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) this_exit_code += process_wrap(install_cmd, repo_path)
if this_exit_code != 0: if this_exit_code != 0: