helloworld / deploy /patches /apply_wm_patch.py
eduzrh's picture
Upload deploy/patches/apply_wm_patch.py with huggingface_hub
e25a3ae verified
Raw History Blame Contribute Delete
1.3 kB
#!/usr/bin/env python3
"""把本地化/默认值补丁写进 worldmonitor 的 index.html(幂等)。
用法:python3 apply_wm_patch.py /data/apps/worldmonitor
"""
import re
import sys
from pathlib import Path
root = Path(sys.argv[1] if len(sys.argv) > 1 else "/data/apps/worldmonitor")
here = Path(__file__).resolve().parent
index = root / "index.html"
html = index.read_text(encoding="utf-8")
head = (here / "wm_head_injection.html").read_text(encoding="utf-8")
dock = (here / "wm_body_dock.html").read_text(encoding="utf-8")
if not index.with_suffix(".html.prezh").exists():
index.with_suffix(".html.prezh").write_text(html, encoding="utf-8")
# 清掉之前注入过的单行 locale 脚本与旧补丁块
html = re.sub(r'<script data-wm-locale-default>.*?</script>\n?', "", html, flags=re.S)
html = re.sub(r'<!--\n World Monitor 本地化与默认值补丁.*?</style>\n?', "", html, flags=re.S)
html = re.sub(r'<!-- 版本切换浮标.*?</nav>\n?', "", html, flags=re.S)
anchor = '<script data-wm-map-prepaint>'
assert anchor in html, "找不到 prepaint 脚本锚点"
html = html.replace(anchor, head + "\n" + anchor, 1)
assert "</body>" in html
html = html.replace("</body>", dock + "\n</body>", 1)
index.write_text(html, encoding="utf-8")
print("patched", index, len(html))