pip install of pyinstaller/pystray/pillow was a separate manual step the README only mentioned in prose, so the script silently died on missing packages -- especially bad on Explorer double-click, where the window closes before any error is visible. Consolidate all dependencies into requirements.txt (also used by README's plain "pip install -r" flow), have the script install it itself, wrap the whole build in try/catch with exit-code checks after every native call, and pause on both success and failure unless -NoPause is passed. Also move the build output from %LOCALAPPDATA% into dist/ next to the script, so it's easy to find and matches the already-gitignored dist/ entry.
98 lines
3.6 KiB
PowerShell
98 lines
3.6 KiB
PowerShell
# Baut VersaPadViewer.exe (PyInstaller --onedir) und kopiert das Ergebnis
|
|
# nach $projectDir\dist\VersaPadViewer.
|
|
#
|
|
# WICHTIG: Sowohl Bauen als auch Laufen muessen lokal passieren, NICHT auf
|
|
# dem Netzlaufwerk (Z:\Git\...):
|
|
# - Laufzeit: Windows blockiert das Nachladen der PyInstaller-_internal-
|
|
# DLLs von einem Netzwerkpfad (SMB-Share) ohne jede Fehlermeldung, der
|
|
# Prozess startet einfach nie.
|
|
# - Buildzeit: PyInstaller scheitert beim Kopieren von Tcl/Tk-tzdata (viele
|
|
# tief verschachtelte, lang benannte Zeitzonen-Ordner) mit
|
|
# "FileNotFoundError: [WinError 3]" -- Pfadlaengen-Problem auf dem
|
|
# SMB-Share, kombiniert mit dem eh schon langen Projektpfad.
|
|
#
|
|
# Deshalb: Quellcode zuerst nach lokal (%TEMP%) kopieren, dort bauen, danach
|
|
# das fertige Bundle nach $projectDir\dist kopieren. Z: wird nur zum Lesen
|
|
# der Quelldateien angefasst.
|
|
#
|
|
# Fehlerverhalten: Bei Doppelklick im Explorer schliesst sich das Fenster
|
|
# sofort nach Skriptende -- ohne Pause waeren Fehlermeldungen unsichtbar
|
|
# ("stirbt ohne jede Fehlermeldung"). Deshalb: alles in try/catch, im
|
|
# Fehlerfall UND am Ende eine Pause, ausser bei -NoPause (fuer CI/Automation).
|
|
|
|
param(
|
|
[switch]$NoPause
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$projectDir = $PSScriptRoot
|
|
$buildSrc = "$env:TEMP\versapad_build_src"
|
|
$localDir = "$projectDir\dist\VersaPadViewer"
|
|
$requirementsFile = "$projectDir\requirements.txt"
|
|
|
|
function Assert-LastExitCode([string]$step) {
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "$step ist fehlgeschlagen (Exit-Code $LASTEXITCODE) -- Ausgabe oben pruefen."
|
|
}
|
|
}
|
|
|
|
function Wait-ForKeyIfInteractive {
|
|
if ($NoPause) { return }
|
|
try {
|
|
Read-Host "Taste druecken zum Schliessen"
|
|
} catch {
|
|
# z.B. nicht-interaktiver Aufruf (stdin nicht verfuegbar) -- einfach ignorieren
|
|
}
|
|
}
|
|
|
|
try {
|
|
Write-Host "Pruefe Python-Installation..."
|
|
py --version
|
|
Assert-LastExitCode "'py --version' (ist Python installiert und im PATH?)"
|
|
|
|
if (-not (Test-Path $requirementsFile)) {
|
|
throw "requirements.txt nicht gefunden unter $requirementsFile"
|
|
}
|
|
Write-Host "Installiere/aktualisiere benoetigte Pakete aus requirements.txt..."
|
|
py -m pip install --quiet --disable-pip-version-check -r $requirementsFile
|
|
Assert-LastExitCode "Paketinstallation (pip install -r requirements.txt)"
|
|
|
|
if (Test-Path $buildSrc) {
|
|
Remove-Item $buildSrc -Recurse -Force
|
|
}
|
|
New-Item -ItemType Directory -Path $buildSrc | Out-Null
|
|
Copy-Item "$projectDir\*.py" -Destination $buildSrc
|
|
Copy-Item "$projectDir\icon.ico" -Destination $buildSrc
|
|
Copy-Item "$projectDir\icon.png" -Destination $buildSrc
|
|
|
|
Push-Location $buildSrc
|
|
try {
|
|
Write-Host "Baue mit PyInstaller (--onedir --windowed)..."
|
|
py -m PyInstaller --windowed --onedir --name VersaPadViewer `
|
|
--icon icon.ico --add-data "icon.png;." --add-data "icon.ico;." `
|
|
desktop_viewer.py --noconfirm
|
|
Assert-LastExitCode "PyInstaller-Build"
|
|
} finally {
|
|
Pop-Location
|
|
}
|
|
|
|
if (-not (Test-Path "$buildSrc\dist\VersaPadViewer\VersaPadViewer.exe")) {
|
|
throw "PyInstaller hat keine VersaPadViewer.exe erzeugt, obwohl der Exit-Code 0 war -- Build-Ausgabe oben pruefen."
|
|
}
|
|
|
|
if (Test-Path $localDir) {
|
|
Remove-Item $localDir -Recurse -Force
|
|
}
|
|
Copy-Item "$buildSrc\dist\VersaPadViewer" -Destination $localDir -Recurse
|
|
Remove-Item $buildSrc -Recurse -Force
|
|
|
|
Write-Host ""
|
|
Write-Host "Fertig: $localDir\VersaPadViewer.exe" -ForegroundColor Green
|
|
Wait-ForKeyIfInteractive
|
|
}
|
|
catch {
|
|
Write-Host ""
|
|
Write-Host "FEHLER: $($_.Exception.Message)" -ForegroundColor Red
|
|
Wait-ForKeyIfInteractive
|
|
exit 1
|
|
}
|