[patch] 优化打包逻辑 控制变量为日志产出 和 安装包整合路径统一

This commit is contained in:
2025-10-10 16:16:36 +08:00
parent 9ff009712a
commit 31ca5d0819
2 changed files with 31 additions and 47 deletions

View File

@@ -85,16 +85,7 @@ def main():
result = subprocess.run(['python', 'quick_build.py'], capture_output=False) result = subprocess.run(['python', 'quick_build.py'], capture_output=False)
if result.returncode == 0: if result.returncode == 0:
# 确保输出目录正确性 # 验证最终输出quick_build.py 已统一输出到 MultiPlatformGUI
if os.path.exists('dist/main') and not os.path.exists('dist/MultiPlatformGUI'):
print("🔄 修正输出目录名称...")
try:
os.rename('dist/main', 'dist/MultiPlatformGUI')
print("✅ 已重命名为: dist/MultiPlatformGUI/")
except Exception as e:
print(f"⚠️ 重命名失败: {e}")
# 验证最终输出
if os.path.exists('dist/MultiPlatformGUI'): if os.path.exists('dist/MultiPlatformGUI'):
print("\n🎉 生产环境打包成功!") print("\n🎉 生产环境打包成功!")
print("📁 输出目录: dist/MultiPlatformGUI/") print("📁 输出目录: dist/MultiPlatformGUI/")
@@ -108,9 +99,7 @@ def main():
else: else:
print("⚠️ 主程序文件未找到") print("⚠️ 主程序文件未找到")
else: else:
print("\n❌ 输出目录验证失败") print("\n❌ 输出目录验证失败: 未找到 dist/MultiPlatformGUI")
if os.path.exists('dist/main'):
print("💡 发现: dist/main/ 目录,请手动重命名为 MultiPlatformGUI")
else: else:
print("\n❌ 打包失败") print("\n❌ 打包失败")

View File

@@ -53,7 +53,7 @@ def build_with_command():
cmd = [ cmd = [
'pyinstaller', 'pyinstaller',
'--name=main', '--name=MultiPlatformGUI', # 直接使用最终目录名
'--onedir', # 相当于 --exclude-binaries '--onedir', # 相当于 --exclude-binaries
'--windowed', # 相当于 -w '--windowed', # 相当于 -w
'--icon=static/ai_assistant_icon_64.png', # 添加主程序图标 '--icon=static/ai_assistant_icon_64.png', # 添加主程序图标
@@ -96,33 +96,32 @@ def build_with_command():
if result.returncode == 0: if result.returncode == 0:
print("✅ 打包成功!") print("✅ 打包成功!")
print("📁 打包结果: dist/main/") print("📁 打包结果: dist/MultiPlatformGUI/")
# 重命名目录为统一的输出路径 # 验证输出目录(不需要重命名了)
if os.path.exists('dist/main'): if os.path.exists('dist/MultiPlatformGUI/MultiPlatformGUI.exe'):
# PyInstaller 生成的 exe 名称是 MultiPlatformGUI.exe
# 重命名为 main.exe保持兼容性
try: try:
# 如果目标目录已存在,先删除 old_exe = 'dist/MultiPlatformGUI/MultiPlatformGUI.exe'
if os.path.exists('dist/MultiPlatformGUI'): new_exe = 'dist/MultiPlatformGUI/main.exe'
print("🗑️ 删除旧的 MultiPlatformGUI 目录...")
shutil.rmtree('dist/MultiPlatformGUI')
# 重命名 if os.path.exists(new_exe):
os.rename('dist/main', 'dist/MultiPlatformGUI') os.remove(new_exe)
print("✅ 已重命名为: dist/MultiPlatformGUI/")
# 验证重命名结果 os.rename(old_exe, new_exe)
if os.path.exists('dist/MultiPlatformGUI/main.exe'): print("✅ 主程序已重命名: MultiPlatformGUI.exe → main.exe")
exe_size = os.path.getsize('dist/MultiPlatformGUI/main.exe') / 1024 / 1024
print(f"✅ 主程序验证通过: main.exe ({exe_size:.1f} MB)") exe_size = os.path.getsize(new_exe) / 1024 / 1024
else: print(f"✅ 主程序验证通过: main.exe ({exe_size:.1f} MB)")
print("⚠️ 重命名后主程序文件验证失败")
except Exception as e: except Exception as e:
print(f"⚠️ 重命名失败: {e}") print(f"⚠️ 重命名主程序失败: {e}")
print("💡 可以手动重命名: dist/main -> dist/MultiPlatformGUI") elif os.path.exists('dist/MultiPlatformGUI/main.exe'):
print("📁 当前可用路径: dist/main/") # 如果已经是 main.exe直接验证
exe_size = os.path.getsize('dist/MultiPlatformGUI/main.exe') / 1024 / 1024
print(f"✅ 主程序验证通过: main.exe ({exe_size:.1f} MB)")
else: else:
print("⚠️ 未找到 dist/main 目录,重命名跳过") print("⚠️ 未找到主程序文件")
# 创建使用说明 # 创建使用说明
try: try:
@@ -237,23 +236,23 @@ def verify_result():
"""验证打包结果""" """验证打包结果"""
print("\n🔍 验证打包结果...") print("\n🔍 验证打包结果...")
# 优先检查MultiPlatformGUI(标准输出目录) # 检查MultiPlatformGUI目录(统一输出目录)
target_dir = "dist/MultiPlatformGUI" target_dir = "dist/MultiPlatformGUI"
fallback_dir = "dist/main"
if os.path.exists(target_dir): if os.path.exists(target_dir):
return _verify_directory(target_dir) return _verify_directory(target_dir)
elif os.path.exists(fallback_dir):
print(f"⚠️ 发现备用目录: {fallback_dir}")
print("💡 建议重命名为: dist/MultiPlatformGUI")
return _verify_directory(fallback_dir)
else: else:
print("❌ 未找到任何打包输出目录") print("❌ 未找到打包输出目录: dist/MultiPlatformGUI")
print("💡 请检查 PyInstaller 执行是否成功")
return False return False
def _verify_directory(base_dir): def _verify_directory(base_dir):
"""验证指定目录的打包结果""" """验证指定目录的打包结果"""
# 检查可能的 exe 名称
exe_path = f"{base_dir}/main.exe" exe_path = f"{base_dir}/main.exe"
if not os.path.exists(exe_path):
exe_path = f"{base_dir}/MultiPlatformGUI.exe"
internal_dir = f"{base_dir}/_internal" internal_dir = f"{base_dir}/_internal"
dll_path = f"{base_dir}/_internal/Utils/PythonNew32/SaiNiuApi.dll" dll_path = f"{base_dir}/_internal/Utils/PythonNew32/SaiNiuApi.dll"
static_dir = f"{base_dir}/_internal/static" static_dir = f"{base_dir}/_internal/static"
@@ -339,15 +338,11 @@ def main():
print("\n" + "=" * 60) print("\n" + "=" * 60)
print("🎉 打包完成!") print("🎉 打包完成!")
# 智能显示可用路径 # 显示打包结果
if os.path.exists("dist/MultiPlatformGUI"): if os.path.exists("dist/MultiPlatformGUI"):
print("📁 打包结果: dist/MultiPlatformGUI/") print("📁 打包结果: dist/MultiPlatformGUI/")
print("🚀 运行方式: cd dist/MultiPlatformGUI && .\\main.exe") print("🚀 运行方式: cd dist/MultiPlatformGUI && .\\main.exe")
print("📦 安装包构建: python installer/build_installer.py") print("📦 安装包构建: python installer/build_installer.py")
elif os.path.exists("dist/main"):
print("📁 打包结果: dist/main/")
print("🚀 运行方式: cd dist/main && .\\main.exe")
print("⚠️ 建议重命名: dist/main -> dist/MultiPlatformGUI")
print("=" * 60) print("=" * 60)