-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_exe.py
More file actions
172 lines (144 loc) · 4.6 KB
/
Copy pathbuild_exe.py
File metadata and controls
172 lines (144 loc) · 4.6 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
#!/usr/bin/env python3
"""
GoatsPass — Build script for Windows EXE (and Linux binary)
Usage:
python build_exe.py # auto-detect platform
python build_exe.py --windows # cross-compile hint (run on Windows)
python build_exe.py --onefile # single .exe (default)
python build_exe.py --onedir # folder with exe (faster startup)
"""
import sys
import subprocess
import shutil
import platform
import argparse
from pathlib import Path
HERE = Path(__file__).parent
MAIN = HERE / "goatspass.py"
ICON = HERE / "icon.png"
ICON_ICO = HERE / "icon.ico"
DIST = HERE / "dist"
BUILD = HERE / "build"
IS_WIN = platform.system() == "Windows"
def banner():
print("\n GoatsPass — EXE Builder")
print(" " + "─" * 40)
def ensure_pyinstaller():
try:
import PyInstaller
print(f" [✓] PyInstaller {PyInstaller.__version__} found")
except ImportError:
print(" [~] Installing PyInstaller...")
flags = ["--quiet"]
if not IS_WIN:
flags.append("--break-system-packages")
subprocess.check_call([sys.executable, "-m", "pip", "install"] + flags + ["pyinstaller"])
print(" [✓] PyInstaller installed")
def png_to_ico():
"""Convert icon.png to icon.ico for Windows EXE"""
if ICON_ICO.exists():
print(f" [✓] icon.ico already exists")
return str(ICON_ICO)
if not ICON.exists():
print(" [!] No icon.png found, using default")
return None
try:
from PIL import Image
img = Image.open(ICON)
sizes = [(16,16),(32,32),(48,48),(64,64),(128,128),(256,256)]
ico_imgs = []
for s in sizes:
resized = img.resize(s, Image.LANCZOS)
if resized.mode != "RGBA":
resized = resized.convert("RGBA")
ico_imgs.append(resized)
ico_imgs[0].save(
ICON_ICO, format="ICO",
sizes=[i.size for i in ico_imgs],
append_images=ico_imgs[1:]
)
print(f" [✓] icon.ico created")
return str(ICON_ICO)
except Exception as e:
print(f" [!] Could not convert icon: {e}")
return None
def build(onefile=True):
banner()
ensure_pyinstaller()
icon_path = None
if IS_WIN:
icon_path = png_to_ico()
elif ICON.exists():
icon_path = str(ICON)
# Clean previous builds
for d in [DIST, BUILD]:
if d.exists():
shutil.rmtree(d)
print(f" [~] Cleaned {d.name}/")
cmd = [
sys.executable, "-m", "PyInstaller",
"--name", "GoatsPass",
"--clean",
"--noconfirm",
]
if onefile:
cmd.append("--onefile")
else:
cmd.append("--onedir")
# Windows: no console window
if IS_WIN:
cmd.append("--windowed")
if icon_path:
cmd += ["--icon", icon_path]
# Bundle icon.png as data file
if ICON.exists():
sep = ";" if IS_WIN else ":"
cmd += ["--add-data", f"{ICON}{sep}."]
# Hidden imports
cmd += [
"--hidden-import", "cryptography",
"--hidden-import", "argon2",
"--hidden-import", "PIL",
"--hidden-import", "tkinter",
]
cmd.append(str(MAIN))
print(f"\n [~] Running PyInstaller...")
print(f" [~] Mode: {'onefile' if onefile else 'onedir'}")
print()
result = subprocess.run(cmd, cwd=str(HERE))
if result.returncode != 0:
print("\n [ERROR] Build failed!")
sys.exit(1)
# Find output
if onefile:
if IS_WIN:
out = DIST / "GoatsPass.exe"
else:
out = DIST / "GoatsPass"
else:
if IS_WIN:
out = DIST / "GoatsPass" / "GoatsPass.exe"
else:
out = DIST / "GoatsPass" / "GoatsPass"
print()
if out.exists():
size_mb = out.stat().st_size / 1024 / 1024
print(f" ✅ Build successful!")
print(f" ─────────────────────────────────────")
print(f" Output: {out}")
print(f" Size: {size_mb:.1f} MB")
else:
print(f" ✅ Build done! Check dist/ folder")
print()
# Clean build artifacts (keep dist)
if BUILD.exists():
shutil.rmtree(BUILD)
spec_file = HERE / "GoatsPass.spec"
if spec_file.exists():
spec_file.unlink()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Build GoatsPass executable")
parser.add_argument("--onedir", action="store_true",
help="Build as folder (faster startup)")
args = parser.parse_args()
build(onefile=not args.onedir)