summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2019-05-28 14:52:12 +0200
committerNirbheek Chauhan <nirbheek@centricular.com>2019-07-20 13:36:53 +0530
commit92c7e18cb0ccdcf3cd5a67a2165e22f46edce288 (patch)
treecb7db165762083c5a68f5fbb33bffcd8ca94195c
parent20d3e1bd5cc44301c3820fc0c6423028036555a5 (diff)
downloadmeson-nirbheek/add-optional-progress-bar.tar.gz
Use tqdm when available for wrap downloads toonirbheek/add-optional-progress-bar
We have a wrapper class for tqdm in mesonlib.py now that handles everything for us.
-rw-r--r--mesonbuild/wrap/wrap.py18
1 files changed, 6 insertions, 12 deletions
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py
index 55f86bc05..4b2a32302 100644
--- a/mesonbuild/wrap/wrap.py
+++ b/mesonbuild/wrap/wrap.py
@@ -18,8 +18,9 @@ import urllib.request, os, hashlib, shutil, tempfile, stat
import subprocess
import sys
import configparser
+
from . import WrapMode
-from ..mesonlib import MesonException
+from ..mesonlib import ProgressBar, MesonException
try:
import ssl
@@ -278,24 +279,17 @@ class Resolver:
tmpfile.write(block)
hashvalue = h.hexdigest()
return hashvalue, tmpfile.name
- print('Download size:', dlsize)
- print('Downloading: ', end='')
sys.stdout.flush()
- printed_dots = 0
- downloaded = 0
+ progress_bar = ProgressBar(bar_type='download', total=dlsize,
+ desc='Downloading')
while True:
block = resp.read(blocksize)
if block == b'':
break
- downloaded += len(block)
h.update(block)
tmpfile.write(block)
- ratio = int(downloaded / dlsize * 10)
- while printed_dots < ratio:
- print('.', end='')
- sys.stdout.flush()
- printed_dots += 1
- print('')
+ progress_bar.update(len(block))
+ progress_bar.close()
hashvalue = h.hexdigest()
return hashvalue, tmpfile.name