From 884f09cbde3882de8e7db3bd90d856f499a0e706 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Thu, 29 Aug 2019 14:06:50 +0200 Subject: move urlretrieve report hook to util.py and use archive in dj_trace --- src/util.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/util.py') diff --git a/src/util.py b/src/util.py index aebdb00..9941d6f 100644 --- a/src/util.py +++ b/src/util.py @@ -23,6 +23,17 @@ import sys import src.globalvars +def download_reporthook(blocknum, blocksize, totalsize): + """Status report hook for urlretrieve""" + readsofar = blocknum * blocksize + if totalsize > 0: + percent = readsofar * 100 / totalsize + status = "\r%5.1f%% %*d / %d" % ( + percent, len(str(totalsize)), readsofar, totalsize) + sys.stderr.write(status) + else: # total size is unknown + sys.stderr.write(f"\rdownloaded {readsofar}") + def is_exe(fpath): """Check if the given path is an exexutable file""" -- cgit v1.2.3