- 改进了自动打包工具,会自动生成版本信息,复制必要的文件,并删除多余的目录。

- 把自动生成的信息加入了git忽略名单
This commit is contained in:
yshtcn 2023-09-06 16:51:30 +08:00
parent 6446940ac6
commit 6ac1fc4d5d
2 changed files with 115 additions and 4 deletions

5
.gitignore vendored
View File

@ -1,3 +1,8 @@
# Build & VerTxt
build/
version_info.txt
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

View File

@ -1,6 +1,112 @@
@echo off
:: 更新标题
title "AutoPyInstaller初始化"
:: 让我们设置一些信息
set "ProductName=heartbeat"
set "InternalName=yshtcn"
set "Comments=GitHub: https://github.com/yshtcn/heartbeat"
:: 进入批处理所在的目录
cd /d %~dp0
rd /S /Q dist
pyinstaller --onefile --noconsole --add-data "config.Exsample.ini;." heartbeat.py
del /F /Q heartbeat.spec
rd /S /Q build
:: 更新标题
title "AutoPyInstaller生成版本文件"
:: 使用WMIC获取当前日期
for /f "delims=" %%a in ('wmic os get localdatetime ^| find "."') do set datetime=%%a
:: 分解日期时间字符串
set "year=%datetime:~0,4%"
set "month=%datetime:~4,2%"
set "day=%datetime:~6,2%"
:: 获取版本的最后一位
set /p "revision=请输入今天的版本次:(%year%, %month%, %day%,[?]):"
:: 当前版本目录未去除先导0
set "versionFolder=%year%_%month%_%day%_%revision%"
:: 去除月和日的前导零(如果有)
set /a "month=1%month%-100"
set /a "day=1%day%-100"
:: 初始化临时文件
set "tempFile=temp.txt"
:: 清空或创建临时文件
echo. > %tempFile%
:: 逐行写入临时文件
echo # version_info.txt >> %tempFile%
echo VSVersionInfo( >> %tempFile%
echo ffi=FixedFileInfo( >> %tempFile%
echo filevers=(%year%, %month%, %day%, %revision%), >> %tempFile%
echo prodvers=(%year%, %month%, %day%, %revision%), >> %tempFile%
echo mask=0x3f, >> %tempFile%
echo flags=0x0, >> %tempFile%
echo OS=0x4, >> %tempFile%
echo fileType=0x1, >> %tempFile%
echo subtype=0x0, >> %tempFile%
echo date=(0, 0) >> %tempFile%
echo ), >> %tempFile%
echo kids=[ >> %tempFile%
echo StringFileInfo( >> %tempFile%
echo [ >> %tempFile%
echo StringTable( >> %tempFile%
echo '040904B0', >> %tempFile%
echo [StringStruct('ProductName', '%ProductName%'), >> %tempFile%
echo StringStruct('ProductVersion', '%year%, %month%, %day%, %revision%'), >> %tempFile%
echo StringStruct('InternalName', '%InternalName%'), >> %tempFile%
echo StringStruct('CompanyName', 'ysht.me - %Comments%'), >> %tempFile%
echo StringStruct('Comments', '%Comments%'), >> %tempFile%
echo StringStruct('LegalCopyright', 'Apache-2.0 license - %Comments%'), >> %tempFile%
echo ] >> %tempFile%
echo ), >> %tempFile%
echo ] >> %tempFile%
echo ), >> %tempFile%
echo VarFileInfo([VarStruct('Translation', [0x804, 1200])]) >> %tempFile%
echo ] >> %tempFile%
echo ) >> %tempFile%
:: 将临时文件内容移动到最终的 version_info.txt
move /Y %tempFile% version_info.txt
:: 输出完成信息
echo 版本信息已成功生成。
::更新标题
title "AutoPyInstaller开始打包"
:: 创建打包目录(如果不存在)
md build
:: 删除打包目录下同版本号的文件夹
rd /S /Q %~dp0\build\%versionFolder%
:: 删除打包目录产生的过程文件
del /q %~dp0\build\heartbeat.spec
rd /S /Q %~dp0\build\build
:: 进入打包目录并开始打包
cd /d %~dp0\build
pyinstaller --onefile --noconsole --version-file %~dp0\version_info.txt --add-data "%~dp0\config.Exsample.ini;." %~dp0\heartbeat.py
::更新标题
title "AutoPyInstaller打包完毕进行一些收尾工作"
:: (再次)删除打包目录下同版本号的文件夹
rd /S /Q %~dp0\build\%versionFolder%
:: (再次)删除打包目录产生的过程文件
del /q %~dp0\build\heartbeat.spec
rd /S /Q %~dp0\build\build
:: 把生成打包的目录以版本号重命名
rename dist %versionFolder%
:: 添加需要一起打包的文件
copy %~dp0\config.Exsample.ini %~dp0\build\%versionFolder%\