esp8266/modules/webrepl_setup: Fix first-time enable of WebREPL.

Prior to this fix, enabling WebREPL for the first time via webrepl_setup
did not work at all because "boot.py" did not contain any lines with
"webrepl" in them that could be uncommented.
This commit is contained in:
Damien George 2017-11-30 10:54:33 +11:00
parent 74fad3536b
commit 4e056d82cc
1 changed files with 4 additions and 10 deletions

View File

@ -35,12 +35,6 @@ def exists(fname):
except OSError: except OSError:
return False return False
def copy_stream(s_in, s_out):
buf = bytearray(64)
while 1:
sz = s_in.readinto(buf)
s_out.write(buf, sz)
def get_daemon_status(): def get_daemon_status():
with open(RC) as f: with open(RC) as f:
@ -51,22 +45,22 @@ def get_daemon_status():
return True return True
return None return None
def add_daemon():
with open(RC) as old_f, open(RC + ".tmp", "w") as new_f:
new_f.write("import webrepl\nwebrepl.start()\n")
copy_stream(old_f, new_f)
def change_daemon(action): def change_daemon(action):
LINES = ("import webrepl", "webrepl.start()") LINES = ("import webrepl", "webrepl.start()")
with open(RC) as old_f, open(RC + ".tmp", "w") as new_f: with open(RC) as old_f, open(RC + ".tmp", "w") as new_f:
found = False
for l in old_f: for l in old_f:
for patt in LINES: for patt in LINES:
if patt in l: if patt in l:
found = True
if action and l.startswith("#"): if action and l.startswith("#"):
l = l[1:] l = l[1:]
elif not action and not l.startswith("#"): elif not action and not l.startswith("#"):
l = "#" + l l = "#" + l
new_f.write(l) new_f.write(l)
if not found:
new_f.write("import webrepl\nwebrepl.start()\n")
# FatFs rename() is not POSIX compliant, will raise OSError if # FatFs rename() is not POSIX compliant, will raise OSError if
# dest file exists. # dest file exists.
os.remove(RC) os.remove(RC)