From d02f59586ec33a7cb0e48dfe44b33b849883caad Mon Sep 17 00:00:00 2001 From: Davide Cavalca Date: Mon, 21 Feb 2022 16:48:25 -0800 Subject: use tqdm for progress bar instead of clint (#59) * Use tqdm for progress bar instead of clint * use new tqdm syntax Co-authored-by: nlscc <66028747+nlscc@users.noreply.github.com> --- samloader/crypt.py | 6 ++++-- samloader/main.py | 7 ++++--- setup.py | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/samloader/crypt.py b/samloader/crypt.py index 29611a6..94414d6 100644 --- a/samloader/crypt.py +++ b/samloader/crypt.py @@ -6,7 +6,7 @@ import hashlib import xml.etree.ElementTree as ET from Cryptodome.Cipher import AES -from clint.textui import progress +from tqdm import tqdm from . import fusclient from . import request @@ -38,7 +38,8 @@ def decrypt_progress(inf, outf, key, length): if length % 16 != 0: raise Exception("invalid input block size") chunks = length//4096+1 - for i in progress.bar(range(chunks)): + pbar = tqdm(total=length, unit="B", unit_scale=True) + for i in range(chunks): block = inf.read(4096) if not block: break @@ -47,3 +48,4 @@ def decrypt_progress(inf, outf, key, length): outf.write(unpad(decblock)) else: outf.write(decblock) + pbar.update(4096) diff --git a/samloader/main.py b/samloader/main.py index 57210dc..48c9a82 100644 --- a/samloader/main.py +++ b/samloader/main.py @@ -5,7 +5,7 @@ import argparse import os import base64 import xml.etree.ElementTree as ET -from clint.textui import progress +from tqdm import tqdm from . import request from . import crypt @@ -46,11 +46,12 @@ def main(): r = client.downloadfile(path+filename, dloffset) if args.show_md5 and "Content-MD5" in r.headers: print("MD5:", base64.b64decode(r.headers["Content-MD5"]).hex()) - # TODO: use own progress bar instead of clint - for chunk in progress.bar(r.iter_content(chunk_size=0x10000), expected_size=((size-dloffset)/0x10000)+1): + pbar = tqdm(total=size, initial=dloffset, unit="B", unit_scale=True) + for chunk in r.iter_content(chunk_size=0x10000): if chunk: fd.write(chunk) fd.flush() + pbar.update(0x10000) fd.close() if args.do_decrypt: # decrypt the file if needed dec = out.replace(".enc4", "").replace(".enc2", "") # TODO: use a better way of doing this diff --git a/setup.py b/setup.py index 1442858..018448f 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ setuptools.setup( ], }, install_requires=[ - "clint", + "tqdm", "pycryptodomex", "requests" ], -- cgit v1.2.3