fix tilda-tools bootstrap

tildatorch
Marek Ventur 2018-08-28 18:44:53 +01:00
parent 1ef5e7786f
commit be985b3240
5 changed files with 56 additions and 5 deletions

View File

@ -29,6 +29,12 @@ def makedirs(path):
if not exists(path):
os.mkdir(path)
def isdir(path):
try:
return os.stat(path)[0] & 0o170000 == 0o040000
except OSError:
return False
def h(p):
try:
with open(p, "rb") as f:
@ -49,3 +55,18 @@ def w(p, c):
except Exception as e:
print(str(e))
return None
def clean(path=""):
for s in os.listdir(path):
full = "/".join([path, s]) if path else s
try:
if isdir(full):
try:
clean(full)
except:
pass
os.rmdir(full)
else:
os.remove(full)
except Exception as e:
print("Error while trying to clean '%s'" % full)

View File

@ -187,4 +187,32 @@ def end_copy_via_repl(args):
pass
def clean_via_repl(args):
raise Exception("not implemented yet")
init_copy_via_repl(args)
print("Cleaning:", end=" ", flush=True)
try:
execbuffer(get_pyb(args), "clean()")
except PyboardError as er:
print("FAIL")
print(er)
pyb.close()
sys.exit(1)
print("DONE")
def hard_reset(args):
pyb = get_pyb(args)
print("Hard reset:", end=" ", flush=True)
try:
pyb.enter_raw_repl()
execbuffer(pyb, "import machine\nmachine.reset()\n")
print("UNEXPECTED")
except PyboardError as er:
print("FAIL")
print(er)
pyb.close()
sys.exit(1)
except Exception as e:
if "Errno 6" in str(e):
print("DONE")
else:
raise e

View File

@ -58,9 +58,7 @@ def sync(args, patterns, resources, verbose, skip_wifi):
return synced_resources
def clean(args):
print("Cleaning:", end=" ", flush=True)
pyboard_util.clean_via_repl(args)
print("DONE")
def set_boot_app(args, app_to_boot):
content = app_to_boot + "\n"

View File

@ -119,7 +119,7 @@ def main():
if command == "bootstrap":
sync.clean(args)
sync.sync(args, ["bootstrap.py"], {}, args.verbose, args.skip_wifi)
pyboard_util.soft_reset(args)
pyboard_util.hard_reset(args)
if command == "sync":
if args.clean:

View File

@ -1,5 +1,6 @@
import os, tilda
print("EMF: boot.py")
os.sync()
root = os.listdir()
@ -23,9 +24,12 @@ def any_home():
return h[0] if len(h) else False
if "no_boot" in root:
print("no_boot found, aborting boot sequence")
else:
start = None
if "main.py" in root:
start = "main.py"
start = file("once.txt", True) or file("default_app.txt", False) or any_home() or "bootstrap.py"
start = start or file("once.txt", True) or file("default_app.txt", False) or any_home() or "bootstrap.py"
print("Booting into %s" % start)
tilda.main(start)