Files
WiFiManager/tools/migrate_debug_wm.py
T
alex ac42d9a342 WiFiManager: structured logging, SPA portal, DFTE bridge.
Replace DEBUG_WM with WiFiManagerLogLevel/log(), optional WiFiManagerLogSink,
and WM_NO_LOG stripping. Add JSON API handlers and shell templates (RootShell,
PortalAppJS). Bridge DFTE logging with owner-scoped teardown; add migrate_debug_wm
helper; document and set WM_LOG_LEVEL in platformio.
2026-04-20 23:28:57 +10:00

52 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""One-shot migration: DEBUG_WM -> WiFiManager::log(...). Run from repo root."""
import re
import sys
SUB = "kWiFiMgrLogSubsystem"
REPLACEMENTS = [
# Longest / most specific first (with optional whitespace)
(r"_wm->\s*DEBUG_WM\s*\(\s*WM_DEBUG_ERROR\s*,", f"_wm->log(WiFiManagerLogLevel::Error, {SUB},"),
(r"_wm->\s*DEBUG_WM\s*\(\s*WM_DEBUG_VERBOSE\s*,", f"_wm->log(WiFiManagerLogLevel::Debug, {SUB},"),
(r"_wm->\s*DEBUG_WM\s*\(\s*WM_DEBUG_DEV\s*,", f"_wm->log(WiFiManagerLogLevel::Trace, {SUB},"),
(r"_wm->\s*DEBUG_WM\s*\(\s*WM_DEBUG_NOTIFY\s*,", f"_wm->log(WiFiManagerLogLevel::Info, {SUB},"),
(r"_wm->\s*DEBUG_WM\s*\(\s*WM_DEBUG_MAX\s*,", f"_wm->log(WiFiManagerLogLevel::Trace, {SUB},"),
(r"DEBUG_WM\s*\(\s*WM_DEBUG_ERROR\s*,", f"log(WiFiManagerLogLevel::Error, {SUB},"),
(r"DEBUG_WM\s*\(\s*WM_DEBUG_VERBOSE\s*,", f"log(WiFiManagerLogLevel::Debug, {SUB},"),
(r"DEBUG_WM\s*\(\s*WM_DEBUG_DEV\s*,", f"log(WiFiManagerLogLevel::Trace, {SUB},"),
(r"DEBUG_WM\s*\(\s*WM_DEBUG_NOTIFY\s*,", f"log(WiFiManagerLogLevel::Info, {SUB},"),
(r"DEBUG_WM\s*\(\s*WM_DEBUG_MAX\s*,", f"log(WiFiManagerLogLevel::Trace, {SUB},"),
# Default / notify-level (no explicit WM_DEBUG_* level)
(r"_wm->\s*DEBUG_WM\s*\(\s*F\(", f"_wm->log(WiFiManagerLogLevel::Info, {SUB}, F("),
(r"DEBUG_WM\s*\(\s*F\(", f"log(WiFiManagerLogLevel::Info, {SUB}, F("),
(r"_wm->\s*DEBUG_WM\s*\(", f"_wm->log(WiFiManagerLogLevel::Info, {SUB}, "),
(r"DEBUG_WM\s*\(", f"log(WiFiManagerLogLevel::Info, {SUB}, "),
]
def migrate(content: str) -> str:
content = content.replace("#ifdef WM_DEBUG_LEVEL", "#ifndef WM_NO_LOG")
content = content.replace("#ifdef WM_DEBUG_LEVEL", "#ifndef WM_NO_LOG")
for pat, repl in REPLACEMENTS:
content = re.sub(pat, repl, content)
return content
def main():
for path in sys.argv[1:]:
with open(path, "r", encoding="utf-8") as f:
old = f.read()
new = migrate(old)
if new != old:
with open(path, "w", encoding="utf-8") as f:
f.write(new)
print(f"updated: {path}")
else:
print(f"unchanged: {path}")
if __name__ == "__main__":
main()