Compare-PBI-Data/build_exe.py
chenwu da0502c369 new file: Compare-PBI-Data.spec
modified:   Evaluate_Result/admin_example_1.xlsx
	modified:   Evaluate_Result/admin_example_2.xlsx
	new file:   __pycache__/compareData.cpython-313.pyc
	new file:   __pycache__/config.cpython-313.pyc
	new file:   __pycache__/getDataFromAS.cpython-313.pyc
	new file:   __pycache__/getQueries.cpython-313.pyc
	modified:   app.py
	new file:   build/Compare-PBI-Data/Analysis-00.toc
	new file:   build/Compare-PBI-Data/Compare-PBI-Data.pkg
	new file:   build/Compare-PBI-Data/EXE-00.toc
	new file:   build/Compare-PBI-Data/PKG-00.toc
	new file:   build/Compare-PBI-Data/PYZ-00.pyz
	new file:   build/Compare-PBI-Data/PYZ-00.toc
	new file:   build/Compare-PBI-Data/base_library.zip
	new file:   build/Compare-PBI-Data/generated-2c83337f9fff21d32f0901febbdb8eec9b843eb92a216cf8171391083f1c5046.ico
	new file:   build/Compare-PBI-Data/localpycs/pyimod01_archive.pyc
	new file:   build/Compare-PBI-Data/localpycs/pyimod02_importers.pyc
	new file:   build/Compare-PBI-Data/localpycs/pyimod03_ctypes.pyc
	new file:   build/Compare-PBI-Data/localpycs/pyimod04_pywin32.pyc
	new file:   build/Compare-PBI-Data/localpycs/struct.pyc
	new file:   build/Compare-PBI-Data/warn-Compare-PBI-Data.txt
	new file:   build/Compare-PBI-Data/xref-Compare-PBI-Data.html
	new file:   build_exe.py
	modified:   config.py
	new file:   dist/Compare-PBI-Data.exe
	new file:   dist/Evaluate_Result/admin_example_1.xlsx
	new file:   dist/Evaluate_Result/admin_example_2.xlsx
	new file:   dist/Export_Json/example.json
	modified:   getDataFromAS.py
	modified:   getQueries.py
	new file:   icon.jpg
	modified:   requirements.txt
	deleted:    run.py
	modified:   templates/index.html
2025-03-08 16:21:14 +08:00

85 lines
3.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import PyInstaller.__main__
import os
import shutil
# 获取当前脚本所在的目录路径
CURRENT_DIR_PATH = os.path.dirname(os.path.abspath(__file__))
# 定义需要包含的文件夹
folders_to_include = [
'Export_Json',
'Evaluate_Result',
'MS.NET_Package',
'templates'
]
# 确保文件夹存在
for folder in folders_to_include:
folder_path = os.path.join(CURRENT_DIR_PATH, folder)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
# 定义PyInstaller参数
pyinstaller_args = [
'app.py', # 主脚本
'--name=Compare-PBI-Data', # 可执行文件名称
'--onefile', # 打包成单个可执行文件
'--windowed', # 不显示控制台窗口
'--icon=icon.jpg', # 使用图标
'--add-data=templates;templates', # 添加模板文件夹
'--add-data=MS.NET_Package;MS.NET_Package', # 添加.NET包
'--add-data=Export_Json;Export_Json', # 添加导出JSON文件夹
'--add-data=Evaluate_Result;Evaluate_Result', # 添加评估结果文件夹
'--hidden-import=pythonnet', # 添加隐藏导入
'--hidden-import=clr', # 添加隐藏导入
'--hidden-import=pandas', # 添加隐藏导入
'--hidden-import=openpyxl', # 添加隐藏导入
'--hidden-import=flask', # 添加隐藏导入
'--hidden-import=signal', # 添加信号处理模块
'--hidden-import=werkzeug.serving', # 添加werkzeug服务模块
'--clean', # 清理临时文件
'--runtime-hook=runtime_hook.py', # 添加运行时钩子
]
# 创建运行时钩子文件
with open('runtime_hook.py', 'w', encoding='utf-8') as f:
f.write("""
# 运行时钩子,用于确保应用程序可以正确关闭并创建必要的文件夹
import os
import signal
import sys
import config
# 确保正确处理SIGTERM信号
def handle_sigterm(*args):
sys.exit(0)
signal.signal(signal.SIGTERM, handle_sigterm)
# 获取应用程序所在的目录路径
app_dir = os.path.dirname(sys.executable) if getattr(sys, 'frozen', False) else os.path.dirname(os.path.abspath(__file__))
# 重新设置config模块中的CURRENT_DIR_PATH变量确保使用正确的运行时路径
config.CURRENT_DIR_PATH = app_dir
# 定义需要确保存在的文件夹
folders_to_ensure = ['Export_Json', 'Evaluate_Result']
# 检查并创建必要的文件夹
for folder in folders_to_ensure:
folder_path = os.path.join(app_dir, folder)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
print(f'已创建文件夹: {folder_path}')
""")
# 运行PyInstaller
PyInstaller.__main__.run(pyinstaller_args)
# 删除临时的运行时钩子文件
if os.path.exists('runtime_hook.py'):
os.remove('runtime_hook.py')
print("打包完成!可执行文件位于 dist 文件夹中。")
print("注意运行可执行文件后用户可以在Export_Json文件夹中放入文件程序会将结果输出到Evaluate_Result文件夹。")
print("程序可以通过界面上的'退出程序'按钮正常关闭。")