Ejemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     # type: (List[Any], Dict[Any, Any]) -> None
     # https://github.com/python/mypy/issues/5887
     super(DownloadProgressMixin, self).__init__(  # type: ignore
         *args, **kwargs)
     self.message = (" " *
                     (get_indentation() + 2)) + self.message  # type: str
Ejemplo n.º 2
0
def _rich_progress_bar(
    iterable: Iterator[bytes],
    *,
    bar_type: str,
    size: int,
) -> Iterator[bytes]:
    assert bar_type == "on", "This should only be used in the default mode."

    if not size:
        total = float("inf")
        columns: Tuple[ProgressColumn, ...] = (
            TextColumn("[progress.description]{task.description}"),
            SpinnerColumn("line", speed=1.5),
            FileSizeColumn(),
            TransferSpeedColumn(),
            TimeElapsedColumn(),
        )
    else:
        total = size
        columns = (
            TextColumn("[progress.description]{task.description}"),
            BarColumn(),
            DownloadColumn(),
            TransferSpeedColumn(),
            TextColumn("eta"),
            TimeRemainingColumn(),
        )

    progress = Progress(*columns, refresh_per_second=30)
    task_id = progress.add_task(" " * (get_indentation() + 2), total=total)
    with progress:
        for chunk in iterable:
            yield chunk
            progress.update(task_id, advance=len(chunk))
Ejemplo n.º 3
0
    def __init__(
        self,
        message,
        file=None,
        spin_chars="-\\|/",

        # Empirically, 8 updates/second looks nice
        min_update_interval_seconds=0.125):

        # type: (str, IO[str], str, float) -> None

        self._message = message

        if file is None:

            file = sys.stdout

        self._file = file

        self._rate_limiter = RateLimiter(min_update_interval_seconds)

        self._finished = False

        self._spin_cycle = itertools.cycle(spin_chars)

        self._file.write(" " * get_indentation() + self._message + " ... ")

        self._width = 0
Ejemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     # type: (List[Any], Dict[Any, Any]) -> None
     super(DownloadProgressMixin, self).__init__(  # type: ignore
         *args,
         **kwargs
     )
     self.message = (" " * (
             get_indentation() + 2
     )) + self.message  # type: str
Ejemplo n.º 5
0
    def __init__(self, message, file=None, spin_chars="-\\|/",
                 # Empirically, 8 updates/second looks nice
                 min_update_interval_seconds=0.125):
        self._message = message
        if file is None:
            file = sys.stdout
        self._file = file
        self._rate_limiter = RateLimiter(min_update_interval_seconds)
        self._finished = False

        self._spin_cycle = itertools.cycle(spin_chars)

        self._file.write(" " * get_indentation() + self._message + " ... ")
        self._width = 0
Ejemplo n.º 6
0
 def __init__(self, *args: Any, **kwargs: Any) -> None:
     # https://github.com/python/mypy/issues/5887
     super().__init__(*args, **kwargs)  # type: ignore
     self.message: str = (" " * (get_indentation() + 2)) + self.message
Ejemplo n.º 7
0
 def __init__(self, *args, **kwargs):
     super(DownloadProgressMixin, self).__init__(*args, **kwargs)
     self.message = (" " * (get_indentation() + 2)) + self.message
Ejemplo n.º 8
0
 def __init__(self, *args, **kwargs):
     super(DownloadProgressMixin, self).__init__(*args, **kwargs)
     self.message = (" " * (get_indentation() + 2)) + self.message
Ejemplo n.º 9
0

class DownloadProgressMixin(object):

    def __init__(self, *args, **kwargs):
        # type: (List[Any], Dict[Any, Any]) -> None
<<<<<<< HEAD
        # https://github.com/python/mypy/issues/5887
=======
>>>>>>> b66a76afa15ab74019740676a52a071b85ed8f71
        super(DownloadProgressMixin, self).__init__(  # type: ignore
            *args,
            **kwargs
        )
        self.message = (" " * (
            get_indentation() + 2
        )) + self.message  # type: str

    @property
    def downloaded(self):
        # type: () -> str
        return format_size(self.index)  # type: ignore

    @property
    def download_speed(self):
        # type: () -> str
        # Avoid zero division errors...
        if self.avg == 0.0:  # type: ignore
            return "..."
        return format_size(1 / self.avg) + "/s"  # type: ignore