# -*- coding: utf-8 -*- r'''把 relay/ 目录 + test_deploy_device.sh 传到设备,跑真机沙箱测试。 用法: python _build/run_device_test.py ''' from __future__ import annotations import sys from pathlib import Path ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote") sys.path.insert(0, str(ROOT / "_build")) from devssh import run, upload # noqa: E402 BASE = "/root/_dtest" def main() -> int: print(" 准备目录…") print(run("rm -rf %s && mkdir -p %s/relay" % (BASE, BASE), timeout=60)[1].strip()) relay = ROOT / "relay" files = [p for p in sorted(relay.iterdir()) if p.is_file() and p.suffix in (".py", ".sh", ".ico")] print(" 上传 relay/ 下 %d 个文件…" % len(files)) for p in files: upload(str(p), "%s/relay/%s" % (BASE, p.name), 0o755) shots = relay / "site_shots" shots_files = [p for p in sorted(shots.iterdir()) if p.is_file()] \ if shots.is_dir() else [] if shots_files: run("mkdir -p %s/relay/site_shots" % BASE, timeout=30) for p in shots_files: upload(str(p), "%s/relay/site_shots/%s" % (BASE, p.name), 0o644) print(" 上传 site_shots/ %d 张截图" % len(shots_files)) upload(str(ROOT / "_build" / "test_deploy_device.sh"), "%s/test_deploy_device.sh" % BASE, 0o755) print(" 跑真机沙箱测试…") print() _c, out, err = run("bash %s/test_deploy_device.sh 2>&1" % BASE, timeout=900) print(out) if err.strip(): print(" ── stderr ──") print(err) return 0 if __name__ == "__main__": sys.exit(main())