updated old legacy store names
This commit is contained in:
+67
-94
@@ -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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user