This repository has been 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 pathinit.py
69 lines (48 loc) · 1.52 KB
/
init.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
"""OpenPython Operating System"""
import sys
import machine
import uos
from ucomponent import invoke
from uio import FileIO
class FileSystem:
def __init__(self, address):
self.address = address
def mount(self, readonly, mkfs):
pass
def umount(self):
pass
def getcwd(self):
return '/'
def ilistdir(self, dir):
for name in invoke(self.address, 'list', dir):
if invoke(self.address, 'isDirectory', dir + "/" + name):
yield (name, 0x4000, 0, -1)
else:
yield (name, 0x8000, 0, 0)
def stat(self, path):
if not invoke(self.address, 'exists', path):
raise OSError(1)
return 0x4000 if invoke(self.address, 'isDirectory', path) else 0x8000, 0, 0, 0, 0, 0, 0, 0, 0, 0
def open(self, file, mode):
return FileIO(self.address, file, mode)
@machine.hook_stdin
def input_handler():
return 0
@machine.hook_stdout
def print_handler(string):
machine.debug(string)
def init():
uos.mount(FileSystem(__path__), '/')
sys.path.append('/lib')
sys.path.append('/lib/internal')
sys.path.append('/lib/openos')
sys.path.append('/usr/lib')
sys.path.append('/lib/micropython')
for filename in sorted(uos.listdir("/boot")):
context = {'__name__': '__main__', '__path__': __path__}
# noinspection PyUnresolvedReferences
execfile("/boot/" + filename, context)
from shell import spawn
spawn("/bin/shell.py")
if __name__ == "__main__":
init()