""" 跨平台开发打包脚本(开发机/测试用) Linux/Mac: ./build.sh Windows: build_windows.bat """ import os import platform import shutil import subprocess import sys from pathlib import Path ROOT = Path(__file__).parent def main(): os.chdir(ROOT) print("=" * 50) print(f" SSHClient 打包脚本 ({platform.system()})") print("=" * 50) venv = ROOT / "venv" if not venv.exists(): print("[1/4] 创建虚拟环境...") subprocess.check_call([sys.executable, "-m", "venv", "venv"]) if platform.system() == "Windows": py = venv / "Scripts" / "python.exe" else: py = venv / "bin" / "python" print("[2/4] 安装依赖...") subprocess.check_call([str(py), "-m", "pip", "install", "--upgrade", "pip"]) subprocess.check_call([str(py), "-m", "pip", "install", "-r", "requirements.txt"]) print("[3/4] 清理旧产物...") for d in ("build", "dist"): if (ROOT / d).exists(): shutil.rmtree(ROOT / d) for f in ROOT.glob("*.spec.bak"): f.unlink() print("[4/4] 开始 PyInstaller 打包...") subprocess.check_call([str(py), "-m", "PyInstaller", "build.spec", "--clean", "--noconfirm"]) exe_name = "SSHClient.exe" if platform.system() == "Windows" else "SSHClient" out = ROOT / "dist" / exe_name if out.exists(): size_mb = out.stat().st_size / 1024 / 1024 print() print("=" * 50) print(f" ✓ 打包完成: {out}") print(f" ✓ 大小: {size_mb:.1f} MB") print("=" * 50) else: print("[X] 打包未产出文件,请检查 PyInstaller 输出") sys.exit(1) if __name__ == "__main__": main()