Skip to content

Commit cbee84e

Browse files
authored
coderabbitai improvements
1 parent 070b6b2 commit cbee84e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pio-scripts/inject_syslog_ui.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pio-scripts/inject_syslog_ui.py
2-
import os, shutil, sys
2+
import os, shutil
33
from SCons.Script import Import
44

55
Import("env")
@@ -117,7 +117,8 @@ def inject_syslog_ui(source, target, env):
117117
print("Backing up and injecting Syslog UI...")
118118
shutil.copyfile(html_path, bak)
119119
try:
120-
original = open(html_path, 'r', encoding='utf8').read()
120+
with open(html_path, 'r', encoding='utf8') as f:
121+
original = f.read()
121122
modified = original
122123

123124
# replace existing section if present
@@ -146,8 +147,20 @@ def inject_syslog_ui(source, target, env):
146147
print("\033[42mSyslog UI injected successfully!\033[0m")
147148
except Exception as e:
148149
print(f"\033[41mError during injection: {e}\033[0m")
150+
# injection failed → remove backup so we’ll retry next time
151+
if os.path.exists(bak):
152+
os.remove(bak)
149153
else:
150154
print("Backup exists; assume already injected.")
155+
# verify that SYSLOG markers really are in the file
156+
with open(html_path, 'r', encoding='utf8') as f:
157+
content = f.read()
158+
if '<!-- SYSLOG-START -->' not in content or '<!-- SYSLOG-END -->' not in content:
159+
print("Backup exists but SYSLOG markers missing—forcing re-injection.")
160+
os.remove(bak)
161+
inject_syslog_ui(source, target, env)
162+
else:
163+
print("Backup exists and markers found; already injected.")
151164

152165
def restore_syslog_ui(source, target, env):
153166
print("\033[44m==== inject_syslog_ui.py (POST BUILD) ====\033[0m")

0 commit comments

Comments
 (0)