Skip to content

Commit 4e056d8

Browse files
committed
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.
1 parent 74fad35 commit 4e056d8

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

ports/esp8266/modules/webrepl_setup.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ def exists(fname):
3535
except OSError:
3636
return False
3737

38-
def copy_stream(s_in, s_out):
39-
buf = bytearray(64)
40-
while 1:
41-
sz = s_in.readinto(buf)
42-
s_out.write(buf, sz)
43-
4438

4539
def get_daemon_status():
4640
with open(RC) as f:
@@ -51,22 +45,22 @@ def get_daemon_status():
5145
return True
5246
return None
5347

54-
def add_daemon():
55-
with open(RC) as old_f, open(RC + ".tmp", "w") as new_f:
56-
new_f.write("import webrepl\nwebrepl.start()\n")
57-
copy_stream(old_f, new_f)
5848

5949
def change_daemon(action):
6050
LINES = ("import webrepl", "webrepl.start()")
6151
with open(RC) as old_f, open(RC + ".tmp", "w") as new_f:
52+
found = False
6253
for l in old_f:
6354
for patt in LINES:
6455
if patt in l:
56+
found = True
6557
if action and l.startswith("#"):
6658
l = l[1:]
6759
elif not action and not l.startswith("#"):
6860
l = "#" + l
6961
new_f.write(l)
62+
if not found:
63+
new_f.write("import webrepl\nwebrepl.start()\n")
7064
# FatFs rename() is not POSIX compliant, will raise OSError if
7165
# dest file exists.
7266
os.remove(RC)

0 commit comments

Comments
 (0)