This commit is contained in:
2026-01-18 03:23:01 -08:00
parent aa675a625a
commit 66132811e0
8 changed files with 50 additions and 50 deletions

View File

@@ -69,7 +69,7 @@ CMDLET = Cmdlet(
)
def _normalise_hash_hex(value: Optional[str]) -> Optional[str]:
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
@@ -99,7 +99,7 @@ def _extract_relationships_from_tag(tag_value: str) -> Dict[str, list[str]]:
if matches:
for rel_type, hash_value in matches:
normalized = _normalise_hash_hex(hash_value)
normalized = _normalize_hash_hex(hash_value)
if normalized:
if rel_type not in result:
result[rel_type] = []
@@ -111,13 +111,13 @@ def _extract_relationships_from_tag(tag_value: str) -> Dict[str, list[str]]:
hashes = [h.strip().lower() for h in hashes if isinstance(h, str)]
if not hashes:
return result
king = _normalise_hash_hex(hashes[0])
king = _normalize_hash_hex(hashes[0])
if not king:
return result
result["king"] = [king]
alts: list[str] = []
for h in hashes[1:]:
normalized = _normalise_hash_hex(h)
normalized = _normalize_hash_hex(h)
if normalized and normalized != king:
alts.append(normalized)
if alts:
@@ -155,13 +155,13 @@ def _apply_relationships_from_tags(
king = (rels.get("king") or [None])[0]
if not king:
continue
king_norm = _normalise_hash_hex(king)
king_norm = _normalize_hash_hex(king)
if not king_norm:
continue
for rel_type in ("alt", "related"):
for other in rels.get(rel_type, []) or []:
other_norm = _normalise_hash_hex(other)
other_norm = _normalize_hash_hex(other)
if not other_norm or other_norm == king_norm:
continue
key = (other_norm, king_norm, rel_type)
@@ -184,7 +184,7 @@ def _apply_relationships_from_tags(
king = (rels.get("king") or [None])[0]
if not king:
continue
king_norm = _normalise_hash_hex(king)
king_norm = _normalize_hash_hex(king)
if not king_norm:
continue
@@ -196,7 +196,7 @@ def _apply_relationships_from_tags(
)
for alt in alt_hashes:
alt_norm = _normalise_hash_hex(alt)
alt_norm = _normalize_hash_hex(alt)
if not alt_norm or alt_norm == king_norm:
continue
if (alt_norm, king_norm) in processed_pairs:
@@ -286,7 +286,7 @@ def _extract_hash_and_store(item: Any) -> tuple[Optional[str], Optional[str]]:
"file_hash")
s = get_field(item, "store")
hash_norm = _normalise_hash_hex(str(h) if h is not None else None)
hash_norm = _normalize_hash_hex(str(h) if h is not None else None)
store_norm: Optional[str]
if s is None:
@@ -330,7 +330,7 @@ def _resolve_king_reference(king_arg: str) -> Optional[str]:
return None
# Check if it's already a valid hash
normalized = _normalise_hash_hex(king_arg)
normalized = _normalize_hash_hex(king_arg)
if normalized:
return normalized
@@ -356,7 +356,7 @@ def _resolve_king_reference(king_arg: str) -> Optional[str]:
)
if item_hash:
normalized = _normalise_hash_hex(str(item_hash))
normalized = _normalize_hash_hex(str(item_hash))
if normalized:
return normalized
@@ -500,7 +500,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
parts = [
p.strip() for p in alt_text.replace(";", ",").split(",") if p.strip()
]
hashes = [h for h in (_normalise_hash_hex(p) for p in parts) if h]
hashes = [h for h in (_normalize_hash_hex(p) for p in parts) if h]
if not hashes:
log(
"Invalid -alt value (expected @ selection or 64-hex sha256 hash list)",
@@ -898,7 +898,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
return 1
if king_hash:
normalized_king = _normalise_hash_hex(str(king_hash))
normalized_king = _normalize_hash_hex(str(king_hash))
if not normalized_king:
log(f"King hash invalid: {king_hash}", file=sys.stderr)
return 1
@@ -973,7 +973,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
# PIPELINE MODE with Hydrus: Track relationships using hash
if file_hash and hydrus_client:
file_hash = _normalise_hash_hex(
file_hash = _normalize_hash_hex(
str(file_hash) if file_hash is not None else None
)
if not file_hash:
@@ -1106,7 +1106,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
log("File hash not available (run add-file first)", file=sys.stderr)
return 1
file_hash = _normalise_hash_hex(file_hash)
file_hash = _normalize_hash_hex(file_hash)
if not file_hash:
log("Invalid file hash format", file=sys.stderr)
return 1