mirror of
https://git.datalinker.icu/ltdrdata/ComfyUI-Manager
synced 2025-12-08 21:54:26 +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
|
||||
|
||||
for path in os.listdir(working_directory):
|
||||
if '@' in path or path.endswith("ComfyUI-Manager"):
|
||||
if path.endswith("ComfyUI-Manager"):
|
||||
continue
|
||||
|
||||
fullpath = os.path.join(working_directory, path)
|
||||
@ -447,6 +447,25 @@ def is_git_repo(path: str) -> bool:
|
||||
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()
|
||||
|
||||
|
||||
|
||||
@ -105,13 +105,13 @@ def check_invalid_nodes():
|
||||
if subdir in ['.disabled', '__pycache__']:
|
||||
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')):
|
||||
invalid_nodes[spec[0]] = os.path.join(root, subdir)
|
||||
package = unified_manager.installed_node_packages.get(subdir)
|
||||
if not package:
|
||||
continue
|
||||
|
||||
if not package.isValid():
|
||||
invalid_nodes[subdir] = package.fullpath
|
||||
|
||||
node_paths = folder_paths.get_folder_paths("custom_nodes")
|
||||
for x in node_paths:
|
||||
@ -309,25 +309,6 @@ class ManagedResult:
|
||||
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:
|
||||
def __init__(self):
|
||||
self.installed_node_packages: dict[str, InstalledNodePackage] = {}
|
||||
@ -470,7 +451,7 @@ class UnifiedManager:
|
||||
self.installed_node_packages[node_package.id] = node_package
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
|
||||
if node_package.is_from_cnr and node_package.is_disabled:
|
||||
|
||||
@ -544,37 +544,12 @@ def populate_markdown(x):
|
||||
|
||||
@routes.get("/customnode/installed")
|
||||
async def installed_list(request):
|
||||
result = {}
|
||||
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
|
||||
unified_manager = core.unified_manager
|
||||
|
||||
spec = module_name.split('@')
|
||||
|
||||
if len(spec) == 2:
|
||||
node_package_name = spec[0]
|
||||
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')
|
||||
return web.json_response({
|
||||
node_id: package.version if package.is_from_cnr else package.get_commit_hash()
|
||||
for node_id, package in unified_manager.installed_node_packages.items()
|
||||
}, content_type='application/json')
|
||||
|
||||
|
||||
@routes.get("/customnode/getlist")
|
||||
|
||||
@ -5,7 +5,7 @@ import os
|
||||
|
||||
import toml
|
||||
|
||||
from git_helper import is_git_repo
|
||||
from git_helper import is_git_repo, get_commit_hash
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -37,6 +37,15 @@ class InstalledNodePackage:
|
||||
def is_disabled(self) -> bool:
|
||||
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
|
||||
def from_fullpath(fullpath: str) -> InstalledNodePackage:
|
||||
parent_folder_name = os.path.split(fullpath)[-2]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user