j
This commit is contained in:
12
CLI.py
12
CLI.py
@@ -1233,6 +1233,10 @@ class CmdletExecutor:
|
|||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
progress_ui.complete_all_pipes()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
try:
|
try:
|
||||||
progress_ui.stop()
|
progress_ui.stop()
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -1280,6 +1284,10 @@ class CmdletExecutor:
|
|||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
progress_ui.complete_all_pipes()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
try:
|
try:
|
||||||
progress_ui.stop()
|
progress_ui.stop()
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -1312,6 +1320,10 @@ class CmdletExecutor:
|
|||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
progress_ui.complete_all_pipes()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
try:
|
try:
|
||||||
progress_ui.stop()
|
progress_ui.stop()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
@@ -1376,16 +1376,18 @@ class PipelineLiveProgress:
|
|||||||
total = self._pipe_totals[pipe_index]
|
total = self._pipe_totals[pipe_index]
|
||||||
active = self._subtask_active_index[pipe_index]
|
active = self._subtask_active_index[pipe_index]
|
||||||
|
|
||||||
# If a stage emits more than expected, extend totals dynamically.
|
# If a stage emits more than expected, or if we have no subtasks yet, extend dynamically.
|
||||||
if done >= total:
|
if (done >= total) or (not self._subtask_ids[pipe_index]):
|
||||||
total = done + 1
|
if done >= total:
|
||||||
self._pipe_totals[pipe_index] = total
|
total = done + 1
|
||||||
pipe_task = self._pipe_tasks[pipe_index]
|
self._pipe_totals[pipe_index] = total
|
||||||
pipe_progress.update(pipe_task, total=total)
|
pipe_task = self._pipe_tasks[pipe_index]
|
||||||
|
pipe_progress.update(pipe_task, total=total)
|
||||||
|
|
||||||
# Add a placeholder subtask.
|
# Add a placeholder/next subtask.
|
||||||
|
label = _pipeline_progress_item_label(emitted)
|
||||||
sub_id = subtasks.add_task(
|
sub_id = subtasks.add_task(
|
||||||
f"{self._pipe_labels[pipe_index]}: {_pipeline_progress_item_label(emitted)}"
|
f"{self._pipe_labels[pipe_index]}: {label}"
|
||||||
)
|
)
|
||||||
subtasks.stop_task(sub_id)
|
subtasks.stop_task(sub_id)
|
||||||
subtasks.update(sub_id, visible=False)
|
subtasks.update(sub_id, visible=False)
|
||||||
@@ -1457,6 +1459,9 @@ class PipelineLiveProgress:
|
|||||||
assert overall is not None
|
assert overall is not None
|
||||||
|
|
||||||
total = self._pipe_totals[pipe_index]
|
total = self._pipe_totals[pipe_index]
|
||||||
|
if total < 1:
|
||||||
|
total = 1
|
||||||
|
self._pipe_totals[pipe_index] = total
|
||||||
done = self._pipe_done[pipe_index]
|
done = self._pipe_done[pipe_index]
|
||||||
|
|
||||||
# Ensure the pipe bar finishes even if cmdlet didn’t emit per item.
|
# Ensure the pipe bar finishes even if cmdlet didn’t emit per item.
|
||||||
@@ -1499,6 +1504,16 @@ class PipelineLiveProgress:
|
|||||||
|
|
||||||
self._update_overall()
|
self._update_overall()
|
||||||
|
|
||||||
|
def complete_all_pipes(self) -> None:
|
||||||
|
"""Mark every configured pipe as finished so UI bars reach 100%."""
|
||||||
|
if not self._enabled:
|
||||||
|
return
|
||||||
|
for idx in range(len(self._pipe_labels)):
|
||||||
|
try:
|
||||||
|
self.finish_pipe(idx)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class PipelineStageContext:
|
class PipelineStageContext:
|
||||||
"""Context information for the current pipeline stage."""
|
"""Context information for the current pipeline stage."""
|
||||||
|
|||||||
@@ -2831,6 +2831,8 @@ class PipelineExecutor:
|
|||||||
total_stages=len(stages),
|
total_stages=len(stages),
|
||||||
pipe_index=pipe_idx,
|
pipe_index=pipe_idx,
|
||||||
worker_id=session.worker_id if session else None,
|
worker_id=session.worker_id if session else None,
|
||||||
|
on_emit=(lambda x: progress_ui.on_emit(pipe_idx, x))
|
||||||
|
if progress_ui is not None and pipe_idx is not None else None,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set context for the current run
|
# Set context for the current run
|
||||||
@@ -2839,6 +2841,12 @@ class PipelineExecutor:
|
|||||||
ctx.set_current_stage_text(" ".join(stage_tokens))
|
ctx.set_current_stage_text(" ".join(stage_tokens))
|
||||||
ctx.clear_emits()
|
ctx.clear_emits()
|
||||||
|
|
||||||
|
if progress_ui is not None and pipe_idx is not None:
|
||||||
|
# Start the pipe task in the UI. For most cmdlets we assume 1 item
|
||||||
|
# initially; cmdlets that process multiple items (like search)
|
||||||
|
# should call begin_pipe themselves with the actual count.
|
||||||
|
progress_ui.begin_pipe(pipe_idx, total_items=1)
|
||||||
|
|
||||||
# RUN THE CMDLET
|
# RUN THE CMDLET
|
||||||
cmd_fn(piped_result, stage_args, config)
|
cmd_fn(piped_result, stage_args, config)
|
||||||
|
|
||||||
@@ -2848,10 +2856,9 @@ class PipelineExecutor:
|
|||||||
piped_result = stage_emits if len(stage_emits) > 1 else stage_emits[0]
|
piped_result = stage_emits if len(stage_emits) > 1 else stage_emits[0]
|
||||||
else:
|
else:
|
||||||
piped_result = None
|
piped_result = None
|
||||||
|
|
||||||
if progress_ui is not None and pipe_idx is not None:
|
|
||||||
progress_ui.complete_stage(pipe_idx)
|
|
||||||
finally:
|
finally:
|
||||||
|
if progress_ui is not None and pipe_idx is not None:
|
||||||
|
progress_ui.finish_pipe(pipe_idx)
|
||||||
if session:
|
if session:
|
||||||
try:
|
try:
|
||||||
session.close()
|
session.close()
|
||||||
@@ -2870,6 +2877,10 @@ class PipelineExecutor:
|
|||||||
finally:
|
finally:
|
||||||
# Stop Live progress and clear pipeline-level live progress
|
# Stop Live progress and clear pipeline-level live progress
|
||||||
if progress_ui is not None:
|
if progress_ui is not None:
|
||||||
|
try:
|
||||||
|
progress_ui.complete_all_pipes()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
try:
|
try:
|
||||||
progress_ui.stop()
|
progress_ui.stop()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ class Get_Metadata(Cmdlet):
|
|||||||
url: list[str],
|
url: list[str],
|
||||||
hash_value: Optional[str],
|
hash_value: Optional[str],
|
||||||
pages: Optional[int] = None,
|
pages: Optional[int] = None,
|
||||||
|
tag: Optional[List[str]] = None,
|
||||||
) -> Dict[str,
|
) -> Dict[str,
|
||||||
Any]:
|
Any]:
|
||||||
"""Build a table row dict with metadata fields."""
|
"""Build a table row dict with metadata fields."""
|
||||||
@@ -142,6 +143,7 @@ class Get_Metadata(Cmdlet):
|
|||||||
"imported": imported_label,
|
"imported": imported_label,
|
||||||
"hash": hash_value,
|
"hash": hash_value,
|
||||||
"url": url,
|
"url": url,
|
||||||
|
"tag": tag or [],
|
||||||
"columns": columns,
|
"columns": columns,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,16 +222,30 @@ class Get_Metadata(Cmdlet):
|
|||||||
|
|
||||||
# Extract title from tags if available
|
# Extract title from tags if available
|
||||||
title = get_field(result, "title") or file_hash[:16]
|
title = get_field(result, "title") or file_hash[:16]
|
||||||
if not get_field(result, "title"):
|
|
||||||
# Try to get title from tags
|
# Get tags from input result
|
||||||
try:
|
item_tags = get_field(result, "tag") or get_field(result, "tags") or []
|
||||||
tags, _ = backend.get_tag(file_hash)
|
if not isinstance(item_tags, list):
|
||||||
for tag in tags:
|
item_tags = [str(item_tags)]
|
||||||
if tag.lower().startswith("title:"):
|
else:
|
||||||
title = tag.split(":", 1)[1]
|
item_tags = [str(t) for t in item_tags]
|
||||||
break
|
|
||||||
except Exception:
|
# Try to enrich tags and title from backend
|
||||||
pass
|
try:
|
||||||
|
backend_tags, _ = backend.get_tag(file_hash)
|
||||||
|
if backend_tags:
|
||||||
|
for t in backend_tags:
|
||||||
|
ts = str(t)
|
||||||
|
if ts not in item_tags:
|
||||||
|
item_tags.append(ts)
|
||||||
|
|
||||||
|
# Also check for title tag if we don't have a title yet
|
||||||
|
if not get_field(result, "title") and ts.lower().startswith("title:"):
|
||||||
|
parts = ts.split(":", 1)
|
||||||
|
if len(parts) > 1:
|
||||||
|
title = parts[1].strip()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
# Extract metadata fields
|
# Extract metadata fields
|
||||||
mime_type = metadata.get("mime") or metadata.get("ext", "")
|
mime_type = metadata.get("mime") or metadata.get("ext", "")
|
||||||
@@ -292,6 +308,7 @@ class Get_Metadata(Cmdlet):
|
|||||||
url=url,
|
url=url,
|
||||||
hash_value=file_hash,
|
hash_value=file_hash,
|
||||||
pages=pages,
|
pages=pages,
|
||||||
|
tag=item_tags,
|
||||||
)
|
)
|
||||||
|
|
||||||
table_title = f"get-metadata: {title}" if title else "get-metadata"
|
table_title = f"get-metadata: {title}" if title else "get-metadata"
|
||||||
|
|||||||
@@ -648,6 +648,34 @@ class Get_Url(Cmdlet):
|
|||||||
# Prepare metadata for the detail view
|
# Prepare metadata for the detail view
|
||||||
metadata = extract_item_metadata(result)
|
metadata = extract_item_metadata(result)
|
||||||
|
|
||||||
|
# Enrich the metadata with tags if missing
|
||||||
|
if not metadata.get("Tags"):
|
||||||
|
try:
|
||||||
|
from cmdlet._shared import get_field
|
||||||
|
item_tags = get_field(result, "tag") or get_field(result, "tags") or []
|
||||||
|
row_tags = []
|
||||||
|
if isinstance(item_tags, list):
|
||||||
|
row_tags.extend([str(t) for t in item_tags])
|
||||||
|
elif isinstance(item_tags, str):
|
||||||
|
row_tags.append(item_tags)
|
||||||
|
|
||||||
|
# Also collect from backend
|
||||||
|
if file_hash and store_name:
|
||||||
|
try:
|
||||||
|
# Re-use existing backend variable
|
||||||
|
if backend and hasattr(backend, "get_tag"):
|
||||||
|
b_tags, _ = backend.get_tag(file_hash)
|
||||||
|
if b_tags:
|
||||||
|
row_tags.extend([str(t) for t in b_tags])
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if row_tags:
|
||||||
|
row_tags = sorted(list(set(row_tags)))
|
||||||
|
metadata["Tags"] = ", ".join(row_tags)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
if file_hash:
|
if file_hash:
|
||||||
metadata["Hash"] = file_hash
|
metadata["Hash"] = file_hash
|
||||||
if store_name:
|
if store_name:
|
||||||
|
|||||||
Reference in New Issue
Block a user