mirror of
https://github.com/Comfy-Org/ComfyUI-Manager.git
synced 2025-12-30 16:50:50 +08:00
handle installed
This commit is contained in:
parent
9d1ef85af8
commit
4e44c26beb
@ -206,7 +206,7 @@ def checkout_custom_node_hash(git_custom_node_infos):
|
|||||||
repo_name_to_url[repo_name] = url
|
repo_name_to_url[repo_name] = url
|
||||||
|
|
||||||
for path in os.listdir(working_directory):
|
for path in os.listdir(working_directory):
|
||||||
if '@' in path or path.endswith("ComfyUI-Manager"):
|
if path.endswith("ComfyUI-Manager"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
fullpath = os.path.join(working_directory, path)
|
fullpath = os.path.join(working_directory, path)
|
||||||
@ -447,6 +447,25 @@ def is_git_repo(path: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def get_commit_hash(fullpath):
|
||||||
|
git_head = os.path.join(fullpath, '.git', 'HEAD')
|
||||||
|
if os.path.exists(git_head):
|
||||||
|
with open(git_head) as f:
|
||||||
|
line = f.readline()
|
||||||
|
|
||||||
|
if line.startswith("ref: "):
|
||||||
|
ref = os.path.join(fullpath, '.git', line[5:].strip())
|
||||||
|
if os.path.exists(ref):
|
||||||
|
with open(ref) as f2:
|
||||||
|
return f2.readline().strip()
|
||||||
|
else:
|
||||||
|
return "unknown"
|
||||||
|
else:
|
||||||
|
return line
|
||||||
|
|
||||||
|
return "unknown"
|
||||||
|
|
||||||
|
|
||||||
setup_environment()
|
setup_environment()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -105,13 +105,13 @@ def check_invalid_nodes():
|
|||||||
if subdir in ['.disabled', '__pycache__']:
|
if subdir in ['.disabled', '__pycache__']:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if '@' in subdir:
|
|
||||||
spec = subdir.split('@')
|
|
||||||
if spec[1] in ['unknown', 'nightly']:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not os.path.exists(os.path.join(root, subdir, '.tracking')):
|
package = unified_manager.installed_node_packages.get(subdir)
|
||||||
invalid_nodes[spec[0]] = os.path.join(root, subdir)
|
if not package:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not package.isValid():
|
||||||
|
invalid_nodes[subdir] = package.fullpath
|
||||||
|
|
||||||
node_paths = folder_paths.get_folder_paths("custom_nodes")
|
node_paths = folder_paths.get_folder_paths("custom_nodes")
|
||||||
for x in node_paths:
|
for x in node_paths:
|
||||||
@ -309,25 +309,6 @@ class ManagedResult:
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
def get_commit_hash(fullpath):
|
|
||||||
git_head = os.path.join(fullpath, '.git', 'HEAD')
|
|
||||||
if os.path.exists(git_head):
|
|
||||||
with open(git_head) as f:
|
|
||||||
line = f.readline()
|
|
||||||
|
|
||||||
if line.startswith("ref: "):
|
|
||||||
ref = os.path.join(fullpath, '.git', line[5:].strip())
|
|
||||||
if os.path.exists(ref):
|
|
||||||
with open(ref) as f2:
|
|
||||||
return f2.readline().strip()
|
|
||||||
else:
|
|
||||||
return "unknown"
|
|
||||||
else:
|
|
||||||
return line
|
|
||||||
|
|
||||||
return "unknown"
|
|
||||||
|
|
||||||
|
|
||||||
class UnifiedManager:
|
class UnifiedManager:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.installed_node_packages: dict[str, InstalledNodePackage] = {}
|
self.installed_node_packages: dict[str, InstalledNodePackage] = {}
|
||||||
@ -470,7 +451,7 @@ class UnifiedManager:
|
|||||||
self.installed_node_packages[node_package.id] = node_package
|
self.installed_node_packages[node_package.id] = node_package
|
||||||
|
|
||||||
if node_package.is_disabled and node_package.is_unknown:
|
if node_package.is_disabled and node_package.is_unknown:
|
||||||
# TODO: figure out where url is used.
|
# NOTE: unknown package does not have a url.
|
||||||
self.unknown_inactive_nodes[node_package.id] = ('', node_package.fullpath)
|
self.unknown_inactive_nodes[node_package.id] = ('', node_package.fullpath)
|
||||||
|
|
||||||
if node_package.is_disabled and node_package.is_nightly:
|
if node_package.is_disabled and node_package.is_nightly:
|
||||||
@ -480,7 +461,7 @@ class UnifiedManager:
|
|||||||
self.active_nodes[node_package.id] = node_package.version, node_package.fullpath
|
self.active_nodes[node_package.id] = node_package.version, node_package.fullpath
|
||||||
|
|
||||||
if node_package.is_enabled and node_package.is_unknown:
|
if node_package.is_enabled and node_package.is_unknown:
|
||||||
# TODO: figure out where url is used.
|
# NOTE: unknown package does not have a url.
|
||||||
self.unknown_active_nodes[node_package.id] = ('', node_package.fullpath)
|
self.unknown_active_nodes[node_package.id] = ('', node_package.fullpath)
|
||||||
|
|
||||||
if node_package.is_from_cnr and node_package.is_disabled:
|
if node_package.is_from_cnr and node_package.is_disabled:
|
||||||
|
|||||||
@ -544,37 +544,12 @@ def populate_markdown(x):
|
|||||||
|
|
||||||
@routes.get("/customnode/installed")
|
@routes.get("/customnode/installed")
|
||||||
async def installed_list(request):
|
async def installed_list(request):
|
||||||
result = {}
|
unified_manager = core.unified_manager
|
||||||
for x in folder_paths.get_folder_paths('custom_nodes'):
|
|
||||||
for module_name in os.listdir(x):
|
|
||||||
if (
|
|
||||||
module_name.endswith('.disabled') or
|
|
||||||
module_name == '__pycache__' or
|
|
||||||
module_name.endswith('.py') or
|
|
||||||
module_name.endswith('.example') or
|
|
||||||
module_name.endswith('.pyc')
|
|
||||||
):
|
|
||||||
continue
|
|
||||||
|
|
||||||
spec = module_name.split('@')
|
return web.json_response({
|
||||||
|
node_id: package.version if package.is_from_cnr else package.get_commit_hash()
|
||||||
if len(spec) == 2:
|
for node_id, package in unified_manager.installed_node_packages.items()
|
||||||
node_package_name = spec[0]
|
}, content_type='application/json')
|
||||||
ver = spec[1].replace('_', '.')
|
|
||||||
|
|
||||||
if ver == 'nightly':
|
|
||||||
ver = None
|
|
||||||
else:
|
|
||||||
node_package_name = module_name
|
|
||||||
ver = None
|
|
||||||
|
|
||||||
# extract commit hash
|
|
||||||
if ver is None:
|
|
||||||
ver = core.get_commit_hash(os.path.join(x, node_package_name))
|
|
||||||
|
|
||||||
result[node_package_name] = ver
|
|
||||||
|
|
||||||
return web.json_response(result, content_type='application/json')
|
|
||||||
|
|
||||||
|
|
||||||
@routes.get("/customnode/getlist")
|
@routes.get("/customnode/getlist")
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import os
|
|||||||
|
|
||||||
import toml
|
import toml
|
||||||
|
|
||||||
from git_helper import is_git_repo
|
from git_helper import is_git_repo, get_commit_hash
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -37,6 +37,15 @@ class InstalledNodePackage:
|
|||||||
def is_disabled(self) -> bool:
|
def is_disabled(self) -> bool:
|
||||||
return self.disabled
|
return self.disabled
|
||||||
|
|
||||||
|
def get_commit_hash(self) -> str:
|
||||||
|
return get_commit_hash(self.fullpath)
|
||||||
|
|
||||||
|
def isValid(self) -> bool:
|
||||||
|
if self.is_from_cnr:
|
||||||
|
return os.path.exists(os.path.join(self.fullpath, '.tracking'))
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_fullpath(fullpath: str) -> InstalledNodePackage:
|
def from_fullpath(fullpath: str) -> InstalledNodePackage:
|
||||||
parent_folder_name = os.path.split(fullpath)[-2]
|
parent_folder_name = os.path.split(fullpath)[-2]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user