1
0
Fork 0

tools: wasptool: Add a progress bar to the BLE uploads

This commit is contained in:
Daniel Thompson 2020-04-06 21:40:34 +01:00
parent e2234112ff
commit 02b92ff90d

View file

@ -11,6 +11,17 @@ import time
import string import string
import sys import sys
def pbar(iterable, quiet=False):
step = 100 / len(iterable)
for i, v in enumerate(iterable):
if not quiet:
percent = round(step * i, 1)
bar = int(percent) // 2
print(f'[{"="*bar}{"-"*(50-bar)}] {percent}%', end='\r', flush=True)
yield v
if not quiet:
print(f'[{"="*50}] 100% ')
def sync(c): def sync(c):
"""Stop the watch and synchronize with the command prompt. """Stop the watch and synchronize with the command prompt.
@ -37,6 +48,9 @@ def unsync(c):
def paste(c, f, verbose=False): def paste(c, f, verbose=False):
docstring = False docstring = False
tosend = []
for ln in f.readlines(): for ln in f.readlines():
ln = ln.rstrip() ln = ln.rstrip()
@ -52,12 +66,11 @@ def paste(c, f, verbose=False):
if ln.lstrip().startswith('#'): if ln.lstrip().startswith('#'):
continue continue
tosend.append(ln)
c.sendline(ln) for ln in pbar(tosend, verbose):
c.expect('=== ') c.sendline(ln)
c.expect('=== ')
if not verbose:
print('.', end='', flush=True)
def handle_eval(c, cmd): def handle_eval(c, cmd):
verbose = bool(c.logfile) verbose = bool(c.logfile)
@ -78,14 +91,13 @@ def handle_exec(c, fname):
with open(fname) as f: with open(fname) as f:
if not verbose: if not verbose:
print(f'Preparing to run {fname} ...', end='', flush=True) print(f'Preparing to run {fname}:')
c.send('\x05') c.send('\x05')
c.expect('=== ') c.expect('=== ')
paste(c, f, verbose) paste(c, f, verbose)
print(' done')
c.logfile = sys.stdout c.logfile = sys.stdout
c.send('\x04') c.send('\x04')
c.expect('>>> ') c.expect('>>> ')
@ -110,14 +122,13 @@ def handle_upload(c, fname):
with open(fname) as f: with open(fname) as f:
if not verbose: if not verbose:
print(f'Uploading {fname} ...', end='', flush=True) print(f'Uploading {fname}:')
c.sendline(f'upload("{os.path.basename(fname)}")') c.sendline(f'upload("{os.path.basename(fname)}")')
c.expect('=== ') c.expect('=== ')
paste(c, f, verbose) paste(c, f, verbose)
c.send('\x04') c.send('\x04')
print(' done')
c.expect('>>> ') c.expect('>>> ')
if __name__ == '__main__': if __name__ == '__main__':