# -*- coding: utf-8 -*- """把活代码里的 LanRemote-Agent 统一改成 ykxmz。 跳过 _build/patch_*.py —— 那些是历史补丁的记录,改了反而对不上账。 """ from __future__ import annotations import re import sys from pathlib import Path ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote") # 替换规则(注意顺序:长的先来) RULES = [ ("LanRemote-Agent.exe", "ykxmz.exe"), ("LanRemote-Agent-Windows.zip", "ykxmz-Windows.zip"), ('dist_exe" / "LanRemote-Agent"', 'dist_exe" / "ykxmz"'), ("dist_exe\\LanRemote-Agent", "dist_exe\\ykxmz"), ("dist_exe/LanRemote-Agent", "dist_exe/ykxmz"), ("LanRemote-Agent\\", "ykxmz\\"), ('"LanRemote-Agent"', '"ykxmz"'), ("LanRemote-Agent 那个目录", "ykxmz 那个目录"), ("LanRemote-Agent 目录", "ykxmz 目录"), ] # 要改的文件(活代码) TARGETS = [ ROOT / "windows" / "run_agent.py", ROOT / "windows" / "lanremote" / "ui.py", ROOT / "windows" / "lanremote" / "netcheck.py", ROOT / "windows" / "lanremote" / "features.py", ROOT / "windows" / "lanremote" / "firewall.py", ROOT / "_build" / "package_remote.py", ROOT / "_build" / "package.py", ROOT / "_build" / "make_fix_bat.py", ROOT / "_build" / "make_toolbox.py", ROOT / "_build" / "rename_tools.py", ROOT / "_build" / "make_exe_fix.py", ROOT / "_build" / "test_resolve.py", ROOT / "_build" / "test_resolve2.py", ROOT / "_build" / "test_file_pull.py", ROOT / "_tests" / "test_e2e_features.py", ROOT / "_tests" / "test_package_remote.py", ROOT / "_tests" / "test_clip_push_safe.py", ROOT / "_tests" / "diag_all_commands.py", ROOT / "_tests" / "acceptance.py", ROOT / "_tests" / "test_firewall.py", ] def main() -> int: total = 0 touched = [] for path in TARGETS: if not path.is_file(): continue text = path.read_text(encoding="utf-8") original = text for old, new in RULES: if old in text: text = text.replace(old, new) if text != original: path.write_text(text, encoding="utf-8", newline="\n") count = sum(original.count(o) for o, _ in RULES if o in original) touched.append((path.name, count)) total += count for name, count in touched: print(f" {name}: {count} 处") print(f" 合计 {total} 处,{len(touched)} 个文件") # 语法检查(只查 Python) import ast bad = [] for path in TARGETS: if path.suffix != ".py" or not path.is_file(): continue try: ast.parse(path.read_text(encoding="utf-8")) except SyntaxError as exc: bad.append((path, exc)) if bad: for path, exc in bad: print(f" [坏] {path.name}: 行 {exc.lineno}: {exc.msg}") return 1 print(" 所有 Python 文件语法正常") # 确认活代码里没有残留(排除历史补丁) left = [] for path in ROOT.rglob("*.py"): rel = str(path.relative_to(ROOT)) if rel.startswith("_build") and path.name.startswith("patch_"): continue if rel.startswith("_build") and path.name.startswith( ("add_", "fix_", "rename_to_", "rename_tools")): continue text = path.read_text(encoding="utf-8", errors="replace") if "LanRemote-Agent.exe" in text: left.append(rel) if left: print(f" 还有 {len(left)} 个文件残留 LanRemote-Agent.exe:") for item in left[:10]: print(f" {item}") else: print(" 没有残留 ✓") return 0 if __name__ == "__main__": sys.exit(main())