1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 04:05:39 +01:00

Break out progress() to svtplay.output module

Now it is very clear that progressbar() duplicates an existing function. But
obsoleting one or the other is work for the future.
This commit is contained in:
Olof Johansson 2013-02-12 19:14:07 +01:00
parent 7433c0465e
commit 5fed1b2a4a

View File

@ -1,7 +1,30 @@
import sys
import os
from svtplay.log import log
progress_stream = sys.stderr
def progress(byte, total, extra = ""):
""" Print some info about how much we have downloaded """
ratio = float(byte) / total
percent = round(ratio*100, 2)
tlen = str(len(str(total)))
fmt = "Downloaded %"+tlen+"dkB of %dkB bytes (% 3.2f%%)"
progresstr = fmt % (byte >> 10, total >> 10, percent)
columns = int(os.getenv("COLUMNS", "80"))
if len(progresstr) < columns - 13:
p = int((columns - len(progresstr) - 3) * ratio)
q = int((columns - len(progresstr) - 3) * (1 - ratio))
progresstr = "[" + ("#" * p) + (" " * q) + "] " + progresstr
progress_stream.write(progresstr + ' ' + extra + '\r')
if byte >= total:
progress_stream.write('\n')
progress_stream.flush()
def progressbar(total, pos, msg=""):
"""
Given a total and a progress position, output a progress bar