Skip to content

Use tqdm for operations with longer durations #324

@ckunki

Description

@ckunki

https://tqdm.github.io/

And display a nice progress bar

Proposed use cases

  • build docker container
  • upload to BucketFS

Sample implementation:

import contextlib
from pathlib import Path

import exasol.bucketfs as bfs
import tqdm

def upload_file_to_bucketfs(bfs_file: bfs.path.PathLike, file: Path) -> None:
    """
    If leave is False, then hide progress bar after upload.

    If leave is not specified (default), then progress bar remains
    visible after upload is completed.
    """
    print(f'Uploading {file.name} to bucketfs:/{bfs_file.parent}')
    size = file.stat().st_size
    with contextlib.ExitStack() as stack:
        fd = stack.enter_context(file.open("rb"))
        progress = stack.enter_context(
            tqdm.tqdm.wrapattr(
                fd,
                "read",
                total=size,
                unit='B',
                unit_scale=True,
                unit_divisor=1024,
                colour="green",
                leave=False, # see above
            )
        )
        bfs_file.write(progress)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureProduct feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions