summaryrefslogtreecommitdiff
path: root/tools/wasptool
diff options
context:
space:
mode:
Diffstat (limited to 'tools/wasptool')
-rwxr-xr-xtools/wasptool48
1 files changed, 34 insertions, 14 deletions
diff --git a/tools/wasptool b/tools/wasptool
index 72e88bc..698cc6c 100755
--- a/tools/wasptool
+++ b/tools/wasptool
@@ -1,9 +1,7 @@
#!/usr/bin/python3
-#
-# SPDX-License-Identifier: MIT
+# SPDX-License-Identifier: LGPL-3.0-or-later
# Copyright (c) 2020 Daniel Thompson
-#
import argparse
import random
@@ -13,7 +11,23 @@ import time
import string
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):
+ """Stop the watch and synchronize with the command prompt.
+
+ Sending a random print ensure the final export (of the prompt)
+ does not accidentally match a previously issued prompt.
+ """
tag = ''.join([random.choice(string.ascii_uppercase) for i in range(6)])
c.send('\x03')
@@ -23,11 +37,20 @@ def sync(c):
c.expect('>>> ')
def unsync(c):
- # Set the watch running again
- c.sendline('wasp.run()')
+ """Set the watch running again.
+
+ There must be an expect (or a sleep) since if we kill the subordinate
+ process too early then the sendline will not have completed.
+ """
+ c.sendline('wasp.system.run()')
+ c.expect('Watch is running, use Ctrl-C to stop')
+ c.send('\x18')
def paste(c, f, verbose=False):
docstring = False
+
+ tosend = []
+
for ln in f.readlines():
ln = ln.rstrip()
@@ -43,12 +66,11 @@ def paste(c, f, verbose=False):
if ln.lstrip().startswith('#'):
continue
+ tosend.append(ln)
- c.sendline(ln)
- c.expect('=== ')
-
- if not verbose:
- print('.', end='', flush=True)
+ for ln in pbar(tosend, verbose):
+ c.sendline(ln)
+ c.expect('=== ')
def handle_eval(c, cmd):
verbose = bool(c.logfile)
@@ -69,14 +91,13 @@ def handle_exec(c, fname):
with open(fname) as f:
if not verbose:
- print(f'Preparing to run {fname} ...', end='', flush=True)
+ print(f'Preparing to run {fname}:')
c.send('\x05')
c.expect('=== ')
paste(c, f, verbose)
- print(' done')
c.logfile = sys.stdout
c.send('\x04')
c.expect('>>> ')
@@ -101,14 +122,13 @@ def handle_upload(c, fname):
with open(fname) as f:
if not verbose:
- print(f'Uploading {fname} ...', end='', flush=True)
+ print(f'Uploading {fname}:')
c.sendline(f'upload("{os.path.basename(fname)}")')
c.expect('=== ')
paste(c, f, verbose)
c.send('\x04')
- print(' done')
c.expect('>>> ')
if __name__ == '__main__':