updated old legacy store names

This commit is contained in:
2026-05-23 13:49:47 -07:00
parent e8913d1344
commit a8cdd09e1e
31 changed files with 466 additions and 469 deletions
+67 -94
View File
@@ -16,7 +16,7 @@ from SYS.pipeline_progress import PipelineProgress
from SYS.result_publication import overlay_existing_result_table, publish_result_table
from SYS.rich_display import show_available_plugins_panel, show_plugin_config_panel
from SYS.utils_constant import ALL_SUPPORTED_EXTENSIONS
from Store import Store
from PluginCore.backend_registry import BackendRegistry
from API.HTTP import _download_direct_file
from .. import _shared as sh
@@ -45,21 +45,21 @@ SUPPORTED_MEDIA_EXTENSIONS = ALL_SUPPORTED_EXTENSIONS
class _CommandDependencies:
"""Command-scope cache for Store and plugin instances to avoid repeated instantiation."""
"""Command-scope cache for the backend registry and plugin instances."""
def __init__(self, config: Dict[str, Any]) -> None:
self.config = config
self._store: Optional[Store] = None
self._backend_registry: Optional[BackendRegistry] = None
self._plugins: Dict[str, Any] = {}
def get_store(self) -> Optional[Store]:
"""Lazily initialize and return the command-scope Store instance."""
if self._store is None:
def get_backend_registry(self) -> Optional[BackendRegistry]:
"""Lazily initialize and return the command-scope backend registry."""
if self._backend_registry is None:
try:
self._store = Store(self.config)
self._backend_registry = BackendRegistry(self.config)
except Exception:
self._store = None
return self._store
self._backend_registry = None
return self._backend_registry
def get_plugin(self, name: str) -> Optional[Any]:
"""Cached plugin lookup by name."""
@@ -236,7 +236,7 @@ class Add_File(Cmdlet):
# Initialize command-scope dependency context (caches Store/plugins)
deps = _CommandDependencies(config)
storage_registry = deps.get_store()
storage_registry = deps.get_backend_registry()
path_arg = parsed.get("path")
location = parsed.get("instance")
@@ -354,8 +354,8 @@ class Add_File(Cmdlet):
is_storage_backend_location = False
if location:
try:
store_for_lookup = storage_registry or deps.get_store()
is_storage_backend_location = Add_File._resolve_backend_by_name(store_for_lookup, str(location)) is not None
backend_registry_for_lookup = storage_registry or deps.get_backend_registry()
is_storage_backend_location = Add_File._resolve_backend_by_name(backend_registry_for_lookup, str(location)) is not None
except Exception:
is_storage_backend_location = False
@@ -697,8 +697,8 @@ class Add_File(Cmdlet):
if location:
try:
store = storage_registry or deps.get_store()
resolved_backend = Add_File._resolve_backend_by_name(store, str(location))
backend_registry = storage_registry or deps.get_backend_registry()
resolved_backend = Add_File._resolve_backend_by_name(backend_registry, str(location))
if resolved_backend is not None:
code = self._handle_storage_backend(
item,
@@ -845,7 +845,7 @@ class Add_File(Cmdlet):
hash_values: List[str],
config: Dict[str,
Any],
store_instance: Optional[Store] = None,
store_instance: Optional[BackendRegistry] = None,
) -> Optional[List[Any]]:
"""Run search-file for a list of hashes and promote the table to a display overlay.
@@ -1053,7 +1053,7 @@ class Add_File(Cmdlet):
str]]],
config: Dict[str,
Any],
store_instance: Optional[Store] = None,
store_instance: Optional[BackendRegistry] = None,
deps: Optional[_CommandDependencies] = None,
) -> None:
"""Persist relationships to backends that support relationships.
@@ -1067,7 +1067,7 @@ class Add_File(Cmdlet):
deps = _CommandDependencies(config)
try:
store = store_instance if store_instance is not None else deps.get_store()
backend_registry = store_instance if store_instance is not None else deps.get_backend_registry()
except Exception:
return
@@ -1076,7 +1076,7 @@ class Add_File(Cmdlet):
continue
try:
backend = store[str(backend_name)]
backend = backend_registry[str(backend_name)]
except Exception:
continue
@@ -1356,9 +1356,9 @@ class Add_File(Cmdlet):
try:
if deps is None:
deps = _CommandDependencies(config)
store = store_instance or deps.get_store()
backend = Add_File._resolve_backend_by_name(store, r_store)
backend_registry = store_instance or deps.get_backend_registry()
backend = Add_File._resolve_backend_by_name(backend_registry, r_store)
if backend is not None:
mp = backend.get_file(r_hash)
if isinstance(mp, Path) and mp.exists():
@@ -1497,14 +1497,14 @@ class Add_File(Cmdlet):
explicit_instance = str(instance_name or "").strip() or None
try:
storage = store_instance if store_instance is not None else Store(config)
backend_registry = store_instance if store_instance is not None else BackendRegistry(config)
except Exception:
storage = None
backend_registry = None
try:
resolved_name, backend = resolver(
explicit_instance,
storage=storage,
storage=backend_registry,
require_explicit=bool(explicit_instance),
)
except TypeError:
@@ -1622,8 +1622,8 @@ class Add_File(Cmdlet):
if deps is None:
deps = _CommandDependencies(config)
store = store_instance or deps.get_store()
backend = Add_File._resolve_backend_by_name(store, r_store) if store is not None else None
backend_registry = store_instance or deps.get_backend_registry()
backend = Add_File._resolve_backend_by_name(backend_registry, r_store) if backend_registry is not None else None
if backend is None:
return None, None, None
@@ -2475,10 +2475,23 @@ class Add_File(Cmdlet):
List[str]]]]] = None,
suppress_last_stage_overlay: bool = False,
auto_search_file: bool = True,
store_instance: Optional[Store] = None,
store_instance: Optional[BackendRegistry] = None,
) -> int:
"""Handle uploading to a registered storage backend (e.g., 'test' folder store, 'hydrus', etc.)."""
##log(f"Adding file to storage backend '{backend_name}': {media_path.name}", file=sys.stderr)
pipeline_progress = PipelineProgress(ctx)
def _set_status(text: str) -> None:
try:
pipeline_progress.set_status(f"{backend_name}: {text}")
except Exception:
pass
def _clear_status() -> None:
try:
pipeline_progress.clear_status()
except Exception:
pass
delete_after_effective = bool(delete_after)
# ... (lines omitted for brevity but I need to keep them contextually correct)
@@ -2510,11 +2523,11 @@ class Add_File(Cmdlet):
pass
try:
store = store_instance if store_instance is not None else Store(config)
backend, store, backend_exc = sh.get_preferred_store_backend(
backend_registry = store_instance if store_instance is not None else BackendRegistry(config)
backend, backend_registry, backend_exc = sh.get_preferred_store_backend(
config,
backend_name,
store_registry=store,
store_registry=backend_registry,
suppress_debug=True,
)
if backend is None:
@@ -2654,6 +2667,8 @@ class Add_File(Cmdlet):
tag=upload_tags,
url=[] if ((defer_url_association and url) or (not supports_url_association)) else url,
file_hash=f_hash,
pipeline_progress=pipeline_progress,
transfer_label=title or media_path.name,
)
##log(f"✓ File added to '{backend_name}': {file_identifier}", file=sys.stderr)
@@ -2704,6 +2719,7 @@ class Add_File(Cmdlet):
try:
adder = getattr(backend, "add_tag", None)
if callable(adder):
_set_status("applying deferred tags")
adder(resolved_hash, list(tags))
except Exception as exc:
log(f"[add-file] Post-upload tagging failed for {backend_name}: {exc}", file=sys.stderr)
@@ -2724,88 +2740,43 @@ class Add_File(Cmdlet):
try:
# Folder.add_file already persists URLs, avoid extra DB traffic here.
if not is_folder_backend:
_set_status("associating urls")
backend.add_url(resolved_hash, list(url))
except Exception:
pass
# If a subtitle note was provided upstream (e.g., download-media writes notes.sub),
# persist it automatically like add-note would.
sub_note = Add_File._get_note_text(result, pipe_obj, "sub")
if sub_note and supports_note_association:
def _write_note(note_name: str, note_text: Optional[str]) -> None:
if not note_text or not supports_note_association:
return
try:
setter = getattr(backend, "set_note", None)
if callable(setter):
setter(resolved_hash, "sub", sub_note)
_set_status(f"writing {note_name} note")
setter(resolved_hash, note_name, note_text)
except Exception as exc:
debug_panel(
"add-file note write failed",
[
("store", backend_name),
("hash", resolved_hash),
("note", "sub"),
("note", note_name),
("error", exc),
],
border_style="yellow",
)
lyric_note = Add_File._get_note_text(result, pipe_obj, "lyric")
if lyric_note and supports_note_association:
try:
setter = getattr(backend, "set_note", None)
if callable(setter):
setter(resolved_hash, "lyric", lyric_note)
except Exception as exc:
debug_panel(
"add-file note write failed",
[
("store", backend_name),
("hash", resolved_hash),
("note", "lyric"),
("error", exc),
],
border_style="yellow",
)
chapters_note = Add_File._get_note_text(result, pipe_obj, "chapters")
if chapters_note and supports_note_association:
try:
setter = getattr(backend, "set_note", None)
if callable(setter):
setter(resolved_hash, "chapters", chapters_note)
except Exception as exc:
debug_panel(
"add-file note write failed",
[
("store", backend_name),
("hash", resolved_hash),
("note", "chapters"),
("error", exc),
],
border_style="yellow",
)
caption_note = Add_File._get_note_text(result, pipe_obj, "caption")
if caption_note and supports_note_association:
try:
setter = getattr(backend, "set_note", None)
if callable(setter):
setter(resolved_hash, "caption", caption_note)
except Exception as exc:
debug_panel(
"add-file note write failed",
[
("store", backend_name),
("hash", resolved_hash),
("note", "caption"),
("error", exc),
],
border_style="yellow",
)
_write_note("sub", Add_File._get_note_text(result, pipe_obj, "sub"))
_write_note("lyric", Add_File._get_note_text(result, pipe_obj, "lyric"))
_write_note("chapters", Add_File._get_note_text(result, pipe_obj, "chapters"))
_write_note("caption", Add_File._get_note_text(result, pipe_obj, "caption"))
meta: Dict[str,
Any] = {}
try:
if not is_folder_backend:
_set_status("loading stored metadata")
meta = backend.get_metadata(resolved_hash) or {}
except Exception:
meta = {}
@@ -2886,9 +2857,11 @@ class Add_File(Cmdlet):
media_path,
delete_source=delete_after_effective
)
_clear_status()
return 0
except Exception as exc:
_clear_status()
log(
f"❌ Failed to add file to backend '{backend_name}': {exc}",
file=sys.stderr
@@ -2907,12 +2880,12 @@ class Add_File(Cmdlet):
List[str]]]],
config: Dict[str,
Any],
store_instance: Optional[Store] = None,
store_instance: Optional[BackendRegistry] = None,
) -> None:
"""Apply deferred URL associations in bulk, grouped per backend."""
try:
store = store_instance if store_instance is not None else Store(config)
backend_registry = store_instance if store_instance is not None else BackendRegistry(config)
except Exception:
return
@@ -2920,10 +2893,10 @@ class Add_File(Cmdlet):
if not pairs:
continue
try:
backend, store, _exc = sh.get_store_backend(
backend, backend_registry, _exc = sh.get_store_backend(
config,
backend_name,
store_registry=store,
store_registry=backend_registry,
)
if backend is None:
continue
@@ -2960,12 +2933,12 @@ class Add_File(Cmdlet):
List[str]]]],
config: Dict[str,
Any],
store_instance: Optional[Store] = None,
store_instance: Optional[BackendRegistry] = None,
) -> None:
"""Apply deferred tag associations in bulk, grouped per backend."""
try:
store = store_instance if store_instance is not None else Store(config)
backend_registry = store_instance if store_instance is not None else BackendRegistry(config)
except Exception:
return
@@ -2974,7 +2947,7 @@ class Add_File(Cmdlet):
pending or {},
bulk_method_name="add_tags_bulk",
single_method_name="add_tag",
store_registry=store,
store_registry=backend_registry,
pass_config_to_bulk=False,
pass_config_to_single=False,
)
+3 -3
View File
@@ -9,7 +9,7 @@ from pathlib import Path
from SYS.logger import debug, log
from PluginCore.registry import get_plugin
from Store import Store
from PluginCore.backend_registry import BackendRegistry
from .. import _shared as sh
from SYS import pipeline as ctx
from SYS.result_table_helpers import add_row_columns
@@ -156,7 +156,7 @@ class Delete_File(sh.Cmdlet):
backend = None
try:
if instance:
registry = Store(config)
registry = BackendRegistry(config)
if registry.is_available(str(store)):
backend = registry[str(store)]
except Exception:
@@ -242,7 +242,7 @@ class Delete_File(sh.Cmdlet):
try:
# Re-use an already resolved backend when available.
if backend is None:
registry = Store(config)
registry = BackendRegistry(config)
if registry.is_available(str(store)):
backend = registry[str(store)]
+1 -1
View File
@@ -1661,7 +1661,7 @@ class Download_File(Cmdlet):
"""Initialize store registry and determine whether a Hydrus backend is usable."""
storage = None
try:
from Store import Store as _Store
from PluginCore.backend_registry import BackendRegistry as _Store
storage = _Store(config)
except Exception:
+12 -12
View File
@@ -1865,8 +1865,8 @@ class search_file(Cmdlet):
worker_id = str(uuid.uuid4())
from Store import Store
storage_registry = Store(config=config or {})
from PluginCore.backend_registry import BackendRegistry
storage_registry = BackendRegistry(config=config or {})
if not storage_registry.list_backends():
# Internal refreshes should not trigger config panels or stop progress.
@@ -1911,8 +1911,8 @@ class search_file(Cmdlet):
except Exception:
pass
from Store.registry import list_configured_backend_names, get_backend_instance
from Store._base import Store as BaseStore
from PluginCore.backend_registry import list_configured_backend_names, get_backend_instance
from PluginCore.backend_base import BackendBase
backend_to_search = storage_backend or None
@@ -1929,13 +1929,13 @@ class search_file(Cmdlet):
for h in hash_query:
resolved_backend_name: Optional[str] = None
resolved_backend = None
store_registry = None
backend_registry_cache = None
for backend_name in backends_to_try:
backend, store_registry, _exc = get_preferred_store_backend(
backend, backend_registry_cache, _exc = get_preferred_store_backend(
config,
backend_name,
store_registry=store_registry,
store_registry=backend_registry_cache,
suppress_debug=True,
)
if backend is None:
@@ -2128,7 +2128,7 @@ class search_file(Cmdlet):
db.update_worker_status(worker_id, "error")
return 1
if type(target_backend).search is BaseStore.search:
if type(target_backend).search is BackendBase.search:
log(
f"Backend '{backend_to_search}' does not support searching",
file=sys.stderr,
@@ -2138,13 +2138,13 @@ class search_file(Cmdlet):
results = target_backend.search(query, limit=limit)
else:
all_results = []
store_registry = None
backend_registry_cache = None
for backend_name in list_configured_backend_names(config or {}):
try:
backend, store_registry, _exc = get_preferred_store_backend(
backend, backend_registry_cache, _exc = get_preferred_store_backend(
config,
backend_name,
store_registry=store_registry,
store_registry=backend_registry_cache,
suppress_debug=True,
)
if backend is None:
@@ -2154,7 +2154,7 @@ class search_file(Cmdlet):
searched_backends.append(backend_name)
if type(backend).search is BaseStore.search:
if type(backend).search is BackendBase.search:
continue
backend_results = backend.search(
+3 -2
View File
@@ -14,6 +14,7 @@ from urllib.parse import urlparse
from SYS.logger import log, debug
from SYS.item_accessors import get_store_name
from SYS.utils import sha256_file
from PluginCore.backend_registry import BackendRegistry
from .. import _shared as sh
Cmdlet = sh.Cmdlet
@@ -166,8 +167,8 @@ def _persist_alt_relationship(
) -> None:
"""Persist directional alt -> king relationship in the given backend."""
try:
store = Store(config)
backend: Any = store[str(store_name)]
backend_registry = BackendRegistry(config)
backend: Any = backend_registry[str(store_name)]
except Exception:
return