This commit is contained in:
2026-03-25 22:39:30 -07:00
parent c31402c8f1
commit 562acd809c
46 changed files with 2367 additions and 1868 deletions

View File

@@ -1,7 +1,6 @@
from __future__ import annotations
from typing import Any, Dict, Sequence
from pathlib import Path
import sys
from SYS import pipeline as ctx
@@ -15,7 +14,6 @@ parse_tag_arguments = sh.parse_tag_arguments
should_show_help = sh.should_show_help
get_field = sh.get_field
from SYS.logger import debug, log
from Store import Store
def _refresh_tag_view_if_current(
@@ -80,31 +78,22 @@ def _refresh_tag_view_if_current(
refresh_args.extend(["-query", f"hash:{file_hash}"])
# Build a lean subject so get-tag fetches fresh tags instead of reusing cached payloads.
def _value_has_content(value: Any) -> bool:
if value is None:
return False
if isinstance(value, str):
return bool(value.strip())
if isinstance(value, (list, tuple, set)):
return len(value) > 0
return True
def _build_refresh_subject() -> Dict[str, Any]:
payload: Dict[str, Any] = {}
payload["hash"] = file_hash
store_value = store_name or get_field(subject, "store")
if _value_has_content(store_value):
if sh.value_has_content(store_value):
payload["store"] = store_value
path_value = path or get_field(subject, "path")
if not _value_has_content(path_value):
if not sh.value_has_content(path_value):
path_value = get_field(subject, "target")
if _value_has_content(path_value):
if sh.value_has_content(path_value):
payload["path"] = path_value
for key in ("title", "name", "url", "relations", "service_name"):
val = get_field(subject, key)
if _value_has_content(val):
if sh.value_has_content(val):
payload[key] = val
extra_value = get_field(subject, "extra")
@@ -115,7 +104,7 @@ def _refresh_tag_view_if_current(
}
if cleaned:
payload["extra"] = cleaned
elif _value_has_content(extra_value):
elif sh.value_has_content(extra_value):
payload["extra"] = extra_value
return payload
@@ -201,11 +190,12 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
rest.append(a)
i += 1
override_hash = sh.parse_single_hash_query(
override_query
) if override_query else None
if override_query and not override_hash:
log("Invalid -query value (expected hash:<sha256>)", file=sys.stderr)
override_hash, query_valid = sh.require_single_hash_query(
override_query,
"Invalid -query value (expected hash:<sha256>)",
log_file=sys.stderr,
)
if not query_valid:
return 1
# Selection syntax (@...) is handled by the pipeline runner, not by this cmdlet.
@@ -242,11 +232,7 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
return 1
# Normalize result to a list for processing
items_to_process = []
if isinstance(result, list):
items_to_process = result
elif result:
items_to_process = [result]
items_to_process = sh.normalize_result_items(result)
# Process each item
success_count = 0
@@ -358,14 +344,7 @@ def _process_deletion(
)
return False
resolved_hash = normalize_hash(file_hash) if file_hash else None
if not resolved_hash and path:
try:
from SYS.utils import sha256_file
resolved_hash = sha256_file(Path(path))
except Exception:
resolved_hash = None
resolved_hash = sh.resolve_hash_for_cmdlet(file_hash, path, None)
if not resolved_hash:
log(
@@ -376,7 +355,13 @@ def _process_deletion(
def _fetch_existing_tags() -> list[str]:
try:
backend = Store(config, suppress_debug=True)[store_name]
backend, _store_registry, _exc = sh.get_store_backend(
config,
store_name,
suppress_debug=True,
)
if backend is None:
return []
existing, _src = backend.get_tag(resolved_hash, config=config)
return list(existing or [])
except Exception:
@@ -403,7 +388,13 @@ def _process_deletion(
return False
try:
backend = Store(config, suppress_debug=True)[store_name]
backend, _store_registry, exc = sh.get_store_backend(
config,
store_name,
suppress_debug=True,
)
if backend is None:
raise exc or KeyError(store_name)
ok = backend.delete_tag(resolved_hash, list(tags), config=config)
if ok:
preview = resolved_hash[:12] + ("" if len(resolved_hash) > 12 else "")