#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 用于打包 bcrypt 加密版本的密码修改器 """ import os import sys import shutil from datetime import datetime # 项目根目录 PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) # 主脚本路径 MAIN_SCRIPT = os.path.join(PROJECT_ROOT, '修改数据库的哈希密码和原始密码做桌面客户端源代码.py') # 输出目录 BUILD_DIR = os.path.join(PROJECT_ROOT, 'build', '密码修改器(bcrypt加密版本)') DIST_DIR = os.path.join(PROJECT_ROOT, 'dist', '密码修改器(bcrypt加密版本)') # 应用名称 APP_NAME = '密码修改器(bcrypt加密版本)' # 资源目录 DB_EXCEL_DIR = os.path.join(PROJECT_ROOT, 'dbExcel') def run_command(cmd): """执行命令并返回结果""" print(f"执行命令: {cmd}") result = os.system(cmd) if result != 0: print(f"命令执行失败: {cmd}") sys.exit(1) def main(): """主函数""" # 确保目录存在 os.makedirs(BUILD_DIR, exist_ok=True) os.makedirs(DIST_DIR, exist_ok=True) # 清理旧的构建文件 if os.path.exists(BUILD_DIR): shutil.rmtree(BUILD_DIR) if os.path.exists(DIST_DIR): shutil.rmtree(DIST_DIR) # 创建PyInstaller命令 pyinstaller_cmd = [ 'pyinstaller', '--name', APP_NAME, '--onefile', '--windowed', '--icon', 'NONE', # 可以替换为实际图标路径 '--distpath', DIST_DIR, '--workpath', BUILD_DIR, '--add-data', f'{DB_EXCEL_DIR};dbExcel', '--hidden-import', 'mysql.connector', '--hidden-import', 'bcrypt', '--hidden-import', 'pandas', '--hidden-import', 'openpyxl', MAIN_SCRIPT ] # 执行PyInstaller命令 run_command(' '.join(pyinstaller_cmd)) # 复制数据库信息目录到dist目录 dist_db_excel = os.path.join(DIST_DIR, 'dbExcel') if not os.path.exists(dist_db_excel): shutil.copytree(DB_EXCEL_DIR, dist_db_excel) print(f"\n打包完成!") print(f"可执行文件位置: {os.path.join(DIST_DIR, f'{APP_NAME}.exe')}") print(f"构建时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") if __name__ == '__main__': main()