refactored and updated tags cmdlet and hydrusnetwork interaction plugin features
This commit is contained in:
+68
-64
@@ -456,36 +456,37 @@ def list_configured_backend_names(config: Optional[Dict[str, Any]]) -> list[str]
|
||||
(case-insensitive) when present, otherwise the instance key.
|
||||
"""
|
||||
try:
|
||||
store_cfg = (config or {}).get("store") or {}
|
||||
if not isinstance(store_cfg, dict):
|
||||
return []
|
||||
|
||||
classes_by_type = _discover_store_classes()
|
||||
names: list[str] = []
|
||||
for raw_store_type, instances in store_cfg.items():
|
||||
if not isinstance(instances, dict):
|
||||
continue
|
||||
store_type = _normalize_store_type(str(raw_store_type))
|
||||
if store_type == "folder" or store_type in _PROVIDER_ONLY_STORE_NAMES:
|
||||
for section_name in ("store", "plugin", "provider"):
|
||||
section_cfg = (config or {}).get(section_name) or {}
|
||||
if not isinstance(section_cfg, dict):
|
||||
continue
|
||||
|
||||
store_cls = _resolve_store_class(store_type, classes_by_type)
|
||||
if store_cls is None:
|
||||
continue
|
||||
|
||||
for instance_name, instance_config in instances.items():
|
||||
try:
|
||||
_build_kwargs(store_cls, str(instance_name), instance_config)
|
||||
except Exception:
|
||||
for raw_store_type, instances in section_cfg.items():
|
||||
if not isinstance(instances, dict):
|
||||
continue
|
||||
if isinstance(instance_config, dict):
|
||||
override_name = _get_case_insensitive(dict(instance_config), "NAME")
|
||||
if override_name:
|
||||
names.append(str(override_name))
|
||||
store_type = _normalize_store_type(str(raw_store_type))
|
||||
if store_type == "folder" or store_type in _PROVIDER_ONLY_STORE_NAMES:
|
||||
continue
|
||||
|
||||
store_cls = _resolve_store_class(store_type, classes_by_type)
|
||||
if store_cls is None:
|
||||
continue
|
||||
|
||||
for instance_name, instance_config in instances.items():
|
||||
try:
|
||||
_build_kwargs(store_cls, str(instance_name), instance_config)
|
||||
except Exception:
|
||||
continue
|
||||
if isinstance(instance_config, dict):
|
||||
override_name = _get_case_insensitive(dict(instance_config), "NAME")
|
||||
if override_name:
|
||||
names.append(str(override_name))
|
||||
else:
|
||||
names.append(str(instance_name))
|
||||
else:
|
||||
names.append(str(instance_name))
|
||||
else:
|
||||
names.append(str(instance_name))
|
||||
|
||||
return sorted(set(names))
|
||||
except Exception:
|
||||
@@ -503,34 +504,37 @@ def get_backend_instance(config: Optional[Dict[str, Any]], backend_name: str, *,
|
||||
"""
|
||||
if not backend_name:
|
||||
return None
|
||||
store_cfg = (config or {}).get("store") or {}
|
||||
if not isinstance(store_cfg, dict):
|
||||
return None
|
||||
classes_by_type = _discover_store_classes()
|
||||
desired = str(backend_name or "").strip().lower()
|
||||
|
||||
for raw_store_type, instances in store_cfg.items():
|
||||
if not isinstance(instances, dict):
|
||||
continue
|
||||
store_type = _normalize_store_type(str(raw_store_type))
|
||||
store_cls = _resolve_store_class(store_type, classes_by_type)
|
||||
if store_cls is None:
|
||||
for section_name in ("store", "plugin", "provider"):
|
||||
section_cfg = (config or {}).get(section_name) or {}
|
||||
if not isinstance(section_cfg, dict):
|
||||
continue
|
||||
|
||||
# Fast path: match using raw 'NAME' or 'name' in config without building full kwargs
|
||||
for instance_name, instance_cfg in instances.items():
|
||||
candidate_alias = None
|
||||
if isinstance(instance_cfg, dict):
|
||||
candidate_alias = (
|
||||
instance_cfg.get("NAME") or instance_cfg.get("name")
|
||||
)
|
||||
candidate_alias = str(candidate_alias or instance_name).strip()
|
||||
if candidate_alias.lower() == desired:
|
||||
for raw_store_type, instances in section_cfg.items():
|
||||
if not isinstance(instances, dict):
|
||||
continue
|
||||
store_type = _normalize_store_type(str(raw_store_type))
|
||||
store_cls = _resolve_store_class(store_type, classes_by_type)
|
||||
if store_cls is None:
|
||||
continue
|
||||
|
||||
# Fast path: match using raw 'NAME' or 'name' in config without building full kwargs
|
||||
for instance_name, instance_cfg in instances.items():
|
||||
candidate_alias = None
|
||||
if isinstance(instance_cfg, dict):
|
||||
candidate_alias = (
|
||||
instance_cfg.get("NAME") or instance_cfg.get("name")
|
||||
)
|
||||
candidate_alias = str(candidate_alias or instance_name).strip()
|
||||
if candidate_alias.lower() != desired:
|
||||
continue
|
||||
try:
|
||||
kwargs = _build_kwargs(store_cls, str(instance_name), instance_cfg)
|
||||
except Exception as exc:
|
||||
if not suppress_debug:
|
||||
debug(f"[Store] Can't build kwargs for '{instance_name}' ({store_type}): {exc}")
|
||||
debug(f"[Store] Can't build kwargs for '{instance_name}' ({store_type}/{section_name}): {exc}")
|
||||
return None
|
||||
try:
|
||||
for key in list(kwargs.keys()):
|
||||
@@ -546,28 +550,28 @@ def get_backend_instance(config: Optional[Dict[str, Any]], backend_name: str, *,
|
||||
debug(f"[Store] Failed to instantiate backend '{candidate_alias}': {exc}")
|
||||
return None
|
||||
|
||||
# Fallback: build kwargs for each instance and compare resolved NAME
|
||||
for instance_name, instance_cfg in instances.items():
|
||||
try:
|
||||
kwargs = _build_kwargs(store_cls, str(instance_name), instance_cfg)
|
||||
except Exception:
|
||||
continue
|
||||
alias = str(kwargs.get("NAME") or instance_name).strip()
|
||||
if alias.lower() != desired:
|
||||
continue
|
||||
try:
|
||||
for key in list(kwargs.keys()):
|
||||
if _normalize_config_key(key) in {"PATH", "LOCATION"}:
|
||||
kwargs[key] = str(expand_path(kwargs[key]))
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
backend = store_cls(**kwargs)
|
||||
return backend
|
||||
except Exception as exc:
|
||||
if not suppress_debug:
|
||||
debug(f"[Store] Failed to instantiate backend '{alias}': {exc}")
|
||||
return None
|
||||
# Fallback: build kwargs for each instance and compare resolved NAME
|
||||
for instance_name, instance_cfg in instances.items():
|
||||
try:
|
||||
kwargs = _build_kwargs(store_cls, str(instance_name), instance_cfg)
|
||||
except Exception:
|
||||
continue
|
||||
alias = str(kwargs.get("NAME") or instance_name).strip()
|
||||
if alias.lower() != desired:
|
||||
continue
|
||||
try:
|
||||
for key in list(kwargs.keys()):
|
||||
if _normalize_config_key(key) in {"PATH", "LOCATION"}:
|
||||
kwargs[key] = str(expand_path(kwargs[key]))
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
backend = store_cls(**kwargs)
|
||||
return backend
|
||||
except Exception as exc:
|
||||
if not suppress_debug:
|
||||
debug(f"[Store] Failed to instantiate backend '{alias}': {exc}")
|
||||
return None
|
||||
|
||||
if not suppress_debug:
|
||||
debug(f"[Store] Backend '{backend_name}' not found in config")
|
||||
|
||||
Reference in New Issue
Block a user