From 14124034bfbce9379ff2ba1d2e59bd40186dbefb Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Sun, 5 Feb 2017 14:20:55 +0100 Subject: [PATCH] show progress when downloading crate Signed-off-by: Igor Gnatenko --- rust2rpm.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rust2rpm.py b/rust2rpm.py index abbb6ac..f64659c 100644 --- a/rust2rpm.py +++ b/rust2rpm.py @@ -7,6 +7,7 @@ import sys import jinja2 import requests +import tqdm import cargodeps @@ -115,14 +116,16 @@ if __name__ == "__main__": if not os.path.isdir(CACHEDIR): os.mkdir(CACHEDIR) - cratef = os.path.join(CACHEDIR, "{}-{}.crate".format(args.crate, args.version)) + cratef_base = "{}-{}.crate".format(args.crate, args.version) + cratef = os.path.join(CACHEDIR, cratef_base) if not os.path.isfile(cratef): url = requests.compat.urljoin(API_URL, "crates/{}/{}/download#".format(args.crate, args.version)) req = requests.get(url, stream=True) req.raise_for_status() + total = int(req.headers["Content-Length"]) with open(cratef, "wb") as f: - # FIXME: should we use req.iter_content() and specify custom chunk size? - for chunk in req: + for chunk in tqdm.tqdm(req.iter_content(), "Downloading {}".format(cratef_base), + total=total, unit="B", unit_scale=True): f.write(chunk) files = []