-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_executable.py
More file actions
236 lines (198 loc) · 6.72 KB
/
build_executable.py
File metadata and controls
236 lines (198 loc) · 6.72 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
"""
Build script for creating distributable executables.
"""
import subprocess
import sys
import shutil
from pathlib import Path
from build_config import *
def install_build_dependencies():
"""Install required build dependencies."""
dependencies = [
"pyinstaller",
"pillow",
"piexif",
"PySimpleGUI",
"click",
]
print("Installing build dependencies...")
for dep in dependencies:
try:
subprocess.run([sys.executable, "-m", "pip", "install", dep],
check=True, capture_output=True)
print(f"[OK] {dep}")
except subprocess.CalledProcessError as e:
print(f"[ERROR] Failed to install {dep}: {e}")
return False
return True
def create_cli_executable():
"""Create CLI executable."""
print("\nBuilding CLI executable...")
# Basic PyInstaller command
cmd = [
sys.executable, "-m", "PyInstaller",
"--name", f"{PROJECT_NAME}-CLI",
"--onefile",
"--console",
"--distpath", str(DIST_DIR),
"--workpath", str(BUILD_DIR),
"--specpath", str(BUILD_DIR),
"--paths", str(SRC_DIR), # Add source directory to Python path
str(CLI_ENTRY)
]
# Add hidden imports
for import_name in PYINSTALLER_OPTIONS["hidden_imports"]:
cmd.extend(["--hidden-import", import_name])
# Add platform-specific options
platform_config = get_platform_config()
if "icon" in platform_config and Path(platform_config["icon"]).exists():
cmd.extend(["--icon", platform_config["icon"]])
try:
subprocess.run(cmd, check=True, cwd=PROJECT_ROOT)
print("[OK] CLI executable created successfully!")
return True
except subprocess.CalledProcessError as e:
print(f"[ERROR] Failed to create CLI executable: {e}")
return False
def create_gui_executable():
"""Create GUI executable."""
print("\nBuilding GUI executable...")
cmd = [
sys.executable, "-m", "PyInstaller",
"--name", f"{PROJECT_NAME}-GUI",
"--onefile",
"--windowed", # No console window
"--distpath", str(DIST_DIR),
"--workpath", str(BUILD_DIR),
"--specpath", str(BUILD_DIR),
"--paths", str(SRC_DIR), # Add source directory to Python path
str(GUI_ENTRY)
]
# Add hidden imports
for import_name in PYINSTALLER_OPTIONS["hidden_imports"]:
cmd.extend(["--hidden-import", import_name])
# Add platform-specific options
platform_config = get_platform_config()
if "icon" in platform_config and Path(platform_config["icon"]).exists():
cmd.extend(["--icon", platform_config["icon"]])
try:
subprocess.run(cmd, check=True, cwd=PROJECT_ROOT)
print("[OK] GUI executable created successfully!")
return True
except subprocess.CalledProcessError as e:
print(f"[ERROR] Failed to create GUI executable: {e}")
return False
def create_version_info():
"""Create version information file for Windows."""
if not sys.platform.startswith('win'):
return
version_info = f"""
# UTF-8
VSVersionInfo(
ffi=FixedFileInfo(
filevers=({VERSION.replace('-beta', '').replace('.', ', ')}, 0),
prodvers=({VERSION.replace('-beta', '').replace('.', ', ')}, 0),
mask=0x3f,
flags=0x0,
OS=0x40004,
fileType=0x1,
subtype=0x0,
date=(0, 0)
),
kids=[
StringFileInfo(
[
StringTable(
u'040904B0',
[StringStruct(u'CompanyName', u'{AUTHOR}'),
StringStruct(u'FileDescription', u'{DESCRIPTION}'),
StringStruct(u'FileVersion', u'{VERSION}'),
StringStruct(u'InternalName', u'{PROJECT_NAME}'),
StringStruct(u'LegalCopyright', u'Copyright © 2025 {AUTHOR}'),
StringStruct(u'OriginalFilename', u'{PROJECT_NAME}.exe'),
StringStruct(u'ProductName', u'{PROJECT_NAME}'),
StringStruct(u'ProductVersion', u'{VERSION}')])
]),
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
]
)"""
version_file = PROJECT_ROOT / "version_info.txt"
version_file.write_text(version_info)
print("Created version information file")
def create_release_package():
"""Create release package with documentation."""
print("\nCreating release package...")
# Create release directory
release_dir = DIST_DIR / f"{PROJECT_NAME}-{VERSION}"
release_dir.mkdir(exist_ok=True)
# Copy executables
for exe_file in DIST_DIR.glob("*.exe"):
if exe_file.is_file():
shutil.copy2(exe_file, release_dir)
# Copy documentation
docs_to_copy = [
"README.md",
"Instructions.md",
"changelog.md",
"LICENSE" if Path("LICENSE").exists() else None
]
for doc in docs_to_copy:
if doc and Path(doc).exists():
shutil.copy2(doc, release_dir)
# Create quick start guide
quick_start = release_dir / "QUICK_START.txt"
quick_start.write_text(f"""
{PROJECT_NAME} v{VERSION} - Quick Start Guide
=== Installation ===
1. Extract all files to a folder of your choice
2. No additional installation required!
=== Usage ===
Command Line Interface:
- Run: {PROJECT_NAME}-CLI.exe --help
- View image metadata: {PROJECT_NAME}-CLI.exe view image.jpg
- Remove metadata: {PROJECT_NAME}-CLI.exe strip image.jpg
Graphical Interface:
- Run: {PROJECT_NAME}-GUI.exe
- Use the file browser to select images
- Click operations to modify metadata
=== Documentation ===
- Full instructions: Instructions.md
- Change log: changelog.md
- Project info: README.md
=== Support ===
For help and bug reports, see the project documentation.
Enjoy using {PROJECT_NAME}!
""")
print(f"Release package created: {release_dir}")
return release_dir
def main():
"""Main build process."""
print(f"Building {PROJECT_NAME} v{VERSION}")
print("=" * 50)
# Create build directories
create_build_directories()
# Install dependencies
if not install_build_dependencies():
return False
# Create version info for Windows
create_version_info()
# Build executables
cli_success = create_cli_executable()
gui_success = create_gui_executable()
if cli_success and gui_success:
# Create release package
release_dir = create_release_package()
print("\n" + "=" * 50)
print("Build completed successfully!")
print(f"Release package: {release_dir}")
print("\nNext steps:")
print("1. Test executables on target platforms")
print("2. Create installer packages")
print("3. Prepare for beta distribution")
return True
else:
print("\nBuild failed!")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)