tools: wasptool: Add a progress bar to the BLE uploads
This commit is contained in:
parent
e2234112ff
commit
02b92ff90d
1 changed files with 20 additions and 9 deletions
|
@ -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,13 +66,12 @@ def paste(c, f, verbose=False):
|
||||||
if ln.lstrip().startswith('#'):
|
if ln.lstrip().startswith('#'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
tosend.append(ln)
|
||||||
|
|
||||||
|
for ln in pbar(tosend, verbose):
|
||||||
c.sendline(ln)
|
c.sendline(ln)
|
||||||
c.expect('=== ')
|
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__':
|
||||||
|
|
Loading…
Reference in a new issue