refactor(download): remove ProviderCore/download.py, move sanitize_filename to SYS.utils, replace callers to use API.HTTP.HTTPClient
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, Iterable, Optional, Sequence
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from typing import Any, Dict, Iterable, Sequence
|
||||
|
||||
from . import _shared as sh
|
||||
from SYS.logger import log, debug
|
||||
@@ -68,47 +68,34 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
return 1
|
||||
items = inputs
|
||||
|
||||
# Build rows
|
||||
try:
|
||||
rows = list(provider.adapter(items))
|
||||
table = provider.build_table(items)
|
||||
except Exception as exc:
|
||||
log(f"Provider adapter failed: {exc}", file=sys.stderr)
|
||||
log(f"Provider '{provider.name}' failed: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
cols = provider.get_columns(rows)
|
||||
|
||||
# Emit rows for downstream pipeline consumption (pipable behavior).
|
||||
try:
|
||||
for r in rows:
|
||||
for item in provider.serialize_rows(table.rows):
|
||||
try:
|
||||
item = {
|
||||
"title": getattr(r, "title", None) or None,
|
||||
"path": getattr(r, "path", None) or None,
|
||||
"ext": getattr(r, "ext", None) or None,
|
||||
"size_bytes": getattr(r, "size_bytes", None) or None,
|
||||
"metadata": getattr(r, "metadata", None) or {},
|
||||
"source": getattr(r, "source", None) or provider.name,
|
||||
"_selection_args": provider.selection_args(r),
|
||||
}
|
||||
ctx.emit(item)
|
||||
except Exception:
|
||||
# Best-effort: continue emitting other rows
|
||||
continue
|
||||
except Exception:
|
||||
# Non-fatal: continue to rendering even if emission fails
|
||||
# Non-fatal: rendering still happens
|
||||
pass
|
||||
|
||||
# Render using RichRenderer
|
||||
try:
|
||||
table = RichRenderer().render(rows, cols, provider.metadata)
|
||||
renderable = RichRenderer().render(table.rows, table.columns, table.meta)
|
||||
try:
|
||||
from rich.console import Console
|
||||
|
||||
Console().print(table)
|
||||
Console().print(renderable)
|
||||
except Exception:
|
||||
# Fallback to simple printing
|
||||
for r in rows:
|
||||
print(" ".join(str((c.extractor(r) or "")) for c in cols))
|
||||
for r in table.rows:
|
||||
print(" ".join(str((c.extractor(r) or "")) for c in table.columns))
|
||||
except Exception as exc:
|
||||
log(f"Rendering failed: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
@@ -123,11 +110,11 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
log("Invalid -select value; must be an integer", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
if select_idx < 0 or select_idx >= len(rows):
|
||||
if select_idx < 0 or select_idx >= len(table.rows):
|
||||
log("-select out of range", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
selected = rows[select_idx]
|
||||
selected = table.rows[select_idx]
|
||||
sel_args = provider.selection_args(selected)
|
||||
|
||||
if not run_cmd:
|
||||
|
||||
Reference in New Issue
Block a user