"vscode:/vscode.git/clone" did not exist on "6adc19a6448af03ac7cc61bf21d07ea3be7099f7"
Commit 50b2f910 authored by Holger Kohr's avatar Holger Kohr Committed by Francisco Massa
Browse files

Fix broken progress bar (#524)

- Fix broken update calculation
- Make progress bar use the neat `unit_scale` feature
  of tqdm
parent 3f6c23c0
......@@ -5,10 +5,12 @@ import errno
from tqdm import tqdm
def gen_bar_updator(pbar):
def gen_bar_updater(pbar):
def bar_update(count, block_size, total_size):
pbar.total = total_size / block_size
pbar.update(count)
if pbar.total is None and total_size:
pbar.total = total_size
progress_bytes = count * block_size
pbar.update(progress_bytes - pbar.n)
return bar_update
......@@ -47,13 +49,19 @@ def download_url(url, root, filename, md5):
else:
try:
print('Downloading ' + url + ' to ' + fpath)
urllib.request.urlretrieve(url, fpath, reporthook=gen_bar_updator(tqdm()))
urllib.request.urlretrieve(
url, fpath,
reporthook=gen_bar_updater(tqdm(unit='B', unit_scale=True))
)
except:
if url[:5] == 'https':
url = url.replace('https:', 'http:')
print('Failed download. Trying https -> http instead.'
' Downloading ' + url + ' to ' + fpath)
urllib.request.urlretrieve(url, fpath)
urllib.request.urlretrieve(
url, fpath,
reporthook=gen_bar_updater(tqdm(unit='B', unit_scale=True))
)
def list_dir(root, prefix=False):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment