MCPcopy
hub / github.com/Textualize/rich / DownloadColumn

Class DownloadColumn

rich/progress.py:865–911  ·  view source on GitHub ↗

Renders file size downloaded and total, e.g. '0.5/2.3 GB'. Args: binary_units (bool, optional): Use binary units, KiB, MiB etc. Defaults to False.

Source from the content-addressed store, hash-verified

863
864
865class DownloadColumn(ProgressColumn):
866 """Renders file size downloaded and total, e.g. '0.5/2.3 GB'.
867
868 Args:
869 binary_units (bool, optional): Use binary units, KiB, MiB etc. Defaults to False.
870 """
871
872 def __init__(
873 self, binary_units: bool = False, table_column: Optional[Column] = None
874 ) -> None:
875 self.binary_units = binary_units
876 super().__init__(table_column=table_column)
877
878 def render(self, task: "Task") -> Text:
879 """Calculate common unit for completed and total."""
880 completed = int(task.completed)
881
882 unit_and_suffix_calculation_base = (
883 int(task.total) if task.total is not None else completed
884 )
885 if self.binary_units:
886 unit, suffix = filesize.pick_unit_and_suffix(
887 unit_and_suffix_calculation_base,
888 ["bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"],
889 1024,
890 )
891 else:
892 unit, suffix = filesize.pick_unit_and_suffix(
893 unit_and_suffix_calculation_base,
894 ["bytes", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
895 1000,
896 )
897 precision = 0 if unit == 1 else 1
898
899 completed_ratio = completed / unit
900 completed_str = f"{completed_ratio:,.{precision}f}"
901
902 if task.total is not None:
903 total = int(task.total)
904 total_ratio = total / unit
905 total_str = f"{total_ratio:,.{precision}f}"
906 else:
907 total_str = "?"
908
909 download_status = f"{completed_str}/{total_str} {suffix}"
910 download_text = Text(download_status, style="progress.download")
911 return download_text
912
913
914class TransferSpeedColumn(ProgressColumn):

Callers 6

test_columnsFunction · 0.90
downloader.pyFile · 0.90
wrap_fileFunction · 0.85
openFunction · 0.85

Calls

no outgoing calls