Use tqdm for progress bar.

This commit is contained in:
WillyPillow 2020-07-11 21:42:58 +08:00
parent 3d42c988f0
commit 73eb4cd08c
2 changed files with 9 additions and 19 deletions

Binary file not shown.

View File

@ -15,6 +15,7 @@ import dnf
import qubesadmin import qubesadmin
import qubesadmin.tools import qubesadmin.tools
import rpm import rpm
import tqdm
import xdg.BaseDirectory import xdg.BaseDirectory
PATH_PREFIX = '/var/lib/qubes/vm-templates' PATH_PREFIX = '/var/lib/qubes/vm-templates'
@ -249,25 +250,14 @@ def qrexec_download(args, app, spec, path, dlsize=None):
payload = qrexec_payload(args, app, spec) payload = qrexec_payload(args, app, spec)
proc.stdin.write(payload.encode('UTF-8')) proc.stdin.write(payload.encode('UTF-8'))
proc.stdin.close() proc.stdin.close()
while proc.poll() == None: with tqdm.tqdm(desc=spec, total=dlsize, unit_scale=True,
width = shutil.get_terminal_size((80, 20)).columns unit_divisor=1000, unit='B') as pbar:
pct = '%5.f%% ' % math.floor(f.tell() / dlsize * 100) last = 0
bar_len = width - len(pct) - 2 while proc.poll() == None:
num_hash = math.floor(f.tell() / dlsize * bar_len) cur = f.tell()
num_space = bar_len - num_hash pbar.update(cur - last)
# Clear previous bar last = cur
print(u'\u001b[1000D', end='', file=sys.stderr) time.sleep(0.1)
print(pct + '[' + ('#' * num_hash) + (' ' * num_space) + ']',
end='', file=sys.stderr)
sys.stderr.flush()
time.sleep(0.1)
#while True:
# c = proc.stderr.read(1)
# if not c:
# break
# # Write raw byte w/o decoding
# sys.stdout.buffer.write(c)
# sys.stdout.flush()
if proc.wait() != 0: if proc.wait() != 0:
return False return False
return True return True