226 lines
7.8 KiB
PowerShell
226 lines
7.8 KiB
PowerShell
# 座位分配系统 Windows 打包脚本 (PowerShell版本)
|
||
# 编码:UTF-8
|
||
|
||
Write-Host "================================" -ForegroundColor Cyan
|
||
Write-Host " 座位分配系统 Windows 打包脚本" -ForegroundColor Cyan
|
||
Write-Host "================================" -ForegroundColor Cyan
|
||
Write-Host ""
|
||
|
||
# 设置错误处理
|
||
$ErrorActionPreference = "Stop"
|
||
|
||
try {
|
||
# 检查Python是否安装
|
||
Write-Host "[信息] 检查Python环境..." -ForegroundColor Yellow
|
||
$pythonVersion = python --version 2>&1
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "Python未安装或不在PATH中,请先安装Python 3.7+"
|
||
}
|
||
Write-Host "Python版本: $pythonVersion" -ForegroundColor Green
|
||
|
||
# 检查pip
|
||
$pipVersion = pip --version 2>&1
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "pip不可用"
|
||
}
|
||
Write-Host "pip版本: $pipVersion" -ForegroundColor Green
|
||
|
||
# 升级pip
|
||
Write-Host ""
|
||
Write-Host "[步骤1] 升级pip..." -ForegroundColor Yellow
|
||
python -m pip install --upgrade pip
|
||
|
||
# 安装PyInstaller
|
||
Write-Host ""
|
||
Write-Host "[步骤2] 安装PyInstaller..." -ForegroundColor Yellow
|
||
pip install pyinstaller
|
||
|
||
# 安装依赖包
|
||
Write-Host ""
|
||
Write-Host "[步骤3] 安装依赖包..." -ForegroundColor Yellow
|
||
pip install pandas numpy openpyxl
|
||
|
||
# 创建必要的目录
|
||
Write-Host ""
|
||
Write-Host "[步骤4] 创建构建目录..." -ForegroundColor Yellow
|
||
$dirs = @("build", "dist", "release", "release\示例文件")
|
||
foreach ($dir in $dirs) {
|
||
if (!(Test-Path $dir)) {
|
||
New-Item -ItemType Directory -Path $dir -Force | Out-Null
|
||
Write-Host "创建目录: $dir" -ForegroundColor Gray
|
||
}
|
||
}
|
||
|
||
# 检查主文件是否存在
|
||
if (!(Test-Path "seat_allocation_system.py")) {
|
||
throw "找不到主程序文件 seat_allocation_system.py"
|
||
}
|
||
|
||
# 打包主程序
|
||
Write-Host ""
|
||
Write-Host "[步骤5] 开始打包座位分配系统..." -ForegroundColor Yellow
|
||
Write-Host "这可能需要几分钟时间,请耐心等待..." -ForegroundColor Gray
|
||
|
||
$pyinstallerArgs = @(
|
||
"--onefile",
|
||
"--console",
|
||
"--name", "座位分配系统",
|
||
"--distpath", "dist",
|
||
"--workpath", "build",
|
||
"--specpath", "build",
|
||
"--clean",
|
||
"seat_allocation_system.py"
|
||
)
|
||
|
||
# 如果存在图标文件,添加图标参数
|
||
if (Test-Path "icon.ico") {
|
||
$pyinstallerArgs += "--icon", "icon.ico"
|
||
}
|
||
|
||
# 如果存在README文件,添加数据文件
|
||
if (Test-Path "README.md") {
|
||
$pyinstallerArgs += "--add-data", "README.md;."
|
||
}
|
||
|
||
& pyinstaller @pyinstallerArgs
|
||
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "PyInstaller打包失败"
|
||
}
|
||
|
||
# 检查打包结果
|
||
$exePath = "dist\座位分配系统.exe"
|
||
if (!(Test-Path $exePath)) {
|
||
throw "打包失败:找不到生成的可执行文件"
|
||
}
|
||
|
||
# 复制文件到发布目录
|
||
Write-Host ""
|
||
Write-Host "[步骤6] 创建发布包..." -ForegroundColor Yellow
|
||
|
||
# 复制主程序
|
||
Copy-Item $exePath "release\" -Force
|
||
Write-Host "复制主程序到发布目录" -ForegroundColor Gray
|
||
|
||
# 复制示例文件
|
||
$exampleFiles = @("人员信息_示例.xlsx", "座位信息_示例.xlsx", "*.xlsx")
|
||
foreach ($pattern in $exampleFiles) {
|
||
$files = Get-ChildItem -Path . -Name $pattern -ErrorAction SilentlyContinue
|
||
foreach ($file in $files) {
|
||
if ($file -notlike "*_最终分配*" -and $file -notlike "*日志*") {
|
||
Copy-Item $file "release\示例文件\" -Force -ErrorAction SilentlyContinue
|
||
Write-Host "复制示例文件: $file" -ForegroundColor Gray
|
||
}
|
||
}
|
||
}
|
||
|
||
# 创建使用说明
|
||
Write-Host ""
|
||
Write-Host "[步骤7] 创建使用说明..." -ForegroundColor Yellow
|
||
|
||
$readme = @"
|
||
座位分配系统 v2.0
|
||
==================
|
||
|
||
使用方法:
|
||
1. 将人员信息和座位信息的Excel文件放在程序同一目录下
|
||
2. 双击运行"座位分配系统.exe"
|
||
3. 按照提示操作
|
||
|
||
文件要求:
|
||
- 人员信息文件:包含姓名、证件类型、证件号、手机号、备注等列
|
||
- 座位信息文件:包含区域、楼层、排号、座位号等列
|
||
|
||
程序特性:
|
||
- ✅ 智能文件识别(自动识别Excel文件类型)
|
||
- ✅ 支持1-10人连坐需求
|
||
- ✅ 支持备注分组和手机号分组两种模式
|
||
- ✅ 自动验证数据完整性和可行性
|
||
- ✅ 智能座位分配算法
|
||
- ✅ 详细的分配日志和统计
|
||
|
||
输出文件:
|
||
程序运行后会在当前目录创建log文件夹,包含:
|
||
- log/座位信息_最终分配.xlsx (分配结果)
|
||
- log/最终座位分配日志.xlsx (详细日志)
|
||
- log/seat_allocation_log.txt (运行日志)
|
||
|
||
操作步骤:
|
||
1. 选择文件识别模式(默认文件名 或 智能识别)
|
||
2. 选择连坐分组方式(备注分组 或 手机号分组)
|
||
3. 程序自动校验数据完整性
|
||
4. 执行智能座位分配
|
||
5. 查看输出结果
|
||
|
||
注意事项:
|
||
- 确保Excel文件格式正确
|
||
- 人员信息文件的"备注"列用数字表示连坐人数
|
||
- 程序会自动过滤无效数据
|
||
- 如有问题请查看详细日志文件
|
||
|
||
技术支持:
|
||
如遇到问题,请查看log文件夹中的日志文件获取详细信息。
|
||
|
||
版本信息:
|
||
- 版本:v2.0 (智能识别版)
|
||
- 支持:Windows 7/8/10/11
|
||
- 依赖:无需额外安装Python环境
|
||
"@
|
||
|
||
$readme | Out-File -FilePath "release\使用说明.txt" -Encoding UTF8
|
||
|
||
# 创建批处理启动文件(可选)
|
||
$batchContent = @"
|
||
@echo off
|
||
chcp 65001 >nul
|
||
echo 启动座位分配系统...
|
||
echo.
|
||
座位分配系统.exe
|
||
echo.
|
||
echo 程序已结束
|
||
pause
|
||
"@
|
||
$batchContent | Out-File -FilePath "release\启动座位分配系统.bat" -Encoding UTF8
|
||
|
||
# 显示完成信息
|
||
Write-Host ""
|
||
Write-Host "================================" -ForegroundColor Green
|
||
Write-Host " 打包完成!" -ForegroundColor Green
|
||
Write-Host "================================" -ForegroundColor Green
|
||
Write-Host ""
|
||
Write-Host "发布文件位置:" -ForegroundColor Cyan
|
||
Write-Host "📁 release\" -ForegroundColor Yellow
|
||
Write-Host " ├── 座位分配系统.exe (主程序)" -ForegroundColor White
|
||
Write-Host " ├── 启动座位分配系统.bat (启动脚本)" -ForegroundColor White
|
||
Write-Host " ├── 使用说明.txt (使用说明)" -ForegroundColor White
|
||
Write-Host " └── 示例文件\ (示例文件夹)" -ForegroundColor White
|
||
Write-Host ""
|
||
Write-Host "文件大小信息:" -ForegroundColor Cyan
|
||
$fileSize = (Get-Item $exePath).Length / 1MB
|
||
Write-Host "主程序大小: $([math]::Round($fileSize, 2)) MB" -ForegroundColor Yellow
|
||
|
||
Write-Host ""
|
||
Write-Host "部署说明:" -ForegroundColor Cyan
|
||
Write-Host "1. 将整个 release 文件夹分发给用户" -ForegroundColor White
|
||
Write-Host "2. 用户直接运行 座位分配系统.exe 或 启动座位分配系统.bat" -ForegroundColor White
|
||
Write-Host "3. 无需安装Python环境" -ForegroundColor White
|
||
|
||
Write-Host ""
|
||
Write-Host "✅ 打包成功完成!" -ForegroundColor Green
|
||
|
||
} catch {
|
||
Write-Host ""
|
||
Write-Host "❌ 打包过程中出现错误:" -ForegroundColor Red
|
||
Write-Host $_.Exception.Message -ForegroundColor Red
|
||
Write-Host ""
|
||
Write-Host "常见解决方案:" -ForegroundColor Yellow
|
||
Write-Host "1. 确保已安装Python 3.7+" -ForegroundColor White
|
||
Write-Host "2. 确保网络连接正常(需要下载依赖包)" -ForegroundColor White
|
||
Write-Host "3. 确保有足够的磁盘空间" -ForegroundColor White
|
||
Write-Host "4. 尝试以管理员权限运行此脚本" -ForegroundColor White
|
||
exit 1
|
||
}
|
||
|
||
Write-Host ""
|
||
Write-Host "按任意键继续..." -ForegroundColor Gray
|
||
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") |