Files
firefox/third_party/python/dlmanager/examples/dl_tqdm.py
T
Andrew Halberstadt 7bb38413f2 Bug 1346025 - Move vendored python modules from /python to /third_party/python, r=ted
This commit is a simple 'hg mv' and does not contain any file modifications.

***
Bug 1346025 - Split vendored modules in python/moz.build to third_party/python/moz.build, r=ted

***
Bug 1346025 - Update references to moved python modules, r=ted

MozReview-Commit-ID: A12RnIFtXju
2017-05-25 11:48:03 -04:00

46 lines
1.0 KiB
Python

import argparse
import tqdm
from six.moves.urllib.parse import urlparse
from dlmanager import Download
def parse_args(argv=None):
parser = argparse.ArgumentParser()
parser.add_argument("url", help="url to download")
return parser.parse_args(argv)
def download_progress(bar):
last_b = [0]
def inner(_, current, total):
if total is not None:
bar.total = total
delta = current - last_b[0]
last_b[0] = current
if delta > 0:
bar.update(delta)
return inner
def download_file(url, dest=None):
if dest is None:
dest = urlparse(url).path.split('/')[-1]
with tqdm.tqdm(unit='B', unit_scale=True, miniters=1, dynamic_ncols=True,
desc=dest) as bar:
dl = Download(url, dest, progress=download_progress(bar))
dl.start()
dl.wait()
if __name__ == '__main__':
options = parse_args()
try:
download_file(options.url)
except KeyboardInterrupt:
print("\nInterrupted.")