mirror of
https://github.com/Comfy-Org/ComfyUI-Manager.git
synced 2025-12-17 02:12:58 +08:00
separate fetch and update check
This commit is contained in:
parent
40e7ddb4f1
commit
28f3fac5f7
46
__init__.py
46
__init__.py
@ -16,7 +16,7 @@ sys.path.append('../..')
|
||||
from torchvision.datasets.utils import download_url
|
||||
|
||||
# ensure .js
|
||||
print("### Loading: ComfyUI-Manager (V0.6.5)")
|
||||
print("### Loading: ComfyUI-Manager (V0.7)")
|
||||
|
||||
comfy_path = os.path.dirname(folder_paths.__file__)
|
||||
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)
|
||||
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]
|
||||
|
||||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
output, _ = process.communicate()
|
||||
output = output.decode('utf-8').strip()
|
||||
@ -70,18 +74,20 @@ def __win_check_git_pull(path):
|
||||
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
|
||||
if not os.path.exists(os.path.join(path, '.git')):
|
||||
raise ValueError('Not a git repository')
|
||||
|
||||
if platform.system() == "Windows":
|
||||
return __win_check_git_update(path)
|
||||
return __win_check_git_update(path, do_fetch)
|
||||
else:
|
||||
# Fetch the latest commits from the remote repository
|
||||
repo = git.Repo(path)
|
||||
remote_name = 'origin'
|
||||
remote = repo.remote(name=remote_name)
|
||||
|
||||
if do_fetch:
|
||||
remote.fetch()
|
||||
|
||||
# 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'])
|
||||
|
||||
|
||||
def check_a_custom_node_installed(item):
|
||||
def check_a_custom_node_installed(item, do_fetch=False):
|
||||
item['installed'] = 'None'
|
||||
|
||||
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)
|
||||
if os.path.exists(dir_path):
|
||||
try:
|
||||
if git_repo_has_updates(dir_path):
|
||||
if git_repo_has_updates(dir_path, do_fetch):
|
||||
item['installed'] = 'Update'
|
||||
else:
|
||||
item['installed'] = 'True'
|
||||
@ -226,9 +232,9 @@ def check_a_custom_node_installed(item):
|
||||
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']:
|
||||
check_a_custom_node_installed(item)
|
||||
check_a_custom_node_installed(item, do_fetch)
|
||||
|
||||
|
||||
@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')
|
||||
|
||||
|
||||
@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")
|
||||
async def fetch_customnode_list(request):
|
||||
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'
|
||||
|
||||
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')
|
||||
|
||||
|
||||
@ -11,11 +11,13 @@ def gitclone(custom_nodes_path, url):
|
||||
repo.git.clear_cache()
|
||||
repo.close()
|
||||
|
||||
def gitcheck(path):
|
||||
def gitcheck(path, do_fetch=False):
|
||||
# Fetch the latest commits from the remote repository
|
||||
repo = git.Repo(path)
|
||||
remote_name = 'origin'
|
||||
remote = repo.remote(name=remote_name)
|
||||
|
||||
if do_fetch:
|
||||
remote.fetch()
|
||||
|
||||
# Get the current commit hash and the commit hash of the remote branch
|
||||
@ -50,7 +52,9 @@ try:
|
||||
if sys.argv[1] == "--clone":
|
||||
gitclone(sys.argv[2], sys.argv[3])
|
||||
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":
|
||||
gitpull(sys.argv[2])
|
||||
exit(0)
|
||||
|
||||
@ -3,6 +3,7 @@ import { ComfyDialog, $el } from "/scripts/ui.js";
|
||||
import {ComfyWidgets} from "../../scripts/widgets.js";
|
||||
|
||||
var update_comfyui_button = null;
|
||||
var fetch_updates_button = null;
|
||||
|
||||
async function getCustomnodeMappings() {
|
||||
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) {
|
||||
if(ModelInstaller.instance) {
|
||||
ModelInstaller.instance.startInstall(target);
|
||||
@ -888,7 +928,7 @@ class ManagerMenuDialog extends ComfyDialog {
|
||||
|
||||
createButtons() {
|
||||
this.local_mode_checkbox = $el("input",{type:'checkbox', id:"use_local_db"},[])
|
||||
const checkbox_text = $el("label",{},["Use local DB"])
|
||||
const checkbox_text = $el("label",{},[" Use local DB"])
|
||||
checkbox_text.style.color = "var(--fg-color)"
|
||||
|
||||
update_comfyui_button =
|
||||
@ -899,6 +939,14 @@ class ManagerMenuDialog extends ComfyDialog {
|
||||
() => updateComfyUI()
|
||||
});
|
||||
|
||||
fetch_updates_button =
|
||||
$el("button", {
|
||||
type: "button",
|
||||
textContent: "Fetch Updates",
|
||||
onclick:
|
||||
() => fetchUpdates()
|
||||
});
|
||||
|
||||
const res =
|
||||
[
|
||||
$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,
|
||||
fetch_updates_button,
|
||||
|
||||
$el("br", {}, []),
|
||||
$el("button", {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user