|
1 | 1 | # pio-scripts/inject_syslog_ui.py |
2 | | -import os, shutil, sys |
| 2 | +import os, shutil |
3 | 3 | from SCons.Script import Import |
4 | 4 |
|
5 | 5 | Import("env") |
@@ -117,7 +117,8 @@ def inject_syslog_ui(source, target, env): |
117 | 117 | print("Backing up and injecting Syslog UI...") |
118 | 118 | shutil.copyfile(html_path, bak) |
119 | 119 | try: |
120 | | - original = open(html_path, 'r', encoding='utf8').read() |
| 120 | + with open(html_path, 'r', encoding='utf8') as f: |
| 121 | + original = f.read() |
121 | 122 | modified = original |
122 | 123 |
|
123 | 124 | # replace existing section if present |
@@ -146,8 +147,20 @@ def inject_syslog_ui(source, target, env): |
146 | 147 | print("\033[42mSyslog UI injected successfully!\033[0m") |
147 | 148 | except Exception as e: |
148 | 149 | 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) |
149 | 153 | else: |
150 | 154 | 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.") |
151 | 164 |
|
152 | 165 | def restore_syslog_ui(source, target, env): |
153 | 166 | print("\033[44m==== inject_syslog_ui.py (POST BUILD) ====\033[0m") |
|
0 commit comments