Repository navigation
Expand file tree
/
Copy pathbuild.py
More file actions
142 lines (113 loc) · 4.44 KB
/
Copy pathbuild.py
File metadata and controls
142 lines (113 loc) · 4.44 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
"""Automated production build script for ShellPDF binary & Inno Setup installer."""
from __future__ import annotations
import os
import shutil
import subprocess
import sys
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parent
def ensure_icons() -> Path:
"""Ensure multi-resolution icon assets exist."""
icon_path = PROJECT_ROOT / "icons" / "app.ico"
if icon_path.exists():
return icon_path
print("Generating application icon assets...")
os.makedirs(PROJECT_ROOT / "icons", exist_ok=True)
try:
from PIL import Image, ImageDraw
sizes = [(256, 256), (128, 128), (64, 64), (48, 48), (32, 32), (16, 16)]
images = []
for w, h in sizes:
img = Image.new("RGBA", (w, h), (0, 0, 0, 0))
draw = ImageDraw.Draw(img)
m = max(1, w // 16)
c = max(2, w // 8)
draw.rounded_rectangle(
[m, m, w - m, h - m],
radius=c,
fill=(61, 89, 161, 255),
outline=(122, 162, 247, 255),
width=max(1, w // 32),
)
images.append(img)
images[0].save(icon_path, format="ICO", sizes=[img.size for img in images])
images[0].save(PROJECT_ROOT / "icons" / "app.png", format="PNG")
print(f"Icon assets saved to '{icon_path}'")
except Exception as exc:
print(f"Icon generation skipped: {exc}")
return icon_path
def generate_installer_scripts() -> None:
"""Generate Windows Registry installer & uninstaller scripts."""
print("Generating Windows Registry installer scripts...")
try:
from registry.context_menu import WindowsRegistryManager
mgr = WindowsRegistryManager()
mgr.generate_bat_scripts(PROJECT_ROOT / "installer")
print("Registry installer scripts generated in 'installer/'")
except Exception as exc:
print(f"Registry script generation failed: {exc}")
def build_pyinstaller_binary() -> None:
"""Compile ShellPDF into standalone executable using PyInstaller."""
print("Building ShellPDF PyInstaller executable...")
icon_path = ensure_icons()
dist_dir = PROJECT_ROOT / "dist"
build_dir = PROJECT_ROOT / "build"
cmd = [
sys.executable,
"-m",
"PyInstaller",
"--noconfirm",
"--onedir",
"--windowed",
"--name=ShellPDF",
f"--icon={icon_path}",
f"--paths={PROJECT_ROOT}",
str(PROJECT_ROOT / "main.py"),
]
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
print(f"PyInstaller build complete! Target directory: '{dist_dir / 'ShellPDF'}'")
def build_inno_setup_installer() -> None:
"""Compile Inno Setup setup.iss script if ISCC compiler is installed."""
iss_file = PROJECT_ROOT / "installer" / "setup.iss"
if not iss_file.exists():
print(f"Inno Setup script not found at '{iss_file}'")
return
# Locate ISCC.exe
iscc_path = shutil.which("ISCC") or shutil.which("ISCC.exe")
if not iscc_path:
user_appdata = os.getenv("LOCALAPPDATA", "")
candidates = [
Path(r"C:\Program Files (x86)\Inno Setup 6\ISCC.exe"),
Path(r"C:\Program Files\Inno Setup 6\ISCC.exe"),
Path(user_appdata) / "Programs" / "Inno Setup 6" / "ISCC.exe",
Path(r"C:\Program Files (x86)\Inno Setup 5\ISCC.exe"),
]
for candidate in candidates:
if candidate.exists():
iscc_path = str(candidate)
break
if not iscc_path:
print("Inno Setup Compiler (ISCC.exe) not found on build machine.")
print("Skipping installer compilation. Install Inno Setup 6 to compile 'installer/setup.iss'.")
return
print(f"Compiling Inno Setup installer using ISCC: '{iscc_path}'...")
try:
subprocess.run([iscc_path, str(iss_file)], check=True)
print("Inno Setup installer compiled successfully! Output in 'output/ShellPDF-Setup-v1.0.0.exe'")
except Exception as exc:
print(f"Inno Setup compilation failed: {exc}")
def main() -> None:
"""Run complete build pipeline."""
print("=" * 60)
print(" ShellPDF Automated Production Build Pipeline")
print("=" * 60)
ensure_icons()
generate_installer_scripts()
build_pyinstaller_binary()
build_inno_setup_installer()
print("=" * 60)
print("Build pipeline completed successfully!")
print("=" * 60)
if __name__ == "__main__":
main()