f
This commit is contained in:
@@ -33,12 +33,15 @@ except ImportError:
|
||||
TEXTUAL_AVAILABLE = False
|
||||
|
||||
|
||||
# Import ResultModel from the API for unification
|
||||
try:
|
||||
from SYS.result_table_api import ResultModel
|
||||
except ImportError:
|
||||
# Fallback if not available yet in directory structure (unlikely)
|
||||
ResultModel = None
|
||||
# Import ResultModel from the API for typing; avoid runtime redefinition issues
|
||||
from typing import TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
from SYS.result_table_api import ResultModel # type: ignore
|
||||
else:
|
||||
ResultModel = None # type: ignore[assignment]
|
||||
|
||||
# Reuse the existing format_bytes helper under a clearer alias
|
||||
from SYS.utils import format_bytes as format_mb
|
||||
|
||||
|
||||
def _sanitize_cell_text(value: Any) -> str:
|
||||
@@ -158,6 +161,8 @@ def extract_hash_value(item: Any) -> str:
|
||||
|
||||
def extract_title_value(item: Any) -> str:
|
||||
data = _as_dict(item) or {}
|
||||
if not isinstance(data, dict):
|
||||
data = {}
|
||||
title = _get_first_dict_value(data, ["title", "name", "filename"])
|
||||
if not title:
|
||||
title = _get_first_dict_value(
|
||||
@@ -171,9 +176,11 @@ def extract_title_value(item: Any) -> str:
|
||||
|
||||
def extract_ext_value(item: Any) -> str:
|
||||
data = _as_dict(item) or {}
|
||||
if not isinstance(data, dict):
|
||||
data = {}
|
||||
|
||||
meta = data.get("metadata") if isinstance(data.get("metadata"),
|
||||
dict) else {}
|
||||
_md = data.get("metadata")
|
||||
meta: Dict[str, Any] = _md if isinstance(_md, dict) else {}
|
||||
raw_path = data.get("path") or data.get("target") or data.get(
|
||||
"filename"
|
||||
) or data.get("title")
|
||||
@@ -206,8 +213,10 @@ def extract_ext_value(item: Any) -> str:
|
||||
|
||||
def extract_size_bytes_value(item: Any) -> Optional[int]:
|
||||
data = _as_dict(item) or {}
|
||||
meta = data.get("metadata") if isinstance(data.get("metadata"),
|
||||
dict) else {}
|
||||
if not isinstance(data, dict):
|
||||
data = {}
|
||||
_md = data.get("metadata")
|
||||
meta: Dict[str, Any] = _md if isinstance(_md, dict) else {}
|
||||
|
||||
size_val = _get_first_dict_value(
|
||||
data,
|
||||
@@ -749,7 +758,7 @@ class Table:
|
||||
row.payload = result
|
||||
|
||||
# Handle ResultModel from the new strict API (SYS/result_table_api.py)
|
||||
if ResultModel and isinstance(result, ResultModel):
|
||||
if ResultModel is not None and isinstance(result, ResultModel):
|
||||
self._add_result_model(row, result)
|
||||
# Handle TagItem from get_tag.py (tag display with index)
|
||||
elif hasattr(result, "__class__") and result.__class__.__name__ == "TagItem":
|
||||
@@ -1573,7 +1582,7 @@ class Table:
|
||||
return None
|
||||
|
||||
# Remaining parts are cmdlet arguments
|
||||
cmdlet_args = {}
|
||||
cmdlet_args: dict[str, Any] = {}
|
||||
i = 1
|
||||
while i < len(parts):
|
||||
part = parts[i]
|
||||
@@ -1906,7 +1915,7 @@ def extract_item_metadata(item: Any) -> Dict[str, Any]:
|
||||
out = {}
|
||||
|
||||
# Handle ResultModel specifically for better detail display
|
||||
if ResultModel and isinstance(item, ResultModel):
|
||||
if ResultModel is not None and isinstance(item, ResultModel):
|
||||
if item.title: out["Title"] = item.title
|
||||
if item.path: out["Path"] = item.path
|
||||
if item.ext: out["Ext"] = item.ext
|
||||
@@ -1964,34 +1973,30 @@ def extract_item_metadata(item: Any) -> Dict[str, Any]:
|
||||
if e: out["Ext"] = e
|
||||
|
||||
size = extract_size_bytes_value(item)
|
||||
if size:
|
||||
out["Size"] = size
|
||||
if size is not None:
|
||||
out["Size"] = format_mb(size)
|
||||
else:
|
||||
s = data.get("size") or data.get("size_bytes")
|
||||
if s: out["Size"] = s
|
||||
|
||||
if s is not None:
|
||||
out["Size"] = str(s)
|
||||
|
||||
# Duration
|
||||
dur = _get_first_dict_value(data, ["duration_seconds", "duration"])
|
||||
if dur:
|
||||
out["Duration"] = _format_duration_hms(dur)
|
||||
|
||||
|
||||
# URL
|
||||
url = _get_first_dict_value(data, ["url", "URL"])
|
||||
if url:
|
||||
out["Url"] = url
|
||||
else:
|
||||
out["Url"] = None # Explicitly None for <null> display
|
||||
out["Url"] = str(url) if url else ""
|
||||
|
||||
# Relationships
|
||||
rels = _get_first_dict_value(data, ["relationships", "rel"])
|
||||
if rels:
|
||||
out["Relations"] = rels
|
||||
else:
|
||||
out["Relations"] = None
|
||||
out["Relations"] = str(rels) if rels else ""
|
||||
|
||||
# Tags Summary
|
||||
tags = _get_first_dict_value(data, ["tags", "tag"])
|
||||
if tags: out["Tags"] = tags
|
||||
if tags:
|
||||
out["Tags"] = ", ".join([str(t) for t in (tags if isinstance(tags, (list, tuple)) else [tags])])
|
||||
|
||||
return out
|
||||
|
||||
|
||||
Reference in New Issue
Block a user