From 6ac1fc4d5d8ee9728f42843878f71d7eb86b38a2 Mon Sep 17 00:00:00 2001 From: yshtcn Date: Wed, 6 Sep 2023 16:51:30 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E6=94=B9=E8=BF=9B=E4=BA=86=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=89=93=E5=8C=85=E5=B7=A5=E5=85=B7=EF=BC=8C=E4=BC=9A?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E7=89=88=E6=9C=AC=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=8C=E5=A4=8D=E5=88=B6=E5=BF=85=E8=A6=81=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6=EF=BC=8C=E5=B9=B6=E5=88=A0=E9=99=A4=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E7=9A=84=E7=9B=AE=E5=BD=95=E3=80=82=20-=20=E6=8A=8A?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E7=9A=84=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E4=BA=86git=E5=BF=BD=E7=95=A5=E5=90=8D?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 ++ heartbeat_pyinstaller.bat | 114 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 115 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 68bc17f..100cbeb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +# Build & VerTxt + +build/ +version_info.txt + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/heartbeat_pyinstaller.bat b/heartbeat_pyinstaller.bat index 33d9eba..7ee7942 100644 --- a/heartbeat_pyinstaller.bat +++ b/heartbeat_pyinstaller.bat @@ -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 \ No newline at end of file + + + +:: 更新标题 +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%\