202 Zeilen
7.0 KiB
Python
202 Zeilen
7.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Metadaten-Crawler Launcher
|
|
==========================
|
|
Startet die Metadaten-Crawler Electron-Anwendung.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import platform
|
|
from pathlib import Path
|
|
|
|
|
|
class MetadatenCrawlerLauncher:
|
|
def __init__(self):
|
|
self.app_dir = Path(__file__).parent.absolute()
|
|
self.system = platform.system()
|
|
|
|
def check_node_installed(self):
|
|
"""Prüft ob Node.js installiert ist"""
|
|
try:
|
|
result = subprocess.run(['node', '--version'],
|
|
capture_output=True,
|
|
text=True)
|
|
if result.returncode == 0:
|
|
print(f"✓ Node.js gefunden: {result.stdout.strip()}")
|
|
return True
|
|
except FileNotFoundError:
|
|
pass
|
|
|
|
print("✗ Node.js ist nicht installiert!")
|
|
print(" Bitte installieren Sie Node.js von: https://nodejs.org/")
|
|
return False
|
|
|
|
def check_dependencies(self):
|
|
"""Prüft ob npm Pakete installiert sind"""
|
|
node_modules = self.app_dir / 'node_modules'
|
|
if not node_modules.exists():
|
|
print("⚠ Dependencies nicht gefunden. Installiere npm Pakete...")
|
|
return self.install_dependencies()
|
|
print("✓ Dependencies gefunden")
|
|
return True
|
|
|
|
def install_dependencies(self):
|
|
"""Installiert npm Dependencies"""
|
|
try:
|
|
print(" Führe 'npm install' aus...")
|
|
result = subprocess.run(['npm', 'install'],
|
|
cwd=self.app_dir,
|
|
capture_output=True,
|
|
text=True)
|
|
if result.returncode == 0:
|
|
print("✓ Dependencies erfolgreich installiert")
|
|
return True
|
|
else:
|
|
print(f"✗ Fehler bei der Installation: {result.stderr}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"✗ Fehler: {str(e)}")
|
|
return False
|
|
|
|
def check_executable(self):
|
|
"""Prüft ob eine ausführbare Datei existiert"""
|
|
if self.system == "Windows":
|
|
exe_path = self.app_dir / 'dist' / 'Metadaten-Crawler.exe'
|
|
if exe_path.exists():
|
|
return str(exe_path)
|
|
elif self.system == "Darwin": # macOS
|
|
app_path = self.app_dir / 'dist' / 'Metadaten-Crawler.app'
|
|
if app_path.exists():
|
|
return str(app_path)
|
|
elif self.system == "Linux":
|
|
app_path = self.app_dir / 'dist' / 'Metadaten-Crawler'
|
|
if app_path.exists():
|
|
return str(app_path)
|
|
return None
|
|
|
|
def start_development(self):
|
|
"""Startet die Anwendung im Entwicklungsmodus"""
|
|
print("\n🚀 Starte Metadaten-Crawler im Entwicklungsmodus...")
|
|
try:
|
|
subprocess.run(['npm', 'start'], cwd=self.app_dir)
|
|
except KeyboardInterrupt:
|
|
print("\n\nAnwendung beendet.")
|
|
except Exception as e:
|
|
print(f"✗ Fehler beim Starten: {str(e)}")
|
|
return False
|
|
return True
|
|
|
|
def start_executable(self, exe_path):
|
|
"""Startet die kompilierte Anwendung"""
|
|
print(f"\n🚀 Starte Metadaten-Crawler von: {exe_path}")
|
|
try:
|
|
if self.system == "Windows":
|
|
subprocess.run([exe_path])
|
|
elif self.system == "Darwin":
|
|
subprocess.run(['open', exe_path])
|
|
else:
|
|
subprocess.run([exe_path])
|
|
except Exception as e:
|
|
print(f"✗ Fehler beim Starten: {str(e)}")
|
|
return False
|
|
return True
|
|
|
|
def build_application(self):
|
|
"""Baut die Anwendung"""
|
|
print("\n🔨 Baue Metadaten-Crawler...")
|
|
try:
|
|
if self.system == "Windows":
|
|
cmd = ['npm', 'run', 'build-win']
|
|
elif self.system == "Darwin":
|
|
cmd = ['npm', 'run', 'build-mac']
|
|
else:
|
|
cmd = ['npm', 'run', 'build-linux']
|
|
|
|
result = subprocess.run(cmd, cwd=self.app_dir)
|
|
if result.returncode == 0:
|
|
print("✓ Build erfolgreich abgeschlossen")
|
|
return True
|
|
else:
|
|
print("✗ Build fehlgeschlagen")
|
|
return False
|
|
except Exception as e:
|
|
print(f"✗ Fehler beim Build: {str(e)}")
|
|
return False
|
|
|
|
def run(self):
|
|
"""Hauptmethode zum Starten der Anwendung"""
|
|
print("=" * 50)
|
|
print(" Metadaten-Crawler Launcher")
|
|
print("=" * 50)
|
|
print(f"System: {self.system}")
|
|
print(f"Arbeitsverzeichnis: {self.app_dir}")
|
|
print()
|
|
|
|
# Prüfe Node.js
|
|
if not self.check_node_installed():
|
|
return False
|
|
|
|
# Prüfe Dependencies
|
|
if not self.check_dependencies():
|
|
return False
|
|
|
|
# Prüfe ob ausführbare Datei existiert
|
|
exe_path = self.check_executable()
|
|
|
|
if len(sys.argv) > 1:
|
|
# Command line arguments
|
|
if sys.argv[1] == '--dev':
|
|
return self.start_development()
|
|
elif sys.argv[1] == '--build':
|
|
return self.build_application()
|
|
elif sys.argv[1] == '--exe' and exe_path:
|
|
return self.start_executable(exe_path)
|
|
|
|
# Interaktives Menü
|
|
print("\nWas möchten Sie tun?")
|
|
print("1. Entwicklungsmodus starten (npm start)")
|
|
if exe_path:
|
|
print("2. Kompilierte Anwendung starten")
|
|
print("3. Anwendung neu bauen")
|
|
else:
|
|
print("2. Anwendung bauen (erstellt .exe)")
|
|
print("0. Beenden")
|
|
|
|
while True:
|
|
try:
|
|
choice = input("\nIhre Wahl: ").strip()
|
|
|
|
if choice == '0':
|
|
print("Auf Wiedersehen!")
|
|
return True
|
|
elif choice == '1':
|
|
return self.start_development()
|
|
elif choice == '2':
|
|
if exe_path:
|
|
return self.start_executable(exe_path)
|
|
else:
|
|
if self.build_application():
|
|
exe_path = self.check_executable()
|
|
if exe_path:
|
|
print("\n✓ Build erfolgreich! Möchten Sie die Anwendung starten? (j/n)")
|
|
if input().lower() == 'j':
|
|
return self.start_executable(exe_path)
|
|
elif choice == '3' and exe_path:
|
|
return self.build_application()
|
|
else:
|
|
print("Ungültige Eingabe. Bitte erneut versuchen.")
|
|
except KeyboardInterrupt:
|
|
print("\n\nProgramm beendet.")
|
|
return True
|
|
|
|
|
|
def main():
|
|
"""Hauptfunktion"""
|
|
launcher = MetadatenCrawlerLauncher()
|
|
launcher.run()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |