undr.display
#
Terminal progress bar.
Overview#
Classes#
Display collects update messages and shows progress in a terminal. |
|
Represents download or process progress. |
|
Measures speed with multiple samples and a sliding window. |
|
Keeps track of download and process progress for a dataset. |
|
Label and icon representing an action in a terminal. |
Functions#
Surrounds the message with ANSI escape characters for bold formatting. |
|
Surrounds the message with ANSI escape characters for dim formatting. |
|
Adds a red cross mark in front of the message. |
|
Adds a kangaroo icon in front of the message. |
|
Generates a progress bar compatible with terminals. |
|
Calculates the total speed for multiple datasets. |
Attributes#
Module Contents#
- undr.display.ANSI_COLORS_ENABLED#
- class undr.display.Display(statuses: list[Status], output_interval: float, download_speed_samples: int, process_speed_samples: int, download_tag: Tag, process_tag: Tag)#
Display collects update messages and shows progress in a terminal.
- Parameters:
statuses (list[Status]) – Initial statuses for all datasets.
output_interval (float) – Time between refreshes in seconds.
download_speed_samples (int) – Size of the sliding window for download speed calculations.
process_speed_samples (int) – Size of the sliding window for process speed calculations.
download_tag (Tag) – Label and icon for the download action.
process_tag (Tag) – Label and icon for the process action.
- __exit__(type: Type[BaseException] | None, value: BaseException | None, traceback: types.TracebackType | None)#
Enables the use of the “with” statement.
- Parameters:
type (Optional[Type[BaseException]]) – None if the context exits without an exception, and the raised exception’s class otherwise.
value (Optional[BaseException]) – None if the context exits without an exception, and the raised exception otherwise.
traceback (Optional[types.TracebackType]) – None if the context exits without an exception, and the raised exception’s traceback otherwise.
- close()#
Terminates the worker thread.
This function is called automatically if display is used as a context manager.
- messages(statuses: list[Status]) list[Status] #
Consumes messages until the queue is empty.
This function consumes messages until the queue is empty, not closed. More messages are likely to be queued after this function returns.
- Parameters:
statuses (list[Status]) – Current statuses, will be modified in-place. Use
copy.deepcopy()
to preserve the original list.- Raises:
RuntimeError – if a message in the queue is not
undr.decode.Progress
,undr.remote.Progress
,undr.json_index_tasks.IndexLoaded
orundr.json_index_tasks.DirectoryScanned
.- Returns:
Updated statuses.
- Return type:
- output(statuses: list[Status], average: bool, download_speed: float, process_speed: float)#
Called by the worker to generate the terminal text.
- push(message: Any)#
Processes update messages.
Ignores messages that are not
undr.decode.Progress
,undr.remote.Progress
,undr.json_index_tasks.IndexLoaded
orundr.json_index_tasks.DirectoryScanned
.- Parameters:
message (Any) – Message from a worker.
- target()#
Worker thread implementation.
- time_left(statuses: list[Status], download_speed: float, process_speed: float) float | None #
Estimates the time left to complete the download and process actions.
- Parameters:
- Returns:
Estimated time left in second or None if at least one dataset is still being indexed or if the download and process speeds are zero.
- Return type:
- class undr.display.DisplayProgress#
Represents download or process progress.
- class undr.display.Speedometer(maximum_samples: int)#
Measures speed with multiple samples and a sliding window.
- Parameters:
maximum_samples (int) – Number of samples. Fewer samples are used for the first few speed estimations, until that number is reached.
- class undr.display.Status#
Keeps track of download and process progress for a dataset.
- download: DisplayProgress#
Represents download progress.
Ignored if the mode is
undr.install_mode.Mode.REMOTE
.
- final_index_files: int#
Total number of index files.
This number may increase as more index files are discovered while indexing.
- mode: undr.install_mode.Mode#
Dataset installation mode.
- path_id: pathlib.PurePosixPath#
Path ID of the dataset’s base directory.
- process: DisplayProgress#
Represents process progress
Ignored if the mode is
undr.install_mode.Mode.REMOTE
orundr.install_mode.Mode.LOCAL
.
- complete() bool #
Checks whether actions are complete for this dataset.
- Returns:
Whether all actions are complete.
- Return type:
- classmethod from_path_id_and_mode(path_id: pathlib.PurePosixPath, dataset_mode: undr.install_mode.Mode)#
Initializes a status from a path ID and a mode.
- Parameters:
path_id (pathlib.PurePosixPath) – The dataset’s base directory.
dataset_mode (install_mode.Mode) – The installation mode.
- Returns:
Default initial status.
- Return type:
- is_parent_of(path_id: pathlib.PurePosixPath) bool #
Checks whether the dataset represented by this status is a parent of the given resource.
This can be used to assign messages from a given resource to the right dataset.
- Parameters:
path_id (pathlib.PurePosixPath) – The path ID of the resource that may be a child of this dataset.
- Returns:
Whether this dataset is a parent of the resource.
- Return type:
- progress_and_representation(download_tag: Tag, process_tag: Tag) tuple[tuple[float, float] | None, str] #
Returns download and process progress in bytes and a string representation of these values.
- Parameters:
- Returns:
The first entry is None if the dataset is being indexed. Otherwise, the first entry is the progress in bytes. The second entry is the string representation of progress, which is always not None.
- Return type:
- class undr.display.Tag#
Label and icon representing an action in a terminal.
- undr.display.format_bold(message: str) str #
Surrounds the message with ANSI escape characters for bold formatting.
- undr.display.format_dim(message: str) str #
Surrounds the message with ANSI escape characters for dim formatting.
- undr.display.progress_bar(width: int, progress: tuple[float, float] | None) str #
Generates a progress bar compatible with terminals.
- Parameters:
width (int) – The progress bar width in characters.
progress (Optional[tuple[float, float]]) – None yields an indeterminate progress bar, a tuple returns a two-levels progress bar (bottom and top). The tuple values must be in the range
[0, 1]
. Use the same value twice to generate a simple (one-level) progress bar.
- Returns:
The progress bar as a string, without line breaks.
- Return type: