implement a download progress indicator (#1519)
This commit is contained in:
@@ -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):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user