Browse Source

separate fetch and update check

pull/14/head
ltdrdata 1 year ago
parent
commit
28f3fac5f7
  1. 46
      __init__.py
  2. 8
      git_helper.py
  3. 50
      js/comfyui-manager.js

46
__init__.py

@ -16,7 +16,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.6.5)") print("### Loading: ComfyUI-Manager (V0.7)")
comfy_path = os.path.dirname(folder_paths.__file__) comfy_path = os.path.dirname(folder_paths.__file__)
custom_nodes_path = os.path.join(comfy_path, 'custom_nodes') custom_nodes_path = os.path.join(comfy_path, 'custom_nodes')
@ -50,8 +50,12 @@ print_comfyui_version()
# use subprocess to avoid file system lock by git (Windows) # use subprocess to avoid file system lock by git (Windows)
def __win_check_git_update(path): def __win_check_git_update(path, do_fetch=False):
if do_fetch:
command = [sys.executable, git_script_path, "--fetch", path]
else:
command = [sys.executable, git_script_path, "--check", path] command = [sys.executable, git_script_path, "--check", path]
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, _ = process.communicate() output, _ = process.communicate()
output = output.decode('utf-8').strip() output = output.decode('utf-8').strip()
@ -70,18 +74,20 @@ def __win_check_git_pull(path):
process.wait() process.wait()
def git_repo_has_updates(path): def git_repo_has_updates(path, do_fetch=False):
# Check if the path is a git repository # Check if the path is a git repository
if not os.path.exists(os.path.join(path, '.git')): if not os.path.exists(os.path.join(path, '.git')):
raise ValueError('Not a git repository') raise ValueError('Not a git repository')
if platform.system() == "Windows": if platform.system() == "Windows":
return __win_check_git_update(path) return __win_check_git_update(path, do_fetch)
else: else:
# Fetch the latest commits from the remote repository # Fetch the latest commits from the remote repository
repo = git.Repo(path) repo = git.Repo(path)
remote_name = 'origin' remote_name = 'origin'
remote = repo.remote(name=remote_name) remote = repo.remote(name=remote_name)
if do_fetch:
remote.fetch() remote.fetch()
# Get the current commit hash and the commit hash of the remote branch # Get the current commit hash and the commit hash of the remote branch
@ -193,7 +199,7 @@ def get_model_path(data):
return os.path.join(base_model, data['filename']) return os.path.join(base_model, data['filename'])
def check_a_custom_node_installed(item): def check_a_custom_node_installed(item, do_fetch=False):
item['installed'] = 'None' item['installed'] = 'None'
if item['install_type'] == 'git-clone' and len(item['files']) == 1: if item['install_type'] == 'git-clone' and len(item['files']) == 1:
@ -201,7 +207,7 @@ def check_a_custom_node_installed(item):
dir_path = os.path.join(custom_nodes_path, dir_name) dir_path = os.path.join(custom_nodes_path, dir_name)
if os.path.exists(dir_path): if os.path.exists(dir_path):
try: try:
if git_repo_has_updates(dir_path): if git_repo_has_updates(dir_path, do_fetch):
item['installed'] = 'Update' item['installed'] = 'Update'
else: else:
item['installed'] = 'True' item['installed'] = 'True'
@ -226,9 +232,9 @@ def check_a_custom_node_installed(item):
item['installed'] = 'False' item['installed'] = 'False'
def check_custom_nodes_installed(json_obj): def check_custom_nodes_installed(json_obj, do_fetch=False):
for item in json_obj['custom_nodes']: for item in json_obj['custom_nodes']:
check_a_custom_node_installed(item) check_a_custom_node_installed(item, do_fetch)
@server.PromptServer.instance.routes.get("/customnode/getmappings") @server.PromptServer.instance.routes.get("/customnode/getmappings")
@ -243,6 +249,28 @@ async def fetch_customnode_mappings(request):
return web.json_response(json_obj, content_type='application/json') return web.json_response(json_obj, content_type='application/json')
@server.PromptServer.instance.routes.get("/customnode/fetch_updates")
async def fetch_updates(request):
try:
if request.rel_url.query["mode"] == "local":
uri = local_db_custom_node_list
else:
uri = 'https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json'
json_obj = await get_data(uri)
check_custom_nodes_installed(json_obj, True)
update_exists = any('custom_nodes' in json_obj and 'installed' in node and node['installed'] == 'Update' for node in
json_obj['custom_nodes'])
if update_exists:
return web.Response(status=201)
return web.Response(status=200)
except:
return web.Response(status=400)
@server.PromptServer.instance.routes.get("/customnode/getlist") @server.PromptServer.instance.routes.get("/customnode/getlist")
async def fetch_customnode_list(request): async def fetch_customnode_list(request):
if request.rel_url.query["mode"] == "local": if request.rel_url.query["mode"] == "local":
@ -251,7 +279,7 @@ async def fetch_customnode_list(request):
uri = 'https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json' uri = 'https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json'
json_obj = await get_data(uri) json_obj = await get_data(uri)
check_custom_nodes_installed(json_obj) check_custom_nodes_installed(json_obj, False)
return web.json_response(json_obj, content_type='application/json') return web.json_response(json_obj, content_type='application/json')

8
git_helper.py

@ -11,11 +11,13 @@ def gitclone(custom_nodes_path, url):
repo.git.clear_cache() repo.git.clear_cache()
repo.close() repo.close()
def gitcheck(path): def gitcheck(path, do_fetch=False):
# Fetch the latest commits from the remote repository # Fetch the latest commits from the remote repository
repo = git.Repo(path) repo = git.Repo(path)
remote_name = 'origin' remote_name = 'origin'
remote = repo.remote(name=remote_name) remote = repo.remote(name=remote_name)
if do_fetch:
remote.fetch() remote.fetch()
# Get the current commit hash and the commit hash of the remote branch # Get the current commit hash and the commit hash of the remote branch
@ -50,7 +52,9 @@ try:
if sys.argv[1] == "--clone": if sys.argv[1] == "--clone":
gitclone(sys.argv[2], sys.argv[3]) gitclone(sys.argv[2], sys.argv[3])
elif sys.argv[1] == "--check": elif sys.argv[1] == "--check":
gitcheck(sys.argv[2]) gitcheck(sys.argv[2], False)
elif sys.argv[1] == "--fetch":
gitcheck(sys.argv[2], True)
elif sys.argv[1] == "--pull": elif sys.argv[1] == "--pull":
gitpull(sys.argv[2]) gitpull(sys.argv[2])
exit(0) exit(0)

50
js/comfyui-manager.js vendored

@ -3,6 +3,7 @@ import { ComfyDialog, $el } from "/scripts/ui.js";
import {ComfyWidgets} from "../../scripts/widgets.js"; import {ComfyWidgets} from "../../scripts/widgets.js";
var update_comfyui_button = null; var update_comfyui_button = null;
var fetch_updates_button = null;
async function getCustomnodeMappings() { async function getCustomnodeMappings() {
var mode = "url"; var mode = "url";
@ -117,6 +118,45 @@ async function updateComfyUI() {
} }
} }
async function fetchUpdates() {
fetch_updates_button.innerText = "Fetching updates...";
fetch_updates_button.disabled = true;
try {
var mode = "url";
if(ManagerMenuDialog.instance.local_mode_checkbox.checked)
mode = "local";
const response = await fetch(`/customnode/fetch_updates?mode=${mode}`);
if(response.status == 400) {
app.ui.dialog.show('Failed to fetch updates.');
app.ui.dialog.element.style.zIndex = 9999;
return false;
}
if(response.status == 201) {
app.ui.dialog.show('There is an updated extension available.');
app.ui.dialog.element.style.zIndex = 9999;
}
else {
app.ui.dialog.show('All extensions are already up-to-date with the latest versions.');
app.ui.dialog.element.style.zIndex = 9999;
}
return true;
}
catch(exception) {
app.ui.dialog.show(`Failed to update ComfyUI / ${exception}`);
app.ui.dialog.element.style.zIndex = 9999;
return false;
}
finally {
fetch_updates_button.disabled = false;
fetch_updates_button.innerText = "Fetch Updates";
}
}
async function install_model(target) { async function install_model(target) {
if(ModelInstaller.instance) { if(ModelInstaller.instance) {
ModelInstaller.instance.startInstall(target); ModelInstaller.instance.startInstall(target);
@ -899,6 +939,14 @@ class ManagerMenuDialog extends ComfyDialog {
() => updateComfyUI() () => updateComfyUI()
}); });
fetch_updates_button =
$el("button", {
type: "button",
textContent: "Fetch Updates",
onclick:
() => fetchUpdates()
});
const res = const res =
[ [
$el("tr.td", {width:"100%"}, [$el("font", {size:6, color:"white"}, [`Manager Menu`])]), $el("tr.td", {width:"100%"}, [$el("font", {size:6, color:"white"}, [`Manager Menu`])]),
@ -938,7 +986,9 @@ class ManagerMenuDialog extends ComfyDialog {
} }
}), }),
$el("br", {}, []),
update_comfyui_button, update_comfyui_button,
fetch_updates_button,
$el("br", {}, []), $el("br", {}, []),
$el("button", { $el("button", {

Loading…
Cancel
Save