138 lines
3.9 KiB
Python
138 lines
3.9 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
fcco-Converter V1 – Build-Skript
|
||
|
||
Erstellt plattformabhängige Standalone-Executables (.exe / .app) mit PyInstaller.
|
||
Aufruf: python build.py
|
||
"""
|
||
|
||
import platform
|
||
import subprocess
|
||
import sys
|
||
import shutil
|
||
from pathlib import Path
|
||
|
||
|
||
def build():
|
||
system = platform.system()
|
||
project_dir = Path(__file__).parent.resolve()
|
||
dist_dir = project_dir / "dist"
|
||
|
||
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",
|
||
app_name,
|
||
"--clean",
|
||
]
|
||
|
||
# Icon hinzufügen (wenn vorhanden)
|
||
icon_path = project_dir / "icon.ico"
|
||
if icon_path.exists():
|
||
args.extend(["--icon", str(icon_path)])
|
||
if system == "Windows":
|
||
args.extend(["--add-data", f"{icon_path};."])
|
||
else:
|
||
args.extend(["--add-data", f"{icon_path}:."])
|
||
|
||
# settings.json mit einbinden
|
||
settings_path = project_dir / "settings.json"
|
||
if settings_path.exists():
|
||
if system == "Windows":
|
||
args.extend(["--add-data", f"{settings_path};."])
|
||
else:
|
||
args.extend(["--add-data", f"{settings_path}:."])
|
||
|
||
# Versteckte Imports
|
||
hidden_imports = [
|
||
"mutagen",
|
||
"mutagen.easyid3",
|
||
"mutagen.id3",
|
||
"static_ffmpeg",
|
||
"tkinter",
|
||
"tkinter.ttk",
|
||
"tkinter.filedialog",
|
||
"tkinter.messagebox",
|
||
"tkinter.simpledialog",
|
||
]
|
||
for imp in hidden_imports:
|
||
args.extend(["--hidden-import", imp])
|
||
|
||
# static_ffmpeg-Binaries einbinden (FFmpeg komplett offline bündeln)
|
||
try:
|
||
import static_ffmpeg
|
||
|
||
print("Lade FFmpeg-Binaries herunter (falls noch nicht vorhanden)...")
|
||
static_ffmpeg.run.get_or_fetch_platform_executables_else_raise()
|
||
|
||
sf_path = Path(static_ffmpeg.__file__).parent
|
||
if system == "Windows":
|
||
args.extend(["--add-data", f"{sf_path};static_ffmpeg"])
|
||
else:
|
||
args.extend(["--add-data", f"{sf_path}:static_ffmpeg"])
|
||
except Exception as e:
|
||
print(f"WARNUNG: static_ffmpeg konnte nicht gebündelt werden: {e}")
|
||
|
||
# Hauptdatei
|
||
args.append(str(project_dir / "main.py"))
|
||
|
||
print(f"Build für {system}...")
|
||
print(f"Befehl: {' '.join(args)}")
|
||
print()
|
||
|
||
result = subprocess.run(args, cwd=str(project_dir))
|
||
if result.returncode == 0:
|
||
# Kopiere settings.json in den dist Ordner
|
||
if settings_path.exists():
|
||
shutil.copy(settings_path, dist_dir / "settings.json")
|
||
|
||
# ZIP-Archiv für das Release erstellen
|
||
import tempfile
|
||
|
||
sys_name = "macos" if system == "Darwin" else system.lower()
|
||
zip_name = f"fcco-Converter-v1-{sys_name}"
|
||
zip_path = dist_dir / zip_name
|
||
|
||
with tempfile.TemporaryDirectory() as tmpdir:
|
||
tmp = Path(tmpdir)
|
||
|
||
# App/Exe ins Temp-Verzeichnis kopieren
|
||
if system == "Darwin":
|
||
shutil.copytree(dist_dir / f"{app_name}.app", tmp / f"{app_name}.app")
|
||
else:
|
||
shutil.copy(dist_dir / f"{app_name}.exe", tmp / f"{app_name}.exe")
|
||
|
||
# settings.json mit in die ZIP packen
|
||
if settings_path.exists():
|
||
shutil.copy(settings_path, tmp / "settings.json")
|
||
|
||
shutil.make_archive(str(zip_path), "zip", str(tmp))
|
||
|
||
print()
|
||
print(f"Build erfolgreich! Ausgabe in: {dist_dir}")
|
||
print(f"ZIP für Release: {zip_path}.zip")
|
||
else:
|
||
print()
|
||
print(f"Build fehlgeschlagen (Code {result.returncode}).")
|
||
sys.exit(1)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
build()
|