This repository was archived by the owner on Apr 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpython.py
88 lines (65 loc) · 1.69 KB
/
python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import computer
import micropython
import uos
from ucode import repl_input, repl_compile, repl_call
class Command:
def __init__(self, func):
self.func = func
def __call__(self, *args, **kwargs):
return self.func(*args, **kwargs)
def __repr__(self):
result = self.func()
if result is None:
# monitor.heightPos -= 1
return ""
else:
return result
def _listdir(path="/"):
print([path for path, *_ in uos.ilistdir(path)])
def _cls():
pass
# monitor.widthPos = 1
# monitor.heightPos = 1
# gpu.fill(1, 1, monitor.widthSize, monitor.heightSize, " ")
def mem_info():
import gc
gc.collect()
micropython.mem_info()
def _show(name=None):
if name is None:
help("modules")
return
module = __import__(name)
help(module)
commands = dict(
listdir=Command(_listdir),
cls=Command(_cls),
mem=Command(mem_info),
help=Command(help),
show=Command(_show),
reboot=Command(computer.reboot),
)
def main():
context = {"__name__": "<shell>"}
context.update(commands)
while True:
try:
code = repl_input()
except Exception as e:
print(type(e).__name__, e)
continue
if code == 'exit':
break
try:
func = repl_compile(code, context)
except SystemExit as e:
return e.args[0] if e.args else 0
except Exception as e:
print(type(e).__name__, e)
continue
try:
repl_call(func, context)
except BaseException as e:
print(type(e).__name__, e)
if __name__ == '__main__':
main()