continuing refactor

This commit is contained in:
2026-05-03 21:20:05 -07:00
parent 77cab1bd27
commit 5534812426
50 changed files with 1004 additions and 428 deletions
+19 -19
View File
@@ -34,7 +34,7 @@ CMDLET = Cmdlet(
type="string",
description="Specify the local file path (if not piping a result).",
),
SharedArgs.STORE,
SharedArgs.INSTANCE,
SharedArgs.QUERY,
CmdletArg(
"-king",
@@ -440,7 +440,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
# Parse arguments using CMDLET spec
parsed = parse_cmdlet_args(_args, CMDLET)
arg_path: Optional[Path] = None
override_store = parsed.get("store")
override_store = parsed.get("instance")
override_hashes, query_valid = sh.require_hash_query(
parsed.get("query"),
"Invalid -query value (expected hash:<sha256>)",
@@ -491,7 +491,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
return 1
if not override_store:
log(
"-store is required when using -alt with a raw hash list",
"-instance is required when using -alt with a raw hash list",
file=sys.stderr
)
return 1
@@ -507,7 +507,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
if (not items_to_process) and override_hashes:
if not override_store:
log(
"-store is required when using -query without piped items",
"-instance is required when using -query without piped items",
file=sys.stderr
)
return 1
@@ -560,7 +560,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
log(f"Failed to resolve king argument: {king_text}", file=sys.stderr)
return 1
# Decide target store: override_store > (king store + piped item stores) (must be consistent)
# Decide target instance: override_store > (king store + piped item stores) (must be consistent)
store_name: Optional[str] = str(override_store).strip() if override_store else None
if not store_name:
stores = set()
@@ -574,15 +574,15 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
store_name = next(iter(stores))
elif len(stores) > 1:
log(
"Multiple stores detected (king/alt across stores); use -store and ensure all selections are from the same store",
"Multiple stores detected (king/alt across stores); use -instance and ensure all selections are from the same store",
file=sys.stderr,
)
return 1
# Enforce same-store relationships when store context is available.
# Enforce same-instance relationships when store context is available.
if king_store and store_name and str(king_store) != str(store_name):
log(
f"Cross-store relationship blocked: king is in store '{king_store}' but -store is '{store_name}'",
f"Cross-instance relationship blocked: king is in store '{king_store}' but -instance is '{store_name}'",
file=sys.stderr,
)
return 1
@@ -591,7 +591,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
s = get_field(item, "store")
if s and str(s) != str(store_name):
log(
f"Cross-store relationship blocked: alt item store '{s}' != '{store_name}'",
f"Cross-instance relationship blocked: alt item store '{s}' != '{store_name}'",
file=sys.stderr,
)
return 1
@@ -707,7 +707,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
except Exception:
pass
# STORE/HASH MODE (preferred): use -store and hashes; do not require file paths.
# STORE/HASH MODE (preferred): use -instance and hashes; do not require file paths.
if store_name and is_folder_store and store_root is not None:
try:
with API_folder_store(store_root) as db:
@@ -719,7 +719,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
if item_store and store_name and str(item_store) != str(
store_name):
log(
f"Cross-store relationship blocked: item store '{item_store}' != '{store_name}'",
f"Cross-instance relationship blocked: item store '{item_store}' != '{store_name}'",
file=sys.stderr,
)
return 1
@@ -743,7 +743,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
h, item_store = _extract_hash_and_store(item)
if item_store and store_name and str(item_store) != str(store_name):
log(
f"Cross-store relationship blocked: item store '{item_store}' != '{store_name}'",
f"Cross-instance relationship blocked: item store '{item_store}' != '{store_name}'",
file=sys.stderr,
)
return 1
@@ -767,10 +767,10 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
log("Hydrus client unavailable for this store", file=sys.stderr)
return 1
# Verify hashes exist in this Hydrus backend to prevent cross-store edges.
# Verify hashes exist in this Hydrus backend to prevent cross-instance edges.
if king_hash and (not _hydrus_hash_exists(hydrus_client, king_hash)):
log(
f"Cross-store relationship blocked: king hash not found in store '{store_name}'",
f"Cross-instance relationship blocked: king hash not found in store '{store_name}'",
file=sys.stderr,
)
return 1
@@ -782,7 +782,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
h, item_store = _extract_hash_and_store(item)
if item_store and store_name and str(item_store) != str(store_name):
log(
f"Cross-store relationship blocked: item store '{item_store}' != '{store_name}'",
f"Cross-instance relationship blocked: item store '{item_store}' != '{store_name}'",
file=sys.stderr,
)
return 1
@@ -792,7 +792,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
first_hash = h
if not _hydrus_hash_exists(hydrus_client, first_hash):
log(
f"Cross-store relationship blocked: hash not found in store '{store_name}'",
f"Cross-instance relationship blocked: hash not found in store '{store_name}'",
file=sys.stderr,
)
return 1
@@ -800,7 +800,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
if h != first_hash:
if not _hydrus_hash_exists(hydrus_client, h):
log(
f"Cross-store relationship blocked: hash not found in store '{store_name}'",
f"Cross-instance relationship blocked: hash not found in store '{store_name}'",
file=sys.stderr,
)
return 1
@@ -812,7 +812,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
h, item_store = _extract_hash_and_store(item)
if item_store and store_name and str(item_store) != str(store_name):
log(
f"Cross-store relationship blocked: item store '{item_store}' != '{store_name}'",
f"Cross-instance relationship blocked: item store '{item_store}' != '{store_name}'",
file=sys.stderr,
)
return 1
@@ -820,7 +820,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
continue
if not _hydrus_hash_exists(hydrus_client, h):
log(
f"Cross-store relationship blocked: hash not found in store '{store_name}'",
f"Cross-instance relationship blocked: hash not found in store '{store_name}'",
file=sys.stderr,
)
return 1