mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 18:20:43 +00:00
1.7.0:常规发布
- 版本号 1.7.0 -> 1.7.0 - 重建三端并打包 - 关键测试全过
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
r"""给被控端加 --code / --name,供安装包调用。
|
||||
|
||||
为什么需要:
|
||||
安装向导里用户填了 6 位配对码,安装程序必须把它传给被控端。
|
||||
但命令行原来只有 --new-code(随机换一个),**没有"设成指定值"** ——
|
||||
所以用户填的码会被忽略,装完还得再跑一次设置窗口。
|
||||
|
||||
加了之后安装程序可以这样一条命令搞定:
|
||||
ykxmz.exe --code 789113 --name 三年二班 --autostart on --silent
|
||||
|
||||
--code 同时会标记 setup_done,这样就不会再弹设置窗口。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
RUN = (Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\windows"
|
||||
r"\run_agent.py"))
|
||||
|
||||
# ---------- 1. 参数声明 ----------
|
||||
|
||||
OLD_ARG = ''' parser.add_argument("--new-code", action="store_true", help="换一组配对码")'''
|
||||
|
||||
NEW_ARG = ''' parser.add_argument("--new-code", action="store_true", help="换一组配对码")
|
||||
parser.add_argument("--code", default=None, metavar="6位数字",
|
||||
help="把配对码设成指定值(必须是 6 位数字)。"
|
||||
"安装包用这个把用户在安装向导里填的码写进去。")
|
||||
parser.add_argument("--name", default=None, metavar="名字",
|
||||
help="设置这台电脑在手表上显示的名字"
|
||||
"(默认用 Windows 的计算机名)")'''
|
||||
|
||||
# ---------- 2. 处理逻辑 ----------
|
||||
|
||||
OLD_USE = ''' if args.reset_devices:
|
||||
store.devices = {}
|
||||
store.save_devices()
|
||||
if args.new_code or not store.pairing_code():
|
||||
store.new_pairing_code()'''
|
||||
|
||||
NEW_USE = ''' if args.reset_devices:
|
||||
store.devices = {}
|
||||
store.save_devices()
|
||||
|
||||
# --code:把配对码设成安装向导里填的那个。
|
||||
# 严格要 6 位数字 —— 和设置窗口里的规则一致,
|
||||
# 免得用户装了之后发现手表上少输一位连不上。
|
||||
if args.code is not None:
|
||||
digits = "".join(ch for ch in str(args.code) if ch.isdigit())
|
||||
if len(digits) != 6:
|
||||
print(f"配对码要 6 位数字,收到的是 {args.code!r}")
|
||||
return 2
|
||||
try:
|
||||
store.set_pairing_code(digits)
|
||||
except ValueError as exc:
|
||||
print(f"设置配对码失败:{exc}")
|
||||
return 2
|
||||
# 装完就是"设置好了",不要再弹设置窗口
|
||||
store.set("setup_done", True)
|
||||
store.set("allow_new_pairing", True)
|
||||
print(f"配对码已设为 {digits}")
|
||||
|
||||
if args.name:
|
||||
store.set("name", str(args.name).strip()[:32])
|
||||
|
||||
if args.new_code or not store.pairing_code():
|
||||
store.new_pairing_code()'''
|
||||
|
||||
# ---------- 3. 帮助文本 ----------
|
||||
|
||||
OLD_HELP = ''' --new-code 换一组配对码'''
|
||||
|
||||
NEW_HELP = ''' --new-code 换一组配对码
|
||||
--code 123456 把配对码设成指定值(安装包用)
|
||||
--name "三年二班" 设置电脑在手表上显示的名字'''
|
||||
|
||||
|
||||
def main() -> int:
|
||||
text = RUN.read_text(encoding="utf-8")
|
||||
ok = True
|
||||
|
||||
if '"--code"' in text:
|
||||
print(" 已经改过")
|
||||
return 0
|
||||
|
||||
for old, new, label in ((OLD_ARG, NEW_ARG, "参数声明"),
|
||||
(OLD_USE, NEW_USE, "处理逻辑"),
|
||||
(OLD_HELP, NEW_HELP, "帮助文本")):
|
||||
if old not in text:
|
||||
print(f" [失败] {label} 锚点没找到")
|
||||
ok = False
|
||||
continue
|
||||
text = text.replace(old, new, 1)
|
||||
print(f" {label}")
|
||||
|
||||
if not ok:
|
||||
return 1
|
||||
|
||||
RUN.write_text(text, encoding="utf-8", newline="\n")
|
||||
try:
|
||||
ast.parse(text)
|
||||
print(" run_agent.py 语法 OK")
|
||||
except SyntaxError as exc:
|
||||
print(f" 语法错误: 行 {exc.lineno}: {exc.msg}")
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user