-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_spec.py
More file actions
156 lines (134 loc) · 4.25 KB
/
build_spec.py
File metadata and controls
156 lines (134 loc) · 4.25 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
"""
Advanced build script that generates platform-specific .spec files for PyInstaller.
This provides more control over the build process and can be customized further.
Usage:
python build_spec.py
pyinstaller PPTCommandExecutor.spec
"""
import sys
import platform
from pathlib import Path
# Detect platform
PLATFORM = platform.system().lower()
IS_WINDOWS = PLATFORM == "windows"
IS_MACOS = PLATFORM == "darwin"
IS_LINUX = PLATFORM == "linux"
# Configuration
APP_NAME = "PPTCommandExecutor"
MAIN_SCRIPT = "main.py"
# Platform-specific paths
if IS_WINDOWS:
ICON_FILE = "assets/favicon.ico"
PATH_SEP = ";"
WINDOWED = True
elif IS_MACOS:
ICON_FILE = "assets/favicon.icns"
PATH_SEP = ":"
WINDOWED = True
else: # Linux
ICON_FILE = "assets/favicon.png"
PATH_SEP = ":"
WINDOWED = False # Keep console on Linux for debugging
# Generate .spec file content
SPEC_CONTENT = f"""# -*- mode: python ; coding: utf-8 -*-
# PyInstaller spec file for {APP_NAME}
# Generated for {PLATFORM}
block_cipher = None
a = Analysis(
['{MAIN_SCRIPT}'],
pathex=[],
binaries=[],
datas=[('assets', 'assets')],
hiddenimports=[
'flask',
'flask_cors',
'socketio',
'gevent',
'gevent.lock',
'geventwebsocket',
'PIL',
'PIL._tkinter_finder',
'customtkinter',
'qrcode',
'pyautogui',
'engineio.async_drivers.gevent',
'src.platform.windows',
'src.platform.linux',
'src.platform.darwin',
],
hookspath=[],
hooksconfig={{}},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='{APP_NAME}',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console={'not ' + str(WINDOWED)},
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
{'icon="' + ICON_FILE + '",' if Path(ICON_FILE).exists() else ''}
)
{'# macOS-specific app bundle' if IS_MACOS else ''}
{'app = BUNDLE(' if IS_MACOS else '# app = BUNDLE('}
{' exe,' if IS_MACOS else '# exe,'}
{' name="' + APP_NAME + '.app",' if IS_MACOS else '# name="' + APP_NAME + '.app",'}
{' icon="' + ICON_FILE + '",' if IS_MACOS and Path(ICON_FILE).exists() else '# icon=None,'}
{' bundle_identifier="com.pptcommandexecutor.app",' if IS_MACOS else '# bundle_identifier=None,'}
{' info_plist={{' if IS_MACOS else '# info_plist={'}
{' "NSHighResolutionCapable": "True",' if IS_MACOS else '# "NSHighResolutionCapable": "True",'}
{' "LSUIElement": "0",' if IS_MACOS else '# "LSUIElement": "0",'}
{' }},' if IS_MACOS else '# },'}
{')' if IS_MACOS else '# )'}
"""
def generate_spec():
"""Generate platform-specific .spec file."""
spec_file = Path(f"{APP_NAME}.spec")
print("="*60)
print(f"Generating {spec_file} for {PLATFORM}")
print("="*60)
# Check if main script exists
if not Path(MAIN_SCRIPT).exists():
print(f"ERROR: {MAIN_SCRIPT} not found")
sys.exit(1)
# Check icon
if Path(ICON_FILE).exists():
print(f"✓ Icon file: {ICON_FILE}")
else:
print(f"WARNING: Icon file not found: {ICON_FILE}")
if IS_MACOS:
print(" To create .icns: sips -s format icns assets/favicon.png --out assets/favicon.icns")
# Write spec file
spec_file.write_text(SPEC_CONTENT)
print(f"\n✓ Generated {spec_file}")
print("\nNext steps:")
print(f" 1. Install PyInstaller: pip install pyinstaller")
print(f" 2. Build executable: pyinstaller {spec_file}")
print(f" 3. Find output in: dist/{APP_NAME}{'/' if IS_WINDOWS else '.app' if IS_MACOS else ''}")
if IS_WINDOWS:
print(f"\nWindows executable will be: dist/{APP_NAME}.exe")
elif IS_MACOS:
print(f"\nmacOS application will be: dist/{APP_NAME}.app")
else:
print(f"\nLinux executable will be: dist/{APP_NAME}")
if __name__ == "__main__":
generate_spec()