Use tqdm for progress bar.
This commit is contained in:
parent
3d42c988f0
commit
73eb4cd08c
BIN
qubesadmin/tools/.qvm_template.py.swp
Normal file
BIN
qubesadmin/tools/.qvm_template.py.swp
Normal file
Binary file not shown.
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user