pack_verify_entry.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. r"""`pack.bat verify` 的入口:找最新的交付包(或用户给的路径)→ 交给 pack_dist.py --verify。
  4. 为什么要单独一个: `pack.bat verify` 不带参数时应该"自动找最新那个 zip",而批处理里做这个
  5. (dir /b /o-d 之类) 既啰嗦又在中文路径上不稳 —— 放到 Python 里三行搞定,批处理只负责传参。
  6. 用法:
  7. python scripts/pack_verify_entry.py # 找 <安装根父目录>/guanlan-v*_dist_*.zip 里最新的
  8. python scripts/pack_verify_entry.py <zip 路径>
  9. """
  10. from __future__ import annotations
  11. import pathlib
  12. import subprocess
  13. import sys
  14. ROOT = pathlib.Path(__file__).resolve().parents[1]
  15. def newest_zip() -> pathlib.Path | None:
  16. """找最新的交付包: 先看安装根的父目录(打包器默认输出处), 再看安装根自己。"""
  17. cands: list[pathlib.Path] = []
  18. for d in (ROOT.parent, ROOT):
  19. if d.is_dir():
  20. cands += [p for p in d.glob('guanlan-*.zip') if p.is_file()]
  21. cands += [p for p in d.glob('*guanlan*v*.zip') if p.is_file()]
  22. cands = sorted(set(cands), key=lambda p: p.stat().st_mtime, reverse=True)
  23. return cands[0] if cands else None
  24. def main() -> int:
  25. arg = sys.argv[1] if len(sys.argv) > 1 else ''
  26. zp = pathlib.Path(arg) if arg else newest_zip()
  27. if zp is None or not zp.is_file():
  28. print('[X] 找不到交付包 zip。给一个路径: python scripts/pack_verify_entry.py <zip>')
  29. return 2
  30. print(f'[i] 开箱验证: {zp} ({zp.stat().st_size/1e6:.0f} MB)')
  31. if arg == '' and not str(zp).startswith(str(ROOT.parent)):
  32. pass
  33. return subprocess.call([sys.executable, str(ROOT / 'scripts' / 'pack_dist.py'), '--verify', str(zp)],
  34. cwd=str(ROOT))
  35. if __name__ == '__main__':
  36. sys.exit(main())