summaryrefslogtreecommitdiffstats
path: root/native_client_sdk
diff options
context:
space:
mode:
authortechtonik <techtonik@gmail.com>2015-11-01 00:22:46 -0700
committerCommit bot <commit-bot@chromium.org>2015-11-01 07:23:31 +0000
commitb7518cda63029a707f5e164f61f70ef387020c6b (patch)
tree9168ffa8bb42a8373630db72692a601a9ee5f274 /native_client_sdk
parenta5d04520265e18b0992b0446fc6b0217ee45d4f2 (diff)
downloadchromium_src-b7518cda63029a707f5e164f61f70ef387020c6b.zip
chromium_src-b7518cda63029a707f5e164f61f70ef387020c6b.tar.gz
chromium_src-b7518cda63029a707f5e164f61f70ef387020c6b.tar.bz2
[NaCl SDK] Show file size while downloading SDK archives
Downloading bundle pepper_46 (file 1/2 - "naclports.tar.bz2") |================================================| 74642748 ... 4416/72893 kB BUG=153014 Review URL: https://codereview.chromium.org/1405103005 Cr-Commit-Position: refs/heads/master@{#357284}
Diffstat (limited to 'native_client_sdk')
-rw-r--r--native_client_sdk/src/build_tools/sdk_tools/download.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/native_client_sdk/src/build_tools/sdk_tools/download.py b/native_client_sdk/src/build_tools/sdk_tools/download.py
index d3da5bb..bda79c8 100644
--- a/native_client_sdk/src/build_tools/sdk_tools/download.py
+++ b/native_client_sdk/src/build_tools/sdk_tools/download.py
@@ -26,19 +26,25 @@ def UrlOpen(url):
def MakeProgressFunction(file_size):
+ '''Returns a progress function based on a known file size'''
# An inner function can only read nonlocal variables, not assign them. We can
# work around this by using a list of one element.
dots = [0]
+ console = sys.stdout.isatty()
def ShowKnownProgress(progress):
- '''Returns a progress function based on a known file size'''
if progress == 0:
- sys.stdout.write('|%s|\n' % ('=' * 48))
+ sys.stdout.write('|%s| %s\n' % ('=' * 48, file_size))
elif progress == -1:
sys.stdout.write('\n')
else:
new_dots = progress * 50 / file_size - dots[0]
- sys.stdout.write('.' * new_dots)
dots[0] += new_dots
+ if not console:
+ sys.stdout.write('.' * new_dots)
+ else:
+ # use line rewrite capability
+ sys.stdout.write(
+ '\r%s %s/%s kB' % ('.' * dots[0], progress//1000, file_size//1000))
sys.stdout.flush()
return ShowKnownProgress
@@ -54,7 +60,7 @@ def DownloadAndComputeHash(from_stream, to_stream=None, progress_func=None):
progress_func: [optional] A function used to report download progress. If
provided, progress_func is called with progress=0 at the
beginning of the download, periodically with progress>0
- (== number of bytes read do far) during the download, and
+ (== number of bytes read so far) during the download, and
progress=-1 at the end or if the download was aborted.
Return