Пример #1
0
    def for_download_and_hashcheck(
        cls, title: str,
        tc_log: logger.CustomLogger = None,
    ) -> "Progress":
        _progress = Progress(
            title=title,
            columns={
                "file_key": r_progress.TextColumn(
                    "[progress.description]{task.description}"),
                "progress": r_progress.BarColumn(),
                "percentage": r_progress.TextColumn(
                    "[progress.percentage]{task.percentage:>3.0f}%"),
                # todo: combine hash checking here ...
                #  especially better if we are building hash as we progress download
                # "hash_progress": progress.BarColumn(),
                # "hash_percentage": progress.TextColumn(
                #     "[progress.percentage]{task.percentage:>3.0f}%"),
                "download": r_progress.DownloadColumn(),
                "time_elapsed": r_progress.TimeElapsedColumn(),
                "status": SpinnerColumn(
                    start_state_key="start",
                    finished_state_key="finished",
                    states={
                        "start": SpinnerType.dots,
                        "finished": EMOJI["white_heavy_check_mark"],
                        "already_finished": EMOJI["heavy_check_mark"],
                        "failed": EMOJI["cross_mark"],
                    }
                ),
            },
            tc_log=tc_log,
        )

        return _progress
Пример #2
0
 def simple_progress(
     title: t.Optional[str] = None,
     refresh_per_second: int = 10,
     console: r_console.Console = r_console.Console(record=True),
     tc_log: logger.CustomLogger = None,
 ) -> "Progress":
     return Progress(
         title=title,  # setting this to str will add panel
         columns={
             "text": r_progress.TextColumn(
                 "[progress.description]{task.description}"),
             "progress": r_progress.BarColumn(),
             "percentage": r_progress.TextColumn(
                 "[progress.percentage]{task.percentage:>3.0f}%"),
             "time_elapsed": r_progress.TimeElapsedColumn(),
             "time_remaining": r_progress.TimeRemainingColumn(),
             "status": SpinnerColumn(
                 start_state_key="start",
                 finished_state_key="finished",
                 states={
                     "start": SpinnerType.dots,
                     "finished": EMOJI["white_heavy_check_mark"],
                 }
             ),
         },
         console=console,
         refresh_per_second=refresh_per_second,
         tc_log=tc_log,
     )
Пример #3
0
    def __post_init__(self):
        # make spinner
        self._spinner = self.spinner.get_spinner(
            text=self.status, speed=self.spinner_speed
        )

        # make overall progress
        if self.overall_progress_iterable is not None:
            self._overall_progress = Progress(
                columns={
                    "text": r_progress.TextColumn(
                        "[progress.description]{task.description}"),
                    "progress": r_progress.BarColumn(),
                    "percentage": r_progress.TextColumn(
                        "[progress.percentage]{task.percentage:>3.0f}%"),
                    "time_elapsed": r_progress.TimeElapsedColumn(),
                    "time_remaining": r_progress.TimeRemainingColumn(),
                    "status": SpinnerColumn(
                        start_state_key="start",
                        finished_state_key="finished",
                        states={
                            "start": SpinnerType.dots,
                            "finished": EMOJI["white_heavy_check_mark"],
                        }
                    ),
                },
                console=self.console,
                refresh_per_second=self.refresh_per_second,
            )

        # call super
        super().__post_init__()
Пример #4
0
def _build_index():
    """Build asteroid name-number index from SsODNet sso_index."""

    tasks = [
        _build_index_of_aliases,
        _build_number_index,
        _build_name_index,
        _build_designation_index,
        _build_palomar_transit_index,
    ]

    with progress.Progress(
            "[progress.description]{task.description}",
            progress.BarColumn(),
            "[progress.percentage]{task.percentage:>3.0f}%",
    ) as progress_bar:

        steps = progress_bar.add_task("Building index", total=len(tasks) + 1)

        index = _retrieve_index_from_ssodnet()
        progress_bar.update(steps, advance=1)

        for task in tasks:
            task(index)
            progress_bar.update(steps, advance=1)
Пример #5
0
def test_bar_columns():
    bar_column = progress.BarColumn(100)
    assert bar_column.bar_width == 100
    task = progress.Task(1, "test", 100, 20)
    bar = bar_column(task)
    assert isinstance(bar, Bar)
    assert bar.completed == 20
    assert bar.total == 100
Пример #6
0
 def __init__(self, console: Console, total_bytes: int):
     self.progress = rp.Progress(
         rp.TextColumn("[bold blue]{task.description}", justify="right"),
         rp.BarColumn(bar_width=None),
         "[progress.percentage]{task.percentage:>3.1f}%",
         rp.DownloadColumn(),
         rp.TimeRemainingColumn(),
         console=console,
     )
     self.task: int = self.progress.add_task(
         description="transfer image...", total=total_bytes)
Пример #7
0
    def setup_bar(self, total: int):
        """Initialize the progress bar."""
        print()
        self.progress_mgr = progress.Progress(
            progress.TextColumn("[progress.description]{task.description}"),
            progress.BarColumn(),
            progress.TextColumn(
                "[progress.percentage]{task.percentage:>3.0f}%"),
            progress.TimeRemainingColumn(),
            progress.TextColumn("{task.fields[text]}"),
            console=console)
        self.exit = type(self.progress_mgr).__exit__
        self.progress = type(self.progress_mgr).__enter__(self.progress_mgr)
        self.bar = self.progress.add_task(self.icon, total=total, text="")

        # Logging needs to be set up after the bar, to make use if its print hook
        self.setup_loggers()
Пример #8
0
                        }
                    }
                }
            }
        }
    }
}
"""

import bson
from pymongo.collection import Collection
from rich import print, progress

progress = progress.Progress(
    progress.TextColumn("{task.description} ", justify="left"),
    progress.BarColumn(bar_width=None),
    "[progress.percentage]{task.percentage:>3.1f}% ({task.completed}/{task.total})",
    "•",
    progress.TimeRemainingColumn(),
)


def extract_schema_from_collection(collection: Collection, partial: bool):
    """ Extracts a schema definition from a collection.

    If the extraction is partial, only the first document in the collection is
    used to create the schema.
    """

    schema = {"count": 0, "document": {}}
    if partial: