hyb
2026-01-30 7657e1b2fa251a2ea372710ad75cb395a3c0e374
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
用于打包 合并版 密码修改器(支持bcrypt和argon2id加密)
"""
 
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', '密码修改器(合并版)')
DIST_DIR = os.path.join(PROJECT_ROOT, 'dist', '密码修改器(合并版)')
 
# 应用名称
APP_NAME = '数据库密码批量修改工具(合并版)'
 
# 资源目录
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', 'argon2',
        '--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()