updated old legacy store names
This commit is contained in:
@@ -13,7 +13,6 @@ from SYS.result_publication import publish_result_table
|
||||
from SYS import models
|
||||
from SYS import pipeline as ctx
|
||||
from .. import _shared as sh
|
||||
from Store import Store # retained for test monkeypatch compatibility
|
||||
|
||||
normalize_result_input = sh.normalize_result_input
|
||||
filter_results_by_temp = sh.filter_results_by_temp
|
||||
@@ -31,6 +30,7 @@ should_show_help = sh.should_show_help
|
||||
get_field = sh.get_field
|
||||
|
||||
_FIELD_NAME_RE = re.compile(r"^[A-Za-z0-9_]+$")
|
||||
_DETAIL_PANEL_LIMIT = 9
|
||||
|
||||
|
||||
def _normalize_title_for_extract(text: str) -> str:
|
||||
@@ -1191,7 +1191,13 @@ class Add_Tag(Cmdlet):
|
||||
subject = display_items[0] if len(display_items) == 1 else list(display_items)
|
||||
# Use helper to display items and make them @-selectable
|
||||
from ._shared import display_and_persist_items
|
||||
display_and_persist_items(list(display_items), title="Result", subject=subject)
|
||||
display_type = "item" if len(display_items) <= _DETAIL_PANEL_LIMIT else "custom"
|
||||
display_and_persist_items(
|
||||
list(display_items),
|
||||
title="Result",
|
||||
subject=subject,
|
||||
display_type=display_type,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@@ -22,6 +22,9 @@ get_field = sh.get_field
|
||||
from SYS.logger import debug, log
|
||||
|
||||
|
||||
_DETAIL_PANEL_LIMIT = 9
|
||||
|
||||
|
||||
def _matches_target(
|
||||
item: Any,
|
||||
target_hash: str | None,
|
||||
@@ -57,15 +60,56 @@ def _set_result_tags(result: Any, tags: list[str]) -> None:
|
||||
normalized = list(tags or [])
|
||||
set_field(result, "tag", normalized)
|
||||
|
||||
def _update_tag_columns(columns: Any) -> Any:
|
||||
if not isinstance(columns, (list, tuple)):
|
||||
return columns
|
||||
|
||||
updated_columns = []
|
||||
changed = False
|
||||
tag_value = ", ".join(normalized)
|
||||
for column in columns:
|
||||
if isinstance(column, tuple) and len(column) == 2:
|
||||
label, existing_value = column
|
||||
if str(label).strip().lower() in {"tag", "tags"}:
|
||||
updated_columns.append((label, tag_value))
|
||||
changed = True
|
||||
else:
|
||||
updated_columns.append((label, existing_value))
|
||||
elif isinstance(column, list) and len(column) == 2:
|
||||
label, existing_value = column
|
||||
if str(label).strip().lower() in {"tag", "tags"}:
|
||||
updated_columns.append([label, tag_value])
|
||||
changed = True
|
||||
else:
|
||||
updated_columns.append([label, existing_value])
|
||||
elif isinstance(column, dict):
|
||||
label = column.get("name") or column.get("label") or column.get("key")
|
||||
if str(label).strip().lower() in {"tag", "tags"}:
|
||||
updated_column = dict(column)
|
||||
updated_column["value"] = tag_value
|
||||
updated_columns.append(updated_column)
|
||||
changed = True
|
||||
else:
|
||||
updated_columns.append(column)
|
||||
else:
|
||||
updated_columns.append(column)
|
||||
if not changed:
|
||||
return columns
|
||||
if isinstance(columns, tuple):
|
||||
return tuple(updated_columns)
|
||||
return updated_columns
|
||||
|
||||
if isinstance(result, dict):
|
||||
result["tags_flat"] = list(normalized)
|
||||
if "tags" in result:
|
||||
result["tags"] = list(normalized)
|
||||
result["columns"] = _update_tag_columns(result.get("columns"))
|
||||
for container_name in ("extra", "metadata", "full_metadata"):
|
||||
container = result.get(container_name)
|
||||
if not isinstance(container, dict):
|
||||
continue
|
||||
if "tag" in container:
|
||||
container["tag"] = list(normalized)
|
||||
container["tag"] = list(normalized)
|
||||
container["tags_flat"] = list(normalized)
|
||||
if "tags" in container:
|
||||
container["tags"] = list(normalized)
|
||||
return
|
||||
@@ -74,12 +118,23 @@ def _set_result_tags(result: Any, tags: list[str]) -> None:
|
||||
setattr(result, "tags", list(normalized))
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
setattr(result, "tags_flat", list(normalized))
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
columns = getattr(result, "columns", None)
|
||||
updated_columns = _update_tag_columns(columns)
|
||||
if updated_columns is not columns:
|
||||
setattr(result, "columns", updated_columns)
|
||||
except Exception:
|
||||
pass
|
||||
for container_name in ("extra", "metadata", "full_metadata"):
|
||||
container = getattr(result, container_name, None)
|
||||
if not isinstance(container, dict):
|
||||
continue
|
||||
if "tag" in container:
|
||||
container["tag"] = list(normalized)
|
||||
container["tag"] = list(normalized)
|
||||
container["tags_flat"] = list(normalized)
|
||||
if "tags" in container:
|
||||
container["tags"] = list(normalized)
|
||||
|
||||
@@ -514,6 +569,11 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
|
||||
# Process each item
|
||||
success_count = 0
|
||||
stage_ctx = ctx.get_stage_context()
|
||||
is_last_stage = (stage_ctx is None) or bool(
|
||||
getattr(stage_ctx, "is_last_stage", False)
|
||||
)
|
||||
display_items: list[Any] = []
|
||||
|
||||
# If we have TagItems and no args, we are deleting the tags themselves
|
||||
# If we have Files (or other objects) and args, we are deleting tags FROM those files
|
||||
@@ -658,6 +718,8 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
if title_value:
|
||||
_apply_title_to_result(item, title_value)
|
||||
_refresh_result_table_tags(new_tags, h, store_str, path)
|
||||
if is_last_stage:
|
||||
display_items.append(item)
|
||||
try:
|
||||
ctx.emit(item)
|
||||
except Exception:
|
||||
@@ -667,12 +729,34 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
for item, item_hash, item_path, store_str in items_needing_individual:
|
||||
if _process_deletion(tags_arg, item_hash, item_path, store_str, config, result=item):
|
||||
success_count += 1
|
||||
if is_last_stage:
|
||||
display_items.append(item)
|
||||
try:
|
||||
ctx.emit(item)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if success_count > 0:
|
||||
if is_last_stage and display_items:
|
||||
try:
|
||||
subject = display_items[0] if len(display_items) == 1 else list(display_items)
|
||||
from ._shared import display_and_persist_items
|
||||
|
||||
display_type = "item" if len(display_items) <= _DETAIL_PANEL_LIMIT else "custom"
|
||||
display_and_persist_items(
|
||||
list(display_items),
|
||||
title="Result",
|
||||
subject=subject,
|
||||
display_type=display_type,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
if stage_ctx is not None:
|
||||
stage_ctx.emits = []
|
||||
except Exception:
|
||||
pass
|
||||
return 0
|
||||
return 1
|
||||
|
||||
|
||||
@@ -426,9 +426,9 @@ def _run_impl(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
backend = None
|
||||
if is_store_backed:
|
||||
try:
|
||||
from Store import Store
|
||||
from PluginCore.backend_registry import BackendRegistry
|
||||
|
||||
storage = Store(config, suppress_debug=True)
|
||||
storage = BackendRegistry(config, suppress_debug=True)
|
||||
backend = storage[str(store_name)]
|
||||
except Exception:
|
||||
backend = None
|
||||
@@ -445,9 +445,9 @@ def _run_impl(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
store_for_scrape = get_field(result, "store", None)
|
||||
if file_hash_for_scrape and store_for_scrape:
|
||||
try:
|
||||
from Store import Store
|
||||
from PluginCore.backend_registry import BackendRegistry
|
||||
|
||||
storage = Store(config, suppress_debug=True)
|
||||
storage = BackendRegistry(config, suppress_debug=True)
|
||||
backend = storage[str(store_for_scrape)]
|
||||
current_tags, _src = backend.get_tag(file_hash_for_scrape, config=config)
|
||||
if isinstance(current_tags, (list, tuple, set)) and current_tags:
|
||||
@@ -764,9 +764,9 @@ def _run_impl(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
)
|
||||
return 0
|
||||
try:
|
||||
from Store import Store
|
||||
from PluginCore.backend_registry import BackendRegistry
|
||||
|
||||
storage = Store(config, suppress_debug=True)
|
||||
storage = BackendRegistry(config, suppress_debug=True)
|
||||
backend = storage[str(store_name)]
|
||||
ok = bool(backend.add_tag(file_hash, apply_tags, config=config))
|
||||
if not ok:
|
||||
@@ -896,9 +896,9 @@ def _run_impl(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
|
||||
# Get tags using storage backend
|
||||
try:
|
||||
from Store import Store
|
||||
from PluginCore.backend_registry import BackendRegistry
|
||||
|
||||
storage = Store(config, suppress_debug=True)
|
||||
storage = BackendRegistry(config, suppress_debug=True)
|
||||
backend = storage[store_name]
|
||||
current, source = backend.get_tag(file_hash, config=config)
|
||||
current = list(current or [])
|
||||
|
||||
@@ -6,7 +6,7 @@ import sys
|
||||
from SYS import pipeline as ctx
|
||||
from .. import _shared as sh
|
||||
from SYS.logger import log
|
||||
from Store import Store
|
||||
from PluginCore.backend_registry import BackendRegistry
|
||||
|
||||
|
||||
class Add_Url(sh.Cmdlet):
|
||||
@@ -117,7 +117,7 @@ class Add_Url(sh.Cmdlet):
|
||||
|
||||
# Get backend and add url
|
||||
try:
|
||||
storage = Store(config)
|
||||
storage = BackendRegistry(config)
|
||||
|
||||
# Build batches per store.
|
||||
store_override = parsed.get("instance")
|
||||
|
||||
Reference in New Issue
Block a user