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

@@ -3,7 +3,11 @@ from __future__ import annotations
from typing import Any, Dict, Sequence, Optional
import sys
from SYS.detail_view_helpers import create_detail_view, prepare_detail_metadata
from SYS.logger import log
from SYS.result_table_helpers import add_row_columns
from SYS.selection_builder import build_hash_store_selection
from SYS.result_publication import publish_result_table
from SYS import pipeline as ctx
from API import HydrusNetwork as hydrus_wrapper
@@ -59,11 +63,12 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
continue
i += 1
override_hash: str | None = (
sh.parse_single_hash_query(override_query) if override_query else None
override_hash, query_valid = sh.require_single_hash_query(
override_query,
'get-relationship requires -query "hash:<sha256>"',
log_file=sys.stderr,
)
if override_query and not override_hash:
log('get-relationship requires -query "hash:<sha256>"', file=sys.stderr)
if not query_valid:
return 1
# Handle @N selection which creates a list
@@ -326,21 +331,19 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
log(f"Hydrus relationships fetch failed: {exc}", file=sys.stderr)
# Display results
from SYS.result_table import ItemDetailView, extract_item_metadata
# Prepare metadata for the detail view
metadata = extract_item_metadata(result)
if hash_hex:
metadata["Hash"] = hash_hex
# Overlays
if source_title and source_title != "Unknown":
metadata["Title"] = source_title
metadata = prepare_detail_metadata(
result,
title=(source_title if source_title and source_title != "Unknown" else None),
hash_value=hash_hex,
)
table = ItemDetailView("Relationships", item_metadata=metadata
).init_command("get-relationship",
[])
table = create_detail_view(
"Relationships",
metadata,
init_command=("get-relationship", []),
value_case=None,
perseverance=False,
)
# Sort by type then title
# Custom sort order: King first, then Derivative, then others
@@ -364,11 +367,14 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
pipeline_results = []
for i, item in enumerate(found_relationships):
row = table.add_row()
row.add_column("Type", item["type"].title())
row.add_column("Title", item["title"])
# row.add_column("Hash", item['hash'][:16] + "...") # User requested removal
row.add_column("Store", item["store"])
add_row_columns(
table,
[
("Type", item["type"].title()),
("Title", item["title"]),
("Store", item["store"]),
],
)
# Create result object for pipeline
res_obj = {
@@ -384,16 +390,15 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
pipeline_results.append(res_obj)
# Set selection args
table.set_row_selection_args(
i,
["-store",
str(item["store"]),
"-query",
f"hash:{item['hash']}"]
selection_args, _selection_action = build_hash_store_selection(
item["hash"],
item["store"],
)
if selection_args:
table.set_row_selection_args(i, selection_args)
# Ensure empty state is still navigable/visible
ctx.set_last_result_table_overlay(table, pipeline_results)
publish_result_table(ctx, table, pipeline_results, overlay=True)
from SYS.rich_display import stdout_console
stdout_console().print(table)