summaryrefslogtreecommitdiff
path: root/ports/esp8266/modules/webrepl_setup.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-11-30 10:54:33 +1100
committerDamien George <damien.p.george@gmail.com>2017-11-30 10:54:33 +1100
commit4e056d82cc7cfa1b40c135e1ac544d728231432e (patch)
tree8bba016289afb24fe66dfc9c24d244013c364573 /ports/esp8266/modules/webrepl_setup.py
parent74fad3536b961e2ffe08e545b1cf787c0c0b4772 (diff)
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.
Diffstat (limited to 'ports/esp8266/modules/webrepl_setup.py')
-rw-r--r--ports/esp8266/modules/webrepl_setup.py14
1 files changed, 4 insertions, 10 deletions
diff --git a/ports/esp8266/modules/webrepl_setup.py b/ports/esp8266/modules/webrepl_setup.py
index 5288c49c0..129313a21 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)