Progress hook does not finish on a greater value than total
authorFrederic Massart <fred@moodle.com>
Mon, 9 Sep 2013 10:15:40 +0000 (18:15 +0800)
committerFrederic Massart <fred@moodle.com>
Mon, 9 Sep 2013 10:15:40 +0000 (18:15 +0800)
lib/tools.py

index 3d85ab8..a70c0e4 100644 (file)
@@ -116,6 +116,8 @@ def downloadProcessHook(count, size, total):
     """Hook to report the downloading a file using urllib.urlretrieve"""
     downloaded = int((count * size) / (1024))
     total = int(total / (1024)) if total != 0 else '?'
+    if downloaded > total:
+        downloaded = total
     sys.stderr.write("\r  %sKB / %sKB" % (downloaded, total))
     sys.stderr.flush()