# -*- coding: utf-8 -*- """把 APK 名字统一成 ykxmz-watch,并修掉测试里的硬编码旧名。 用户要求:"名字不要带中文,就 ykxmz" APK 现在叫 LanRemote-Watch-1.4.0.apk —— 是新名之前留下的, 和 ykxmz 不一致。改成 ykxmz-watch-1.4.0.apk。 顺带: * test_apk_contents.py 里硬编码了 1.3.0,改成跟着版本走 * 两个测试都改成"扫 dist 目录找最新 apk",别再写死版本号 (写死的老是升级一次就坏一次,已经踩过好几回了) """ from __future__ import annotations import sys from pathlib import Path ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote") BUILD = ROOT / "android" / "build_apk.ps1" PKG = ROOT / "_build" / "package_remote.py" APK_TEST = ROOT / "_tests" / "test_apk_contents.py" NEW_NAME = "ykxmz-watch-1.4.0.apk" def main() -> int: ok = True # ---------- 1. build_apk.ps1(保持 BOM)---------- raw = BUILD.read_bytes() had_bom = raw.startswith(b"\xef\xbb\xbf") text = raw.decode("utf-8-sig") old = '$apkName = "LanRemote-Watch-1.4.0.apk"' new = '$apkName = "ykxmz-watch-1.4.0.apk"' if old in text: text = text.replace(old, new, 1) BUILD.write_bytes((b"\xef\xbb\xbf" if had_bom else b"") + text.replace("\r\n", "\n").encode("utf-8")) print(f" build_apk.ps1: APK 改名(BOM {'保留' if had_bom else '无'})") elif new in text: print(" build_apk.ps1: 已经是新名") else: print(" [失败] build_apk.ps1 找不到 apkName") ok = False # ---------- 2. package_remote.py ---------- text = PKG.read_text(encoding="utf-8") old = 'APK_SRC = ROOT / "dist" / f"LanRemote-Watch-{VERSION}.apk"' new = 'APK_SRC = ROOT / "dist" / f"ykxmz-watch-{VERSION}.apk"' if old in text: text = text.replace(old, new, 1) PKG.write_text(text, encoding="utf-8", newline="\n") print(" package_remote.py: APK 路径已更新") elif new in text: print(" package_remote.py: 已经是新名") else: print(" [警告] package_remote.py 里没找到 APK_SRC") # ---------- 3. test_apk_contents.py ---------- text = APK_TEST.read_text(encoding="utf-8") old = 'APK = ROOT / "dist" / "LanRemote-Watch-1.3.0.apk"' new = '''# 别写死版本号 —— 一升级就坏(这坑踩过好几回了)。 # 直接扫 dist 里最新的手表 APK。 def _latest_apk() -> Path: candidates = sorted( (ROOT / "dist").glob("*watch*.apk"), key=lambda p: p.stat().st_mtime, reverse=True) return candidates[0] if candidates else \\ ROOT / "dist" / "ykxmz-watch-1.4.0.apk" APK = _latest_apk()''' if old in text: text = text.replace(old, new, 1) APK_TEST.write_text(text, encoding="utf-8", newline="\n") print(" test_apk_contents.py: 改成动态找最新 APK") else: print(" [警告] test_apk_contents.py 锚点没找到") # ---------- 4. 语法 ---------- import ast for label, path in (("package_remote.py", PKG), ("test_apk_contents.py", APK_TEST)): try: ast.parse(path.read_text(encoding="utf-8")) print(f" {label} 语法 OK") except SyntaxError as exc: print(f" {label} 语法错误: {exc}") ok = False # ---------- 5. 删掉旧的 1.4.0 apk ---------- for stale in ("LanRemote-Watch-1.4.0.apk", "LanRemote-Watch-1.4.0.apk.idsig"): path = ROOT / "dist" / stale if path.exists(): path.unlink() print(f" 删掉旧文件 {stale}") return 0 if ok else 1 if __name__ == "__main__": sys.exit(main())