-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
156 lines (137 loc) · 5.22 KB
/
build.ps1
File metadata and controls
156 lines (137 loc) · 5.22 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
# PyInstaller Build Script - TOTP Password Manager
# Using UPX compression optimization, single file mode, no console window
# Configuration parameters
$UPX_PATH = "F:\Program Files\upx-5.0.2-win64\upx.exe"
$ICON_PATH = "icon.ico"
$MAIN_FILE = "main.py"
$OUTPUT_NAME = "totp_app"
$PROJECT_PATH = $PWD
# Check if UPX exists
if (-not (Test-Path $UPX_PATH)) {
Write-Host "Warning: UPX path does not exist: $UPX_PATH" -ForegroundColor Yellow
Write-Host "Will proceed without UPX compression" -ForegroundColor Yellow
$UPX_PATH = $null
}
# Check if icon file exists
if (-not (Test-Path $ICON_PATH)) {
Write-Host "Warning: Icon file does not exist: $ICON_PATH" -ForegroundColor Yellow
$ICON_PATH = ""
}
# Build PyInstaller command arguments
$PyInstallerArgs = @(
"--optimize","1"
"--onefile", # Single file mode
"--noconsole", # No console window
"--name=$OUTPUT_NAME", # Output filename
"--clean", # Clean temporary files
"--distpath", "dist", # Output directory
"--workpath", "build", # Working directory
"--specpath", ".", # Spec file directory
"--add-data", "icon.ico;.", # Include icon file
"--add-data", "data;data" # Include data directory
)
# Add UPX parameters (if exists)
if ($UPX_PATH -ne $null) {
$PyInstallerArgs += @(
"--upx-dir", (Split-Path $UPX_PATH -Parent)
)
}
# Add icon parameter (if exists)
if ($ICON_PATH -ne "") {
$PyInstallerArgs += "--icon=$ICON_PATH"
}
# Exclude unnecessary libraries
$PyInstallerArgs += @(
"--exclude-module", "tkinter",
"--exclude-module", "matplotlib",
"--exclude-module", "scipy",
"--exclude-module", "numpy",
"--exclude-module", "pandas",
"--exclude-module", "PIL",
"--exclude-module", "PyQt5",
"--exclude-module", "wx"
)
# Add hidden imports (PySide6 and cryptography related)
$PyInstallerArgs += @(
"--hidden-import", "PySide6",
"--hidden-import", "PySide6.QtCore",
"--hidden-import", "PySide6.QtGui",
"--hidden-import", "PySide6.QtWidgets",
"--hidden-import", "PySide6.QtUiTools",
"--hidden-import", "PySide6.QtNetwork",
"--hidden-import", "cryptography",
"--hidden-import", "cryptography.hazmat",
"--hidden-import", "cryptography.hazmat.backends",
"--hidden-import", "cryptography.hazmat.primitives",
"--hidden-import", "cryptography.hazmat.primitives.kdf.pbkdf2",
"--hidden-import", "pyotp"
)
# Add main file
$PyInstallerArgs += $MAIN_FILE
Write-Host "Starting TOTP Password Manager build..." -ForegroundColor Green
Write-Host "Project path: $PROJECT_PATH" -ForegroundColor Cyan
if ($UPX_PATH -ne $null) {
Write-Host "UPX path: $UPX_PATH" -ForegroundColor Cyan
} else {
Write-Host "UPX: Not used" -ForegroundColor Yellow
}
Write-Host "Icon file: $ICON_PATH" -ForegroundColor Cyan
Write-Host "Output name: $OUTPUT_NAME" -ForegroundColor Cyan
# Clean previous build files
if (Test-Path "build") {
Remove-Item -Recurse -Force "build" -ErrorAction SilentlyContinue
Write-Host "Cleaned build directory" -ForegroundColor Yellow
}
if (Test-Path "dist") {
Remove-Item -Recurse -Force "dist" -ErrorAction SilentlyContinue
Write-Host "Cleaned dist directory" -ForegroundColor Yellow
}
# Activate virtual environment if exists, else use global python
$pythonExe = $null
$vEnvPath = Join-Path $PROJECT_PATH ".venv"
$venvPython = Join-Path $vEnvPath "Scripts\python.exe"
if (Test-Path $venvPython) {
$pythonExe = $venvPython
Write-Host "Using virtual environment: $vEnvPath" -ForegroundColor Cyan
} else {
# Fall back to global `python`
try {
$pythonExe = (Get-Command python -ErrorAction Stop).Path
Write-Host "Using global Python: $pythonExe" -ForegroundColor Cyan
} catch {
Write-Host "Error: Python not found in PATH and no virtual environment at '$vEnvPath'" -ForegroundColor Red
exit 1
}
}
# Execute PyInstaller
try {
Write-Host "Running PyInstaller..." -ForegroundColor Green
& $pythonExe -m PyInstaller @PyInstallerArgs
if ($LASTEXITCODE -eq 0) {
Write-Host "Build completed successfully!" -ForegroundColor Green
Write-Host "Output file: dist\$OUTPUT_NAME.exe" -ForegroundColor Green
# Display file size
$OutputFile = "dist\$OUTPUT_NAME.exe"
if (Test-Path $OutputFile) {
$FileSize = (Get-Item $OutputFile).Length / 1MB
Write-Host "File size: $([math]::Round($FileSize, 2)) MB" -ForegroundColor Yellow
# Verify executable can run
Write-Host "Verifying executable..." -ForegroundColor Cyan
$Process = Start-Process -FilePath $OutputFile -PassThru -WindowStyle Hidden
Start-Sleep -Seconds 2
if (-not $Process.HasExited) {
$Process.Kill()
Write-Host "Executable verification passed" -ForegroundColor Green
} else {
Write-Host "Executable may have issues" -ForegroundColor Yellow
}
}
} else {
Write-Host "Build failed! Exit code: $LASTEXITCODE" -ForegroundColor Red
exit $LASTEXITCODE
}
}
catch {
Write-Host "Error during build process: $_" -ForegroundColor Red
exit 1
}