implement a download progress indicator (#1519)

This commit is contained in:
Mike Fährmann
2021-09-28 22:37:11 +02:00
parent cad85640de
commit d0761454b1
5 changed files with 79 additions and 15 deletions

View File

@@ -258,6 +258,9 @@ class NullOutput():
def success(self, path, tries):
"""Print a message indicating the completion of a download"""
def progress(self, bytes_total, bytes_downloaded, bytes_per_second):
"""Display download progress"""
class PipeOutput(NullOutput):
@@ -289,6 +292,19 @@ class TerminalOutput(NullOutput):
def success(self, path, tries):
print("\r", self.shorten(CHAR_SUCCESS + path), sep="")
def progress(self, bytes_total, bytes_downloaded, bytes_per_second):
if bytes_total is None:
print("\r {:>8} {:>10} \r".format(
util.format_value(bytes_downloaded, "B"),
util.format_value(bytes_per_second, "B/s"),
), end="")
else:
print("\r{:>3}% {:>8} {:>10} \r".format(
bytes_downloaded * 100 // bytes_total,
util.format_value(bytes_downloaded, "B"),
util.format_value(bytes_per_second, "B/s"),
), end="")
class ColorOutput(TerminalOutput):