From 4e056d82cc7cfa1b40c135e1ac544d728231432e Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 30 Nov 2017 10:54:33 +1100 Subject: [PATCH] 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. --- ports/esp8266/modules/webrepl_setup.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/ports/esp8266/modules/webrepl_setup.py b/ports/esp8266/modules/webrepl_setup.py index 5288c49c0c..129313a21c 100644 --- a/ports/esp8266/modules/webrepl_setup.py +++ b/ports/esp8266/modules/webrepl_setup.py @@ -35,12 +35,6 @@ def exists(fname): except OSError: 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(): with open(RC) as f: @@ -51,22 +45,22 @@ def get_daemon_status(): return True 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): LINES = ("import webrepl", "webrepl.start()") with open(RC) as old_f, open(RC + ".tmp", "w") as new_f: + found = False for l in old_f: for patt in LINES: if patt in l: + found = True if action and l.startswith("#"): l = l[1:] elif not action and not l.startswith("#"): l = "#" + 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 # dest file exists. os.remove(RC)