| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- """
- 部署检查脚本
- """
- import sys
- from pathlib import Path
- import subprocess
- def check_deployment():
- """检查部署包"""
- deploy_dir = Path("build") / "deploy"
- if not deploy_dir.exists():
- print("❌ 部署包不存在,请先运行编译: python cythonize.py")
- return False
- print("🔍 检查部署包...")
- # 检查必要文件
- required_files = {
- "app.py": "主应用文件",
- "api/": "API模块",
- "core/": "核心模块",
- "tools/": "工具模块",
- }
- all_ok = True
- for file_name, description in required_files.items():
- file_path = deploy_dir / file_name
- if file_path.exists():
- print(f" ✓ {file_name:20} {description}")
- else:
- print(f" ✗ {file_name:20} {description} (缺失)")
- all_ok = False
- # 检查编译文件
- compiled_ext = ".pyd" if sys.platform == "win32" else ".so"
- compiled_files = list(deploy_dir.rglob(f"*{compiled_ext}"))
- print(f" ✓ 编译文件数量: {len(compiled_files)} 个 {compiled_ext} 文件")
- # 检查依赖
- req_file = deploy_dir / "requirements.txt"
- if req_file.exists():
- print(f" ✓ requirements.txt 存在")
- # 检查Python版本
- try:
- result = subprocess.run(
- [sys.executable, "--version"], capture_output=True, text=True
- )
- print(f" Python版本: {result.stdout.strip()}")
- except:
- print(" ⚠️ 无法获取Python版本")
- else:
- print(" ⚠️ requirements.txt 不存在")
- all_ok = False
- return all_ok
- def create_minimal_deploy():
- """创建最小化部署包"""
- import zipfile
- deploy_dir = Path("build") / "deploy"
- if not deploy_dir.exists():
- print("❌ 部署包不存在")
- return
- # 创建zip包
- zip_path = Path("build") / "longjoeagent_deploy.zip"
- with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
- for file_path in deploy_dir.rglob("*"):
- if file_path.is_file():
- arcname = file_path.relative_to(deploy_dir)
- zipf.write(file_path, arcname)
- print(f"✅ 创建部署包: {zip_path}")
- print(f" 大小: {zip_path.stat().st_size / 1024 / 1024:.2f} MB")
- def main():
- """主函数"""
- print("=" * 50)
- print(" LongjoeAgent 部署检查工具")
- print("=" * 50)
- if check_deployment():
- print("\n✅ 部署包检查通过")
- # 询问是否创建zip包
- if sys.platform == "win32":
- response = input("\n是否创建zip部署包? (y/n): ")
- if response.lower() == "y":
- create_minimal_deploy()
- else:
- print("\n❌ 部署包检查失败")
- print("\n📋 部署命令示例:")
- print(" scp -r build/deploy/ user@server:/opt/longjoeagent/")
- print(" cd /opt/longjoeagent && pip install -r requirements.txt")
- print(" python app.py")
- if __name__ == "__main__":
- main()
|