updated panel display
This commit is contained in:
+68
-32
@@ -11,7 +11,7 @@ from urllib.parse import urlparse
|
||||
|
||||
from SYS import models
|
||||
from SYS import pipeline as ctx
|
||||
from SYS.logger import log, debug, is_debug_enabled
|
||||
from SYS.logger import log, debug, debug_panel, is_debug_enabled
|
||||
from SYS.payload_builders import build_table_result_payload
|
||||
from SYS.pipeline_progress import PipelineProgress
|
||||
from SYS.result_publication import overlay_existing_result_table, publish_result_table
|
||||
@@ -247,11 +247,13 @@ class Add_File(Cmdlet):
|
||||
is None) or bool(getattr(stage_ctx,
|
||||
"is_last_stage",
|
||||
False))
|
||||
has_downstream_stage = bool(stage_ctx is not None and not is_last_stage)
|
||||
|
||||
# Directory-mode selector:
|
||||
# - First pass: `add-file -store X -path <DIR>` should ONLY show a selectable table.
|
||||
# - Second pass (triggered by @ selection expansion): re-run add-file with `-path file1,file2,...`
|
||||
# and actually ingest/copy.
|
||||
# - Terminal use: `add-file -store X -path <DIR>` shows a selectable table.
|
||||
# - Pipelined use: `add-file -store X -path <DIR> | ...` processes the full batch
|
||||
# immediately so downstream stages receive the uploaded items.
|
||||
# - Selection replay: `@N` re-runs add-file with `-path file1,file2,...`.
|
||||
dir_scan_mode = False
|
||||
dir_scan_results: Optional[List[Dict[str, Any]]] = None
|
||||
explicit_path_list_results: Optional[List[Dict[str, Any]]] = None
|
||||
@@ -350,6 +352,19 @@ class Add_File(Cmdlet):
|
||||
|
||||
total_items = len(items_to_process) if isinstance(items_to_process, list) else 0
|
||||
processed_items = 0
|
||||
try:
|
||||
ui, _ = progress.ui_and_pipe_index()
|
||||
if ui is not None and total_items:
|
||||
preview_items = (
|
||||
list(items_to_process)
|
||||
if isinstance(items_to_process, list) else [items_to_process]
|
||||
)
|
||||
progress.begin_pipe(
|
||||
total_items=total_items,
|
||||
items_preview=preview_items,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
if total_items:
|
||||
progress.set_percent(0)
|
||||
@@ -369,12 +384,20 @@ class Add_File(Cmdlet):
|
||||
except Exception:
|
||||
use_steps = False
|
||||
|
||||
debug(f"[add-file] INPUT result type={type(result).__name__}")
|
||||
if isinstance(result, list):
|
||||
debug(f"[add-file] INPUT result is list with {len(result)} items")
|
||||
debug(
|
||||
f"[add-file] PARSED args: location={location}, provider={provider_name}, delete={delete_after}"
|
||||
)
|
||||
try:
|
||||
debug_panel(
|
||||
"add-file",
|
||||
[
|
||||
("result_type", type(result).__name__),
|
||||
("items", total_items),
|
||||
("location", location),
|
||||
("provider", provider_name),
|
||||
("delete", delete_after),
|
||||
],
|
||||
border_style="cyan",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# add-file is ingestion-only: it does not download URLs here.
|
||||
|
||||
@@ -393,22 +416,22 @@ class Add_File(Cmdlet):
|
||||
except Exception:
|
||||
po = None
|
||||
if po is None:
|
||||
debug(f"[add-file] PIPE item[{idx}] preview (non-PipeObject)")
|
||||
continue
|
||||
debug(f"[add-file] PIPE item[{idx}] PipeObject preview")
|
||||
try:
|
||||
safe_po = _sanitize_pipe_object_for_debug(po)
|
||||
safe_po.debug_table()
|
||||
except Exception:
|
||||
pass
|
||||
if len(preview_items) > max_preview:
|
||||
debug(
|
||||
f"[add-file] Skipping {len(preview_items) - max_preview} additional piped item(s) in debug preview"
|
||||
)
|
||||
|
||||
# If this invocation was directory selector mode, show a selectable table and stop.
|
||||
should_present_directory_selector = bool(dir_scan_mode and not has_downstream_stage)
|
||||
if dir_scan_mode and has_downstream_stage:
|
||||
debug(
|
||||
"[add-file] Continuing with directory batch ingest because downstream stages exist"
|
||||
)
|
||||
|
||||
# If this invocation was terminal directory selector mode, show a selectable table and stop.
|
||||
# The user then runs @N (optionally piped), which replays add-file with selected paths.
|
||||
if dir_scan_mode:
|
||||
if should_present_directory_selector:
|
||||
try:
|
||||
from SYS.result_table import Table
|
||||
from pathlib import Path as _Path
|
||||
@@ -563,13 +586,19 @@ class Add_File(Cmdlet):
|
||||
media_path, file_hash, temp_dir_to_cleanup = Add_File._download_provider_source(
|
||||
pipe_obj, config, storage_registry
|
||||
)
|
||||
if media_path:
|
||||
debug(
|
||||
f"[add-file] Provider source downloaded: {media_path}"
|
||||
if media_path:
|
||||
try:
|
||||
debug_panel(
|
||||
f"add-file source {idx}/{max(1, total_items)}",
|
||||
[
|
||||
("path", media_path),
|
||||
("hash", file_hash or "N/A"),
|
||||
("provider", provider_name or "local"),
|
||||
],
|
||||
border_style="green",
|
||||
)
|
||||
debug(
|
||||
f"[add-file] RESOLVED source: path={media_path}, hash={file_hash if file_hash else 'N/A'}..."
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
if not media_path:
|
||||
failures += 1
|
||||
continue
|
||||
@@ -1616,6 +1645,7 @@ class Add_File(Cmdlet):
|
||||
) -> None:
|
||||
pipe_obj.hash = hash_value
|
||||
pipe_obj.store = store
|
||||
pipe_obj.is_temp = False
|
||||
pipe_obj.path = path
|
||||
pipe_obj.tag = tag
|
||||
if title:
|
||||
@@ -2211,11 +2241,20 @@ class Add_File(Cmdlet):
|
||||
upload_tags = tags
|
||||
if prefer_defer_tags and upload_tags:
|
||||
upload_tags = []
|
||||
debug(f"[add-file] Deferring tag application for {backend_name} (backend preference)")
|
||||
|
||||
debug(
|
||||
f"[add-file] Storing into backend '{backend_name}' path='{media_path}' title='{title}' hash='{f_hash[:12] if f_hash else 'N/A'}'"
|
||||
)
|
||||
try:
|
||||
debug_panel(
|
||||
"add-file store",
|
||||
[
|
||||
("backend", backend_name),
|
||||
("path", media_path),
|
||||
("title", title),
|
||||
("hash_hint", f_hash[:12] if f_hash else "N/A"),
|
||||
("defer_tags", bool(prefer_defer_tags and tags)),
|
||||
],
|
||||
border_style="yellow",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Call backend's add_file with full metadata
|
||||
# Backend returns hash as identifier. If we already know the hash from _resolve_source
|
||||
@@ -2227,9 +2266,6 @@ class Add_File(Cmdlet):
|
||||
url=[] if (defer_url_association and url) else url,
|
||||
file_hash=f_hash,
|
||||
)
|
||||
debug(
|
||||
f"[add-file] backend.add_file returned identifier {file_identifier} (len={len(str(file_identifier)) if file_identifier is not None else 'None'})"
|
||||
)
|
||||
##log(f"✓ File added to '{backend_name}': {file_identifier}", file=sys.stderr)
|
||||
|
||||
stored_path: Optional[str] = None
|
||||
|
||||
Reference in New Issue
Block a user