Skip to content

Commit

Permalink
wasptool: Fix progress bar numbering
Browse files Browse the repository at this point in the history
Currently direct callers of draw_pbar() can have 20 or more digits after
the decimal place. Fix this by moving the rounding function.

Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
  • Loading branch information
daniel-thompson committed May 5, 2021
1 parent 69a989b commit 3bbd808
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions tools/wasptool
Expand Up @@ -18,13 +18,13 @@ def draw_pbar(percent, quiet=False, end='\r'):
if percent > 100:
percent = 100
bar = int(percent) // 2
print(f'[{"#"*bar}{"."*(50-bar)}] {percent}% ', end=end, flush=True)
print(f'[{"#"*bar}{"."*(50-bar)}] {round(percent, 1)}% ', end=end, flush=True)

def pbar(iterable, quiet=False):
step = 100 / len(iterable)

for i, v in enumerate(iterable):
draw_pbar(round(step * i, 1), quiet)
draw_pbar(step * i, quiet)
yield v
if not quiet:
draw_pbar(100, quiet, None)
Expand Down Expand Up @@ -264,7 +264,6 @@ def handle_binary_download(c, tname, fname):
elif reply.startswith("'"):
# 'b\'..CONTENT..\''
reply = reply[1:-1].replace("\\'", "'")
data = print(reply)
data = eval(reply)
if len(data) == 0:
break
Expand Down

0 comments on commit 3bbd808

Please sign in to comment.