Skip to content

Commit 238e1c4

Browse files
authored
syslog inject fix / coderabbit improments
1 parent a77b85a commit 238e1c4

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

pio-scripts/inject_syslog_ui.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ def set_syslog_state(project_dir, enabled):
3131
f.write("1" if enabled else "0")
3232

3333
# This is the HTML we want to inject
34-
SYSLOG_HTML = """
35-
<h3>Syslog</h3>
34+
SYSLOG_HTML = """<h3>Syslog</h3>
3635
<div id="Syslog">
3736
Enable Syslog: <input type="checkbox" name="SL_en"><br>
3837
Host: <input type="text" name="SL_host" maxlength="32"><br>
3938
Port: <input type="number" name="SL_port" min="1" max="65535" value="%SL_port%"><br>
40-
</div>
41-
"""
39+
</div>"""
4240

4341
def inject_syslog_ui(source, target, env, retry_count=0):
4442
print("\033[44m==== inject_syslog_ui.py (PRE BUILD) ====\033[0m")
@@ -50,7 +48,7 @@ def inject_syslog_ui(source, target, env, retry_count=0):
5048
build_flags = env.get("BUILD_FLAGS", "")
5149
if isinstance(build_flags, list):
5250
build_flags = " ".join(build_flags)
53-
has_syslog = bool(re.search(r'-D\s*WLED_ENABLE_SYSLOG', build_flags))
51+
has_syslog = bool(re.search(r'-D\s*WLED_ENABLE_SYSLOG\b', build_flags))
5452

5553
project_dir = env.subst("$PROJECT_DIR")
5654
html_path = os.path.join(project_dir, "wled00/data/settings_sync.htm")
@@ -92,6 +90,9 @@ def inject_syslog_ui(source, target, env, retry_count=0):
9290
idx = modified.rfind('<hr>')
9391
if idx == -1:
9492
print("\033[41mCould not find <hr> to insert Syslog UI!\033[0m")
93+
# Clean up backup since injection failed
94+
if os.path.exists(bak):
95+
os.remove(bak)
9596
return
9697
modified = (
9798
modified[:idx]
@@ -118,7 +119,7 @@ def inject_syslog_ui(source, target, env, retry_count=0):
118119
# verify that SYSLOG markers really are in the file
119120
with open(html_path, 'r', encoding='utf8') as f:
120121
content = f.read()
121-
if '<!-- SYSLOG-INJECT -->' not in content:
122+
if '<h3>Syslog</h3>' not in content:
122123
print("Backup exists but SYSLOG markers missing—forcing re-injection.")
123124
os.remove(bak)
124125
# only retry up to 3 times
@@ -141,8 +142,6 @@ def restore_syslog_ui(source, target, env):
141142
# restore only if backup file is present
142143
if os.path.exists(bak):
143144
print("Restoring original file from backup...")
144-
if os.path.exists(html_path):
145-
os.chmod(html_path, 0o644)
146145
shutil.copy2(bak, html_path)
147146
os.remove(bak)
148147

0 commit comments

Comments
 (0)