You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Curriculum_Design/package_v1.0.py

251 lines
7.5 KiB

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
MagicWord 1.0.0 完整打包脚本
创建包含所有资源的发布包
"""
import os
import sys
import shutil
import zipfile
from datetime import datetime
def create_package():
"""创建完整的发布包"""
print("=" * 60)
print("MagicWord 1.0.0 完整打包程序")
print("=" * 60)
# 检查可执行文件是否存在
exe_path = "dist/MagicWord.exe"
if not os.path.exists(exe_path):
print(f"错误: 找不到可执行文件 {exe_path}")
print("请先运行PyInstaller构建可执行文件")
return False
# 创建发布目录
release_dir = "MagicWord_v1.0.0_Windows"
if os.path.exists(release_dir):
shutil.rmtree(release_dir)
os.makedirs(release_dir)
print("创建发布包目录...")
# 复制主要文件
files_to_copy = [
(exe_path, "MagicWord.exe"),
("README.md", "README.md"),
("CHANGELOG.md", "CHANGELOG.md"),
("requirements.txt", "requirements.txt"),
("install_and_fix.py", "install_and_fix.py"),
]
for src, dst in files_to_copy:
if os.path.exists(src):
shutil.copy2(src, os.path.join(release_dir, dst))
print(f"✓ 复制: {src} -> {dst}")
else:
print(f"⚠ 跳过: {src} (文件不存在)")
# 复制图标文件
icons_dir = os.path.join(release_dir, "icons")
if os.path.exists("resources/icons"):
shutil.copytree("resources/icons", icons_dir)
print("✓ 复制图标文件到发布包")
# 复制配置文件
config_dir = os.path.join(release_dir, "config")
if os.path.exists("resources/config"):
shutil.copytree("resources/config", config_dir)
print("✓ 复制配置文件到发布包")
# 复制样式文件
qss_dir = os.path.join(release_dir, "qss")
if os.path.exists("resources/qss") and os.listdir("resources/qss"):
shutil.copytree("resources/qss", qss_dir)
print("✓ 复制样式文件到发布包")
# 注意: UI图像文件已通过PyInstaller打包到可执行文件中
# 程序会在运行时从打包的资源中加载 114514.png 和 UI.png
# 创建运行脚本
print("创建运行脚本...")
# Windows运行脚本
run_script = """@echo off
echo ========================================
echo MagicWord 1.0.0 启动中...
echo ========================================
cd /d "%~dp0"
start "" "MagicWord.exe"
echo 程序已启动!
timeout /t 3 /nobreak > nul
"""
with open(os.path.join(release_dir, "运行程序.bat"), "w", encoding='utf-8') as f:
f.write(run_script)
# 创建桌面快捷方式脚本
desktop_shortcut_script = """@echo off
echo 正在创建桌面快捷方式...
cd /d "%~dp0"
set SCRIPT_DIR=%CD%
set DESKTOP=%USERPROFILE%\Desktop
set SHORTCUT=%DESKTOP%\MagicWord.lnk
echo 脚本目录: %SCRIPT_DIR%
echo 桌面路径: %DESKTOP%
powershell -Command "
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut('%SHORTCUT%')
$Shortcut.TargetPath = '%SCRIPT_DIR%\MagicWord.exe'
$Shortcut.WorkingDirectory = '%SCRIPT_DIR%'
$Shortcut.IconLocation = '%SCRIPT_DIR%\icons\app_icon_256X256.png'
$Shortcut.Description = 'MagicWord 1.0.0 - 隐私学习软件'
$Shortcut.Save()
Write-Host '桌面快捷方式创建成功!' -ForegroundColor Green
"
if exist "%SHORTCUT%" (
echo 桌面快捷方式创建成功!
) else (
echo 桌面快捷方式创建失败!
)
echo.
echo 按任意键退出...
pause > nul
"""
with open(os.path.join(release_dir, "创建桌面快捷方式.bat"), "w", encoding='utf-8') as f:
f.write(desktop_shortcut_script)
# 创建安装说明
install_guide = """MagicWord 1.0.0 安装使用说明
========================================
系统要求
========================================
- Windows 7/8/10/11 (64位)
- 至少 100MB 可用磁盘空间
- 建议内存: 4GB 以上
========================================
快速开始
========================================
方法1: 直接运行
1. 双击 "MagicWord.exe" 即可运行程序
方法2: 使用运行脚本
1. 双击 "运行程序.bat" 自动启动程序
方法3: 创建桌面快捷方式
1. 双击 "创建桌面快捷方式.bat"
2. 桌面上会出现 MagicWord 快捷方式
3. 双击桌面快捷方式即可运行
========================================
文件说明
========================================
MagicWord.exe - 主程序文件
icons/ - 图标文件夹
app_icon.ico - 应用程序图标
app_icon_256X256.png - 256x256图标
app_icon_128X128.png - 128x128图标
app_icon_64X64.png - 64x64图标
app_icon_32X32.png - 32x32图标
config/ - 配置文件
README.md - 项目说明文档
CHANGELOG.md - 更新日志
========================================
卸载方法
========================================
直接删除整个 MagicWord 文件夹即可完全卸载
========================================
技术支持
========================================
如有问题,请查看 README.md 文件或联系开发者
========================================
版本信息
========================================
版本: 1.0.0
构建时间: {build_time}
平台: Windows
架构: {architecture}
祝您使用愉快!
""".format(
build_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
architecture="64位"
)
with open(os.path.join(release_dir, "安装说明.txt"), "w", encoding='utf-8') as f:
f.write(install_guide)
# 创建版本信息文件
version_info = f"""MagicWord Version 1.0.0
Build Date: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
Platform: Windows
Architecture: 64-bit
Python Version: 3.13
Qt Version: PyQt5
This is a standalone executable package containing all necessary dependencies.
"""
with open(os.path.join(release_dir, "version.txt"), "w", encoding='utf-8') as f:
f.write(version_info)
print("创建ZIP压缩包...")
# 创建ZIP压缩包
zip_filename = f"MagicWord_v1.0.0_Windows_64bit"
with zipfile.ZipFile(f"{zip_filename}.zip", 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, dirs, files in os.walk(release_dir):
for file in files:
file_path = os.path.join(root, file)
arc_path = os.path.relpath(file_path, release_dir)
zipf.write(file_path, arc_path)
print(f"添加到压缩包: {arc_path}")
print("=" * 60)
print("✅ 打包完成!")
print(f"📁 发布包目录: {release_dir}/")
print(f"📦 ZIP压缩包: {zip_filename}.zip")
print("=" * 60)
# 显示发布包内容
print("\n发布包内容:")
for root, dirs, files in os.walk(release_dir):
level = root.replace(release_dir, '').count(os.sep)
indent = ' ' * 2 * level
print(f"{indent}{os.path.basename(root)}/")
subindent = ' ' * 2 * (level + 1)
for file in files:
print(f"{subindent}{file}")
return True
def main():
"""主函数"""
try:
success = create_package()
if success:
print("\n🎉 所有文件已成功打包!")
print("您可以分发 ZIP 文件给用户。")
else:
print("\n❌ 打包过程中出现错误。")
return 1
except Exception as e:
print(f"\n❌ 发生错误: {e}")
return 1
return 0
if __name__ == "__main__":
sys.exit(main())