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

@@ -8,6 +8,7 @@ from pathlib import Path
import sys
from SYS.logger import log
from SYS.item_accessors import get_sha256_hex, get_store_name
from SYS import pipeline as ctx
from API import HydrusNetwork as hydrus_wrapper
@@ -20,7 +21,6 @@ parse_cmdlet_args = sh.parse_cmdlet_args
normalize_result_input = sh.normalize_result_input
should_show_help = sh.should_show_help
get_field = sh.get_field
from Store import Store
CMDLET = Cmdlet(
name="add-relationship",
@@ -68,14 +68,7 @@ CMDLET = Cmdlet(
)
def _normalize_hash_hex(value: Optional[str]) -> Optional[str]:
"""Normalize a hash hex string to lowercase 64-char format."""
if not value or not isinstance(value, str):
return None
normalized = value.strip().lower()
if len(normalized) == 64 and all(c in "0123456789abcdef" for c in normalized):
return normalized
return None
_normalize_hash_hex = sh.normalize_hash
def _extract_relationships_from_tag(tag_value: str) -> Dict[str, list[str]]:
@@ -279,23 +272,10 @@ def _resolve_items_from_at(token: str) -> Optional[list[Any]]:
def _extract_hash_and_store(item: Any) -> tuple[Optional[str], Optional[str]]:
"""Extract (hash_hex, store) from a result item (dict/object)."""
try:
h = get_field(item,
"hash_hex") or get_field(item,
"hash") or get_field(item,
"file_hash")
s = get_field(item, "store")
hash_norm = _normalize_hash_hex(str(h) if h is not None else None)
store_norm: Optional[str]
if s is None:
store_norm = None
else:
store_norm = str(s).strip()
if not store_norm:
store_norm = None
return hash_norm, store_norm
return (
get_sha256_hex(item, "hash_hex", "hash", "file_hash"),
get_store_name(item, "store"),
)
except Exception:
return None, None
@@ -461,9 +441,12 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
parsed = parse_cmdlet_args(_args, CMDLET)
arg_path: Optional[Path] = None
override_store = parsed.get("store")
override_hashes = sh.parse_hash_query(parsed.get("query"))
if parsed.get("query") and not override_hashes:
log("Invalid -query value (expected hash:<sha256>)", file=sys.stderr)
override_hashes, query_valid = sh.require_hash_query(
parsed.get("query"),
"Invalid -query value (expected hash:<sha256>)",
log_file=sys.stderr,
)
if not query_valid:
return 1
king_arg = parsed.get("king")
alt_arg = parsed.get("alt")
@@ -618,14 +601,13 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
is_folder_store = False
store_root: Optional[Path] = None
if store_name:
try:
store = Store(config)
backend = store[str(store_name)]
backend, _store_registry, _exc = sh.get_store_backend(config, str(store_name))
if backend is not None:
loc = getattr(backend, "location", None)
if callable(loc):
is_folder_store = True
store_root = Path(str(loc()))
except Exception:
else:
backend = None
is_folder_store = False
store_root = None