forked from emfcamp/Mk4-Apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot.py
46 lines (39 loc) · 1.05 KB
/
boot.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
import os, tilda
from machine import Neopix
n=Neopix()
n.display([0,0,0])
n.display([0,0,0])
print("EMF: boot.py")
os.sync()
root = os.listdir()
def app(a):
if (a in root) and ("main.py" in os.listdir(a)):
return a + "/main.py"
def file(file, remove):
try:
a = None
with open(file, 'r') as f:
a = f.read().strip()
if remove:
os.remove(file)
return app(a)
except Exception as e:
print("Not found: %s" % file)
def any_home():
h = [a for a in root if a.startswith("home")]
return h[0] if len(h) else False
if "no_boot" in root:
os.remove("no_boot")
print("no_boot found, aborting boot sequence")
elif "bootstrap.py" in root:
print("Bootstrapping...")
tilda.main("bootstrap.py")
else:
start = None
if "main.py" in root:
start = "main.py"
start = start or file("once.txt", True) or file("default_app.txt", False) or any_home()
if ".py" not in start:
start += "/main.py"
print("Booting into %s" % start)
tilda.main(start)