primus.cli.shared.CommandProgress module

class primus.cli.shared.CommandProgress.CommandProgress

Bases: object

Progress tracking scoped to one command execution context.

A worker can process more than one command at a time. Progress state and callbacks therefore live in ContextVar bindings instead of process-wide class attributes, so one command can never publish updates through another command’s lifecycle callback.

classmethod bind_update_callback(callback)

Bind fresh progress state and a callback for one command execution.

classmethod get_current_state() → ProgressState | None

Get the current progress state if any.

classmethod set_update_callback(callback)

Set the callback function that will be called when progress is updated.

classmethod track(total: int, status: str)

Context manager for tracking progress of an operation. Safe to use even when no callback is set.

classmethod update(current: int, total: int, status: str = None)

Update the progress state and notify the callback if set. Safe to call even when no callback is set.

class primus.cli.shared.CommandProgress.ProgressState(current: int, total: int, status: str, start_time: float)

Bases: object

__init__(current: int, total: int, status: str, start_time: float) → None
current: int
property elapsed_time: str
property estimated_remaining: str | None
start_time: float
status: str
total: int