check_deploy.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. """
  2. 部署检查脚本
  3. """
  4. import sys
  5. from pathlib import Path
  6. import subprocess
  7. def check_deployment():
  8. """检查部署包"""
  9. deploy_dir = Path("build") / "deploy"
  10. if not deploy_dir.exists():
  11. print("❌ 部署包不存在,请先运行编译: python cythonize.py")
  12. return False
  13. print("🔍 检查部署包...")
  14. # 检查必要文件
  15. required_files = {
  16. "app.py": "主应用文件",
  17. "api/": "API模块",
  18. "core/": "核心模块",
  19. "tools/": "工具模块",
  20. }
  21. all_ok = True
  22. for file_name, description in required_files.items():
  23. file_path = deploy_dir / file_name
  24. if file_path.exists():
  25. print(f" ✓ {file_name:20} {description}")
  26. else:
  27. print(f" ✗ {file_name:20} {description} (缺失)")
  28. all_ok = False
  29. # 检查编译文件
  30. compiled_ext = ".pyd" if sys.platform == "win32" else ".so"
  31. compiled_files = list(deploy_dir.rglob(f"*{compiled_ext}"))
  32. print(f" ✓ 编译文件数量: {len(compiled_files)} 个 {compiled_ext} 文件")
  33. # 检查依赖
  34. req_file = deploy_dir / "requirements.txt"
  35. if req_file.exists():
  36. print(f" ✓ requirements.txt 存在")
  37. # 检查Python版本
  38. try:
  39. result = subprocess.run(
  40. [sys.executable, "--version"], capture_output=True, text=True
  41. )
  42. print(f" Python版本: {result.stdout.strip()}")
  43. except:
  44. print(" ⚠️ 无法获取Python版本")
  45. else:
  46. print(" ⚠️ requirements.txt 不存在")
  47. all_ok = False
  48. return all_ok
  49. def create_minimal_deploy():
  50. """创建最小化部署包"""
  51. import zipfile
  52. deploy_dir = Path("build") / "deploy"
  53. if not deploy_dir.exists():
  54. print("❌ 部署包不存在")
  55. return
  56. # 创建zip包
  57. zip_path = Path("build") / "longjoeagent_deploy.zip"
  58. with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
  59. for file_path in deploy_dir.rglob("*"):
  60. if file_path.is_file():
  61. arcname = file_path.relative_to(deploy_dir)
  62. zipf.write(file_path, arcname)
  63. print(f"✅ 创建部署包: {zip_path}")
  64. print(f" 大小: {zip_path.stat().st_size / 1024 / 1024:.2f} MB")
  65. def main():
  66. """主函数"""
  67. print("=" * 50)
  68. print(" LongjoeAgent 部署检查工具")
  69. print("=" * 50)
  70. if check_deployment():
  71. print("\n✅ 部署包检查通过")
  72. # 询问是否创建zip包
  73. if sys.platform == "win32":
  74. response = input("\n是否创建zip部署包? (y/n): ")
  75. if response.lower() == "y":
  76. create_minimal_deploy()
  77. else:
  78. print("\n❌ 部署包检查失败")
  79. print("\n📋 部署命令示例:")
  80. print(" scp -r build/deploy/ user@server:/opt/longjoeagent/")
  81. print(" cd /opt/longjoeagent && pip install -r requirements.txt")
  82. print(" python app.py")
  83. if __name__ == "__main__":
  84. main()