Auto-clean old dist builds and copy config.json

This commit is contained in:
joel
2026-07-20 18:07:14 +02:00
parent 790cdc9911
commit eb222dd2ca
+24 -6
View File
@@ -12,27 +12,40 @@ import sys
from pathlib import Path
import shutil
def build():
system = platform.system()
project_dir = Path(__file__).parent
dist_dir = project_dir / "dist"
# Alte App löschen
app_name = "fcco-Converter"
if system == "Darwin":
old_app = dist_dir / f"{app_name}.app"
else:
old_app = dist_dir / f"{app_name}.exe"
if old_app.exists():
if old_app.is_dir():
shutil.rmtree(old_app)
else:
old_app.unlink()
# Basis-Argumente für PyInstaller
args = [
sys.executable,
"-m", "PyInstaller",
"--onefile",
"--windowed",
"--name", "fcco-Converter",
"--name", app_name,
"--clean",
]
# Icon hinzufügen (wenn vorhanden)
icon_path = project_dir / "icon.ico"
if icon_path.exists():
if system == "Windows":
args.extend(["--icon", str(icon_path)])
elif system == "Darwin":
# macOS braucht .icns .ico funktioniert trotzdem als Fallback
args.extend(["--icon", str(icon_path)])
# Versteckte Imports (die PyInstaller evtl. nicht automatisch findet)
@@ -66,8 +79,13 @@ def build():
result = subprocess.run(args, cwd=str(project_dir))
if result.returncode == 0:
# Kopiere config.json in den dist Ordner, damit die App sie direkt findet
config_src = project_dir / "config.json"
if config_src.exists():
shutil.copy(config_src, dist_dir / "config.json")
print()
print(f"Build erfolgreich! Ausgabe in: {project_dir / 'dist'}")
print(f"Build erfolgreich! Ausgabe in: {dist_dir}")
else:
print()
print(f"Build fehlgeschlagen (Code {result.returncode}).")