mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 07:05:43 -03:00
fix(config): rename legacy default library
This commit is contained in:
63
py/config.py
63
py/config.py
@@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import folder_paths # type: ignore
|
import folder_paths # type: ignore
|
||||||
from typing import Dict, Iterable, List, Mapping
|
from typing import Dict, Iterable, List, Mapping, Set
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
@@ -13,6 +13,37 @@ standalone_mode = os.environ.get("LORA_MANAGER_STANDALONE", "0") == "1" or os.en
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def _normalize_folder_paths_for_comparison(
|
||||||
|
folder_paths: Mapping[str, Iterable[str]]
|
||||||
|
) -> Dict[str, Set[str]]:
|
||||||
|
"""Normalize folder paths for comparison across libraries."""
|
||||||
|
|
||||||
|
normalized: Dict[str, Set[str]] = {}
|
||||||
|
for key, values in folder_paths.items():
|
||||||
|
if isinstance(values, str):
|
||||||
|
candidate_values: Iterable[str] = [values]
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
candidate_values = iter(values)
|
||||||
|
except TypeError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
normalized_values: Set[str] = set()
|
||||||
|
for value in candidate_values:
|
||||||
|
if not isinstance(value, str):
|
||||||
|
continue
|
||||||
|
stripped = value.strip()
|
||||||
|
if not stripped:
|
||||||
|
continue
|
||||||
|
normalized_values.add(os.path.normcase(os.path.normpath(stripped)))
|
||||||
|
|
||||||
|
if normalized_values:
|
||||||
|
normalized[key] = normalized_values
|
||||||
|
|
||||||
|
return normalized
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
"""Global configuration for LoRA Manager"""
|
"""Global configuration for LoRA Manager"""
|
||||||
|
|
||||||
@@ -45,6 +76,29 @@ class Config:
|
|||||||
|
|
||||||
libraries = settings_service.get_libraries()
|
libraries = settings_service.get_libraries()
|
||||||
comfy_library = libraries.get("comfyui", {})
|
comfy_library = libraries.get("comfyui", {})
|
||||||
|
default_library = libraries.get("default", {})
|
||||||
|
|
||||||
|
target_folder_paths = {
|
||||||
|
'loras': list(self.loras_roots),
|
||||||
|
'checkpoints': list(self.checkpoints_roots or []),
|
||||||
|
'unet': list(self.unet_roots or []),
|
||||||
|
'embeddings': list(self.embeddings_roots or []),
|
||||||
|
}
|
||||||
|
|
||||||
|
normalized_target_paths = _normalize_folder_paths_for_comparison(target_folder_paths)
|
||||||
|
|
||||||
|
if (not comfy_library and default_library and normalized_target_paths and
|
||||||
|
_normalize_folder_paths_for_comparison(default_library.get("folder_paths", {})) ==
|
||||||
|
normalized_target_paths):
|
||||||
|
try:
|
||||||
|
settings_service.rename_library("default", "comfyui")
|
||||||
|
logger.info("Renamed legacy 'default' library to 'comfyui'")
|
||||||
|
libraries = settings_service.get_libraries()
|
||||||
|
comfy_library = libraries.get("comfyui", {})
|
||||||
|
except Exception as rename_error:
|
||||||
|
logger.debug(
|
||||||
|
"Failed to rename legacy 'default' library: %s", rename_error
|
||||||
|
)
|
||||||
|
|
||||||
default_lora_root = comfy_library.get("default_lora_root", "")
|
default_lora_root = comfy_library.get("default_lora_root", "")
|
||||||
if not default_lora_root and len(self.loras_roots) == 1:
|
if not default_lora_root and len(self.loras_roots) == 1:
|
||||||
@@ -66,12 +120,7 @@ class Config:
|
|||||||
|
|
||||||
settings_service.upsert_library(
|
settings_service.upsert_library(
|
||||||
"comfyui",
|
"comfyui",
|
||||||
folder_paths={
|
folder_paths=target_folder_paths,
|
||||||
'loras': list(self.loras_roots),
|
|
||||||
'checkpoints': list(self.checkpoints_roots or []),
|
|
||||||
'unet': list(self.unet_roots or []),
|
|
||||||
'embeddings': list(self.embeddings_roots or []),
|
|
||||||
},
|
|
||||||
default_lora_root=default_lora_root,
|
default_lora_root=default_lora_root,
|
||||||
default_checkpoint_root=default_checkpoint_root,
|
default_checkpoint_root=default_checkpoint_root,
|
||||||
default_embedding_root=default_embedding_root,
|
default_embedding_root=default_embedding_root,
|
||||||
|
|||||||
Reference in New Issue
Block a user