Auto-clean old dist builds and copy config.json
This commit is contained in:
@@ -12,28 +12,41 @@ import sys
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
|
||||||
def build():
|
def build():
|
||||||
system = platform.system()
|
system = platform.system()
|
||||||
project_dir = Path(__file__).parent
|
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
|
# Basis-Argumente für PyInstaller
|
||||||
args = [
|
args = [
|
||||||
sys.executable,
|
sys.executable,
|
||||||
"-m", "PyInstaller",
|
"-m", "PyInstaller",
|
||||||
"--onefile",
|
"--onefile",
|
||||||
"--windowed",
|
"--windowed",
|
||||||
"--name", "fcco-Converter",
|
"--name", app_name,
|
||||||
"--clean",
|
"--clean",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Icon hinzufügen (wenn vorhanden)
|
# Icon hinzufügen (wenn vorhanden)
|
||||||
icon_path = project_dir / "icon.ico"
|
icon_path = project_dir / "icon.ico"
|
||||||
if icon_path.exists():
|
if icon_path.exists():
|
||||||
if system == "Windows":
|
args.extend(["--icon", str(icon_path)])
|
||||||
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)
|
# Versteckte Imports (die PyInstaller evtl. nicht automatisch findet)
|
||||||
hidden_imports = [
|
hidden_imports = [
|
||||||
@@ -66,8 +79,13 @@ def build():
|
|||||||
|
|
||||||
result = subprocess.run(args, cwd=str(project_dir))
|
result = subprocess.run(args, cwd=str(project_dir))
|
||||||
if result.returncode == 0:
|
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()
|
||||||
print(f"Build erfolgreich! Ausgabe in: {project_dir / 'dist'}")
|
print(f"Build erfolgreich! Ausgabe in: {dist_dir}")
|
||||||
else:
|
else:
|
||||||
print()
|
print()
|
||||||
print(f"Build fehlgeschlagen (Code {result.returncode}).")
|
print(f"Build fehlgeschlagen (Code {result.returncode}).")
|
||||||
|
|||||||
Reference in New Issue
Block a user