summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-02-19 19:33:35 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-02-19 19:57:08 (GMT)
commitdf11539c29745f5592259b13320c834c3cb920fa (patch)
tree7882cc2899b3ad868b40b46e4422bacc4dece53a
parentf689c90498b58a5198bb56a2d3d5211db9670283 (diff)
wasp: Simple shell commands (based on upysh)
-rwxr-xr-xtools/wasptool5
-rw-r--r--wasp/boards/pinetime/manifest.py3
-rw-r--r--wasp/shell.py71
3 files changed, 77 insertions, 2 deletions
diff --git a/tools/wasptool b/tools/wasptool
index a6faf38..822ada9 100755
--- a/tools/wasptool
+++ b/tools/wasptool
@@ -83,11 +83,14 @@ def handle_rtc(c):
def handle_upload(c, fname):
verbose = bool(c.logfile)
+ c.sendline('from shell import upload')
+ c.expect('>>> ')
+
with open(fname) as f:
if not verbose:
print(f'Uploading {fname} ...', end='', flush=True)
- c.sendline(f'upload("{fname}")')
+ c.sendline(f'upload("{os.path.basename(fname)}")')
c.expect('=== ')
paste(c, f, verbose)
c.send('\x04')
diff --git a/wasp/boards/pinetime/manifest.py b/wasp/boards/pinetime/manifest.py
index 46016c8..3c0e19a 100644
--- a/wasp/boards/pinetime/manifest.py
+++ b/wasp/boards/pinetime/manifest.py
@@ -11,8 +11,9 @@ freeze('../..',
'drivers/vibrator.py',
'fonts.py',
'icons.py',
- 'manager.py',
'logo.py',
+ 'manager.py',
+ 'shell.py',
'widgets.py',
),
opt=3
diff --git a/wasp/shell.py b/wasp/shell.py
new file mode 100644
index 0000000..5ad9623
--- /dev/null
+++ b/wasp/shell.py
@@ -0,0 +1,71 @@
+# SPDX-License-Identifier: MIT
+# Copyright (c) 2020 Daniel Thompson
+# Copyright (c) 2016 Paul Sokolovsky
+
+import sys
+import os
+
+class LS:
+ def __repr__(self):
+ self.__call__()
+ return ""
+
+ def __call__(self, path="."):
+ l = os.listdir(path)
+ l.sort()
+ for f in l:
+ st = os.stat("%s/%s" % (path, f))
+ if st[0] & 0x4000: # stat.S_IFDIR
+ print(" <dir> %s" % f)
+ else:
+ print("% 8d %s" % (st[6], f))
+
+class PWD:
+ def __repr__(self):
+ return os.getcwd()
+
+ def __call__(self):
+ return self.__repr__()
+
+class CLEAR:
+ def __repr__(self):
+ return "\x1b[2J\x1b[H"
+
+ def __call__(self):
+ return self.__repr__()
+
+
+pwd = PWD()
+ls = LS()
+clear = CLEAR()
+
+cd = os.chdir
+mkdir = os.mkdir
+mv = os.rename
+rm = os.remove
+rmdir = os.rmdir
+
+def head(f, n=10):
+ with open(f) as f:
+ for i in range(n):
+ l = f.readline()
+ if not l: break
+ print(l, end='')
+
+def cat(f):
+ head(f, 1 << 30)
+
+def download(path):
+ head(f, 1 << 30)
+
+def upload(path):
+ print("upload mode; Ctrl-C to cancel, Ctrl-D to finish")
+ with open(path, "w") as f:
+ while 1:
+ print('=== ', end='')
+ try:
+ l = input()
+ except EOFError:
+ break
+ f.write(l)
+ f.write("\n")