From 066245324f0427c4ee3b47b97f883ca53d0a3b18 Mon Sep 17 00:00:00 2001
From: Neil Gershenfeld <gersh@cba.mit.edu>
Date: Wed, 5 Jul 2023 21:28:09 -0400
Subject: [PATCH] wip

---
 upy.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/upy.py b/upy.py
index 4a33a96..3b0365f 100755
--- a/upy.py
+++ b/upy.py
@@ -3,8 +3,11 @@
 # upy.py: raw REPL tool
 #    udp.py port ls
 #    udp.py port run file.py
+#       runs in RAM
 #    udp.py port put file.py
 #       use single quotes for triple quote strings
+#    udp.py port put file.py code.py
+#       to rename file; code.py to run at boot
 #    udp.py port get file.py
 #    udp.py port rm file.py
 #
@@ -28,6 +31,7 @@ s.write(b'\x01') # ^a enter raw mode
 while (s.in_waiting > 0): # clear buffer
    s.read()
 if (sys.argv[2] == 'run'):
+   s.write(b'\x03') # ^c interrupt
    file = open(sys.argv[3],'r')
    str = file.read()
    file.close()
@@ -38,6 +42,7 @@ if (sys.argv[2] == 'run'):
    while (True): # show output
       sys.stdout.write(s.read().decode('utf-8'))
 elif (sys.argv[2] == 'ls'):
+   s.write(b'\x03') # ^c interrupt
    s.write(b'import os\n')
    s.write(b'files = os.listdir()\n')
    s.write(b'print("")\n')
@@ -49,11 +54,15 @@ elif (sys.argv[2] == 'ls'):
       sys.stdout.write(s.read().decode('utf-8'))
    print('')
 elif (sys.argv[2] == 'put'):
+   s.write(b'\x03') # ^c interrupt
    file = open(sys.argv[3],'r')
    str = file.read()
    file.close()
    s.write(bytes(f'str = """{str}"""\n','ascii'))
-   s.write(bytes(f'file = open("{sys.argv[3]}","w")\n','ascii'))
+   if (len(sys.argv) == 4):
+      s.write(bytes(f'file = open("{sys.argv[3]}","w")\n','ascii'))
+   elif (len(sys.argv) == 5):
+      s.write(bytes(f'file = open("{sys.argv[4]}","w")\n','ascii'))
    s.write(b'file.write(str)\n')
    s.write(b'file.close()\n')
    s.write(b'del str\n')
@@ -63,6 +72,7 @@ elif (sys.argv[2] == 'put'):
       sys.stdout.write(s.read().decode('utf-8'))
    print('')
 elif (sys.argv[2] == 'get'):
+   s.write(b'\x03') # ^c interrupt
    s.write(bytes(f'file = open("{sys.argv[3]}","r")\n','ascii'))
    s.write(b'print(file.read())\n')
    s.write(b'file.close()\n')
@@ -72,6 +82,7 @@ elif (sys.argv[2] == 'get'):
       sys.stdout.write(s.read().decode('utf-8'))
    print('')
 elif (sys.argv[2] == 'rm'):
+   s.write(b'\x03') # ^c interrupt
    s.write(b'import os\n')
    s.write(bytes(f'os.remove("{sys.argv[3]}")\n','ascii'))
    s.write(b'\x04') # ^d exit raw mode and execute
-- 
GitLab