This commit is contained in:
nose
2025-12-16 01:45:01 -08:00
parent a03eb0d1be
commit 9873280f0e
36 changed files with 4911 additions and 1225 deletions

View File

@@ -80,6 +80,7 @@ class PipeObject:
"""
try:
from SYS.logger import is_debug_enabled, debug
import shutil
if not is_debug_enabled():
return
@@ -87,24 +88,20 @@ class PipeObject:
return
# Prepare display values
hash_display = self.hash or "N/A"
store_display = self.store or "N/A"
title_display = self.title or "N/A"
hash_display = str(self.hash or "N/A")
store_display = str(self.store or "N/A")
title_display = str(self.title or "N/A")
tag_display = ", ".join(self.tag[:3]) if self.tag else "[]"
if len(self.tag) > 3:
tag_display += f" (+{len(self.tag) - 3} more)"
file_path_display = self.path or "N/A"
if file_path_display != "N/A" and len(file_path_display) > 50:
file_path_display = "..." + file_path_display[-47:]
file_path_display = str(self.path or "N/A")
url_display: Any = self.url or "N/A"
if isinstance(url_display, (list, tuple, set)):
parts = [str(x) for x in url_display if x]
url_display = ", ".join(parts) if parts else "N/A"
elif url_display != "N/A":
else:
url_display = str(url_display)
if url_display != "N/A" and len(url_display) > 48:
url_display = url_display[:45] + "..."
relationships_display = "N/A"
if self.relationships:
@@ -117,24 +114,55 @@ class PipeObject:
relationships_display = ", ".join(rel_parts)
warnings_display = f"{len(self.warnings)} warning(s)" if self.warnings else "none"
def _fit(text: str, max_len: int) -> str:
if max_len <= 0:
return ""
if len(text) <= max_len:
return text
if max_len <= 3:
return text[:max_len]
return text[: max_len - 3] + "..."
# Compute box width from terminal size, but never allow overflow.
try:
term_cols = int(getattr(shutil.get_terminal_size((120, 20)), "columns", 120))
except Exception:
term_cols = 120
box_inner_max = max(60, term_cols - 3) # line length = box_inner + 3
rows = [
("Hash", hash_display),
("Store", store_display),
("Title", title_display),
("Tag", tag_display),
("URL", str(url_display)),
("File Path", file_path_display),
("Relationships", relationships_display),
("Warnings", warnings_display),
]
label_width = max(len(k) for k, _ in rows)
# Estimate a good inner width from current content, capped to terminal.
base_contents = [f"{k:<{label_width}} : {v}" for k, v in rows]
desired_inner = max([len("PipeObject Debug Info"), *[len(x) for x in base_contents], 60])
box_inner = min(desired_inner, box_inner_max)
def _line(content: str) -> str:
return f"{_fit(content, box_inner):<{box_inner}}"
# Print table
debug("─────────────────────────────────────────────────────────────")
debug("PipeObject Debug Info")
debug("─────────────────────────────────────────────────────────────")
debug(f"│ Hash : {hash_display:<48}")
debug(f"│ Store : {store_display:<48}")
debug(f"│ Title : {title_display:<48}")
debug(f"│ Tag : {tag_display:<48}")
debug(f"│ URL : {url_display:<48}")
debug(f"│ File Path : {file_path_display:<48}")
debug(f"│ Relationships: {relationships_display:<47}")
debug(f"│ Warnings : {warnings_display:<48}")
debug("" + ("" * (box_inner + 1)) + "")
debug(_line("PipeObject Debug Info"))
debug("" + ("" * (box_inner + 1)) + "")
for key, val in rows:
content = f"{key:<{label_width}} : {val}"
debug(_line(content))
# Show extra keys as individual rows
if self.extra:
debug("─────────────────────────────────────────────────────────────")
debug("Extra Fields:")
debug("" + ("" * (box_inner + 1)) + "")
debug(_line("Extra Fields:"))
for key, val in self.extra.items():
# Format value for display
if isinstance(val, (list, set)):
@@ -148,14 +176,16 @@ class PipeObject:
val_display = val_str if len(val_str) <= 40 else val_str[:37] + "..."
# Truncate key if needed
key_display = key if len(key) <= 15 else key[:12] + "..."
debug(f"{key_display:<15}: {val_display:<42}")
key_display = str(key)
key_display = key_display if len(key_display) <= 15 else key_display[:12] + "..."
content = f" {key_display:<15}: {val_display}"
debug(_line(content))
# If we have structured provider metadata, expand it for debugging.
full_md = self.extra.get("full_metadata")
if isinstance(full_md, dict) and full_md:
debug("─────────────────────────────────────────────────────────────")
debug("full_metadata:")
debug("" + ("" * (box_inner + 1)) + "")
debug(_line("full_metadata:"))
for md_key in sorted(full_md.keys(), key=lambda x: str(x)):
md_val = full_md.get(md_key)
if isinstance(md_val, (str, int, float)) or md_val is None or isinstance(md_val, bool):
@@ -176,9 +206,8 @@ class PipeObject:
md_key_display = str(md_key)
md_key_display = md_key_display if len(md_key_display) <= 15 else md_key_display[:12] + "..."
if len(md_display) > 42:
md_display = md_display[:39] + "..."
debug(f"{md_key_display:<15}: {md_display:<42}")
content = f" {md_key_display:<15}: {md_display}"
debug(_line(content))
if self.action:
debug("├─────────────────────────────────────────────────────────────┤")
@@ -443,11 +472,6 @@ def _sanitise_for_json(value: Any, *, max_depth: int = 8, _seen: Optional[set[in
return repr(value)
# ============================================================================
# PROGRESS BAR CLASS
# ============================================================================
class ProgressBar:
"""Formats download progress with visual bar, speed, ETA, and file size."""