Skip to content
Snippets Groups Projects
Commit 06624532 authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

wip

parent 6788e263
No related branches found
No related tags found
No related merge requests found
...@@ -3,8 +3,11 @@ ...@@ -3,8 +3,11 @@
# upy.py: raw REPL tool # upy.py: raw REPL tool
# udp.py port ls # udp.py port ls
# udp.py port run file.py # udp.py port run file.py
# runs in RAM
# udp.py port put file.py # udp.py port put file.py
# use single quotes for triple quote strings # 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 get file.py
# udp.py port rm file.py # udp.py port rm file.py
# #
...@@ -28,6 +31,7 @@ s.write(b'\x01') # ^a enter raw mode ...@@ -28,6 +31,7 @@ s.write(b'\x01') # ^a enter raw mode
while (s.in_waiting > 0): # clear buffer while (s.in_waiting > 0): # clear buffer
s.read() s.read()
if (sys.argv[2] == 'run'): if (sys.argv[2] == 'run'):
s.write(b'\x03') # ^c interrupt
file = open(sys.argv[3],'r') file = open(sys.argv[3],'r')
str = file.read() str = file.read()
file.close() file.close()
...@@ -38,6 +42,7 @@ if (sys.argv[2] == 'run'): ...@@ -38,6 +42,7 @@ if (sys.argv[2] == 'run'):
while (True): # show output while (True): # show output
sys.stdout.write(s.read().decode('utf-8')) sys.stdout.write(s.read().decode('utf-8'))
elif (sys.argv[2] == 'ls'): elif (sys.argv[2] == 'ls'):
s.write(b'\x03') # ^c interrupt
s.write(b'import os\n') s.write(b'import os\n')
s.write(b'files = os.listdir()\n') s.write(b'files = os.listdir()\n')
s.write(b'print("")\n') s.write(b'print("")\n')
...@@ -49,11 +54,15 @@ elif (sys.argv[2] == 'ls'): ...@@ -49,11 +54,15 @@ elif (sys.argv[2] == 'ls'):
sys.stdout.write(s.read().decode('utf-8')) sys.stdout.write(s.read().decode('utf-8'))
print('') print('')
elif (sys.argv[2] == 'put'): elif (sys.argv[2] == 'put'):
s.write(b'\x03') # ^c interrupt
file = open(sys.argv[3],'r') file = open(sys.argv[3],'r')
str = file.read() str = file.read()
file.close() file.close()
s.write(bytes(f'str = """{str}"""\n','ascii')) s.write(bytes(f'str = """{str}"""\n','ascii'))
if (len(sys.argv) == 4):
s.write(bytes(f'file = open("{sys.argv[3]}","w")\n','ascii')) 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.write(str)\n')
s.write(b'file.close()\n') s.write(b'file.close()\n')
s.write(b'del str\n') s.write(b'del str\n')
...@@ -63,6 +72,7 @@ elif (sys.argv[2] == 'put'): ...@@ -63,6 +72,7 @@ elif (sys.argv[2] == 'put'):
sys.stdout.write(s.read().decode('utf-8')) sys.stdout.write(s.read().decode('utf-8'))
print('') print('')
elif (sys.argv[2] == 'get'): 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(bytes(f'file = open("{sys.argv[3]}","r")\n','ascii'))
s.write(b'print(file.read())\n') s.write(b'print(file.read())\n')
s.write(b'file.close()\n') s.write(b'file.close()\n')
...@@ -72,6 +82,7 @@ elif (sys.argv[2] == 'get'): ...@@ -72,6 +82,7 @@ elif (sys.argv[2] == 'get'):
sys.stdout.write(s.read().decode('utf-8')) sys.stdout.write(s.read().decode('utf-8'))
print('') print('')
elif (sys.argv[2] == 'rm'): elif (sys.argv[2] == 'rm'):
s.write(b'\x03') # ^c interrupt
s.write(b'import os\n') s.write(b'import os\n')
s.write(bytes(f'os.remove("{sys.argv[3]}")\n','ascii')) s.write(bytes(f'os.remove("{sys.argv[3]}")\n','ascii'))
s.write(b'\x04') # ^d exit raw mode and execute s.write(b'\x04') # ^d exit raw mode and execute
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment