-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_exe.py
More file actions
113 lines (90 loc) · 2.69 KB
/
build_exe.py
File metadata and controls
113 lines (90 loc) · 2.69 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"""
The Bazaar Gate 打包脚本
使用 PyInstaller 将启动器打包为独立的可执行文件。
Author: The Bazaar Gate Team
Version: 1.3.0
"""
import PyInstaller.__main__
import os
import sys
import traceback
from typing import List
BASE_DIR: str = os.path.dirname(os.path.abspath(__file__))
DIST_DIR: str = os.path.join(BASE_DIR, "dist")
OUTPUT_NAME: str = "TheBazaarGate"
REQUIRED_FILES: List[str] = ["launcher_tool.py", "language.csv"]
def check_required_files() -> bool:
"""
检查打包所需的必需文件是否存在。
Returns:
所有必需文件存在返回True,否则返回False
"""
missing_files = []
for f in REQUIRED_FILES:
file_path = os.path.join(DIST_DIR, f)
if not os.path.exists(file_path):
missing_files.append(file_path)
if missing_files:
print(f"Missing required files: {', '.join(missing_files)}")
return False
return True
def get_dist_file_path(filename: str) -> str:
"""
获取 dist 目录下文件的绝对路径。
Args:
filename: 文件名
Returns:
文件绝对路径
"""
return os.path.join(DIST_DIR, filename)
def build() -> int:
"""
执行打包流程。
Returns:
成功返回0,失败返回1
"""
if not check_required_files():
return 1
print("Building The Bazaar Gate...")
launcher_script_path = get_dist_file_path("launcher_tool.py")
language_csv_path = get_dist_file_path("language.csv")
try:
PyInstaller.__main__.run(
[
launcher_script_path,
"--onefile",
"--windowed",
f"--name={OUTPUT_NAME}",
"--icon=NONE",
f"--add-data={language_csv_path};.",
"--clean",
"--noconfirm",
]
)
print("\nBuild completed!")
print(f"Executable created at: {os.path.join('dist', f'{OUTPUT_NAME}.exe')}")
return 0
except SystemExit as e:
print(f"\nPyInstaller execution failed: {e}")
return 1
except OSError as e:
print(f"\nFilesystem error: {e}")
return 1
except RuntimeError as e:
print(f"\nBuild failed: {e}")
return 1
except ImportError as e:
print(f"\nDependency import failed: {e}")
return 1
except ValueError as e:
print(f"\nInvalid build argument: {e}")
return 1
except TypeError as e:
print(f"\nInvalid build argument type: {e}")
return 1
except AttributeError as e:
print(f"\nBuild tool error: {e}")
traceback.print_exc()
return 1
if __name__ == "__main__":
sys.exit(build())