"feat: Add test paths and config settings for improved testing"

This commit is contained in:
Till Tomczak 2025-05-26 12:13:04 +02:00
parent c7a2f442e5
commit 80172951d7
3 changed files with 353 additions and 173 deletions

View File

@ -2,9 +2,22 @@ import os
import json
from datetime import timedelta
def get_env_variable(name: str, default: str = None) -> str:
"""
Holt eine Umgebungsvariable oder gibt den Standardwert zurück.
Args:
name: Name der Umgebungsvariable
default: Standardwert, falls die Variable nicht gesetzt ist
Returns:
str: Wert der Umgebungsvariable oder Standardwert
"""
return os.environ.get(name, default)
# Hardcodierte Konfiguration
SECRET_KEY = "7445630171969DFAC92C53CEC92E67A9CB2E00B3CB2F"
DATABASE_PATH = "../database/myp.db"
DATABASE_PATH = "C:/Users/TTOMCZA.EMEA/Dev/Projektarbeit-MYP/database/myp.db"
TAPO_USERNAME = "till.tomczak@mercedes-benz.com"
TAPO_PASSWORD = "744563017196A"
@ -19,7 +32,7 @@ PRINTERS = {
}
# Logging-Konfiguration
LOG_DIR = "logs"
LOG_DIR = "C:/Users/TTOMCZA.EMEA/Dev/Projektarbeit-MYP/backend/app/logs"
LOG_SUBDIRS = ["app", "scheduler", "auth", "jobs", "printers", "errors"]
LOG_LEVEL = "INFO"
LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
@ -34,8 +47,8 @@ SESSION_LIFETIME = timedelta(days=7)
# SSL-Konfiguration
SSL_ENABLED = get_env_variable("MYP_SSL_ENABLED", "True").lower() in ("true", "1", "yes")
SSL_CERT_PATH = os.path.join(BASE_DIR, "certs", "myp.crt")
SSL_KEY_PATH = os.path.join(BASE_DIR, "certs", "myp.key")
SSL_CERT_PATH = "C:/Users/TTOMCZA.EMEA/Dev/Projektarbeit-MYP/backend/app/certs/myp.crt"
SSL_KEY_PATH = "C:/Users/TTOMCZA.EMEA/Dev/Projektarbeit-MYP/backend/app/certs/myp.key"
SSL_HOSTNAME = get_env_variable("MYP_SSL_HOSTNAME", "raspberrypi")
# Scheduler-Konfiguration
@ -207,4 +220,20 @@ def create_simple_ssl_cert():
return None
except Exception as e:
print(f"Fehler beim Erstellen der SSL-Zertifikate: {e}")
return None
return None
# Debug-Informationen für Pfad-Überprüfung
if __name__ == "__main__":
print("=== Pfad-Konfiguration ===")
print(f"BASE_DIR: {BASE_DIR}")
print(f"PROJECT_ROOT: {PROJECT_ROOT}")
print(f"DATABASE_PATH: {DATABASE_PATH}")
print(f"LOG_DIR: {LOG_DIR}")
print(f"SSL_CERT_PATH: {SSL_CERT_PATH}")
print(f"SSL_KEY_PATH: {SSL_KEY_PATH}")
print()
print("=== Pfad-Existenz ===")
print(f"Datenbank existiert: {os.path.exists(DATABASE_PATH)}")
print(f"Log-Verzeichnis existiert: {os.path.exists(LOG_DIR)}")
print(f"SSL-Zertifikat existiert: {os.path.exists(SSL_CERT_PATH)}")
print(f"SSL-Schlüssel existiert: {os.path.exists(SSL_KEY_PATH)}")

40
backend/app/test_paths.py Normal file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env python3
"""Test-Skript für Pfad-Überprüfung"""
import os
import sys
# Aktuelles Verzeichnis hinzufügen
sys.path.append('.')
try:
from config.settings import (
BASE_DIR, PROJECT_ROOT, DATABASE_PATH,
LOG_DIR, SSL_CERT_PATH, SSL_KEY_PATH
)
print("=== Pfad-Konfiguration ===")
print(f"BASE_DIR: {BASE_DIR}")
print(f"PROJECT_ROOT: {PROJECT_ROOT}")
print(f"DATABASE_PATH: {DATABASE_PATH}")
print(f"LOG_DIR: {LOG_DIR}")
print(f"SSL_CERT_PATH: {SSL_CERT_PATH}")
print(f"SSL_KEY_PATH: {SSL_KEY_PATH}")
print()
print("=== Pfad-Existenz ===")
print(f"Datenbank existiert: {os.path.exists(DATABASE_PATH)}")
print(f"Log-Verzeichnis existiert: {os.path.exists(LOG_DIR)}")
print(f"SSL-Zertifikat existiert: {os.path.exists(SSL_CERT_PATH)}")
print(f"SSL-Schlüssel existiert: {os.path.exists(SSL_KEY_PATH)}")
print()
print("=== Absolute Pfade ===")
print(f"DATABASE_PATH absolut: {os.path.abspath(DATABASE_PATH)}")
print(f"LOG_DIR absolut: {os.path.abspath(LOG_DIR)}")
print(f"SSL_CERT_PATH absolut: {os.path.abspath(SSL_CERT_PATH)}")
except ImportError as e:
print(f"Import-Fehler: {e}")
except Exception as e:
print(f"Fehler: {e}")

View File

@ -1,8 +1,8 @@
# MYP Installer Control Center
# Zentrale Installationskonsole fuer die MYP-Plattform
# Version 2.0
# MYP Installer Control Center - Vollständige Windows-Installation
# Zentrale Installationskonsole für die MYP-Plattform
# Version 3.0 - Konsolidiert alle Setup-Funktionen
# Farbdefinitionen fuer bessere Lesbarkeit
# Farbdefinitionen für bessere Lesbarkeit
$ColorTitle = "Cyan"
$ColorSuccess = "Green"
$ColorError = "Red"
@ -10,7 +10,7 @@ $ColorWarning = "Yellow"
$ColorInfo = "Blue"
$ColorCommand = "White"
# Ueberpruefen, ob das Skript als Administrator ausgefuehrt wird
# Überprüfen, ob das Skript als Administrator ausgeführt wird
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
function Show-Header {
@ -19,13 +19,14 @@ function Show-Header {
Clear-Host
Write-Host "=============================================================" -ForegroundColor $ColorTitle
Write-Host " MYP INSTALLER CONTROL CENTER" -ForegroundColor $ColorTitle
Write-Host " Version 3.0" -ForegroundColor $ColorTitle
Write-Host "=============================================================" -ForegroundColor $ColorTitle
Write-Host " $Title" -ForegroundColor $ColorTitle
Write-Host "=============================================================" -ForegroundColor $ColorTitle
if (-not $isAdmin) {
Write-Host "HINWEIS: Dieses Skript laeuft ohne Administrator-Rechte." -ForegroundColor $ColorWarning
Write-Host "Einige Funktionen sind moeglicherweise eingeschraenkt." -ForegroundColor $ColorWarning
Write-Host "HINWEIS: Dieses Skript läuft ohne Administrator-Rechte." -ForegroundColor $ColorWarning
Write-Host "Einige Funktionen sind möglicherweise eingeschränkt." -ForegroundColor $ColorWarning
Write-Host "=============================================================" -ForegroundColor $ColorTitle
}
@ -55,16 +56,16 @@ function Exec-Command {
try {
Invoke-Expression $Command | Out-Host
if ($LASTEXITCODE -eq 0 -or $null -eq $LASTEXITCODE) {
Write-Host "Erfolgreich abgeschlossen!" -ForegroundColor $ColorSuccess
Write-Host "Erfolgreich abgeschlossen!" -ForegroundColor $ColorSuccess
return $true
} else {
Write-Host "Fehler beim Ausfuehren des Befehls. Exit-Code: $LASTEXITCODE" -ForegroundColor $ColorError
Write-Host "✗ Fehler beim Ausführen des Befehls. Exit-Code: $LASTEXITCODE" -ForegroundColor $ColorError
return $false
}
}
catch {
$errorMessage = $_.Exception.Message
Write-Host "Fehler: $errorMessage" -ForegroundColor $ColorError
Write-Host "Fehler: $errorMessage" -ForegroundColor $ColorError
return $false
}
}
@ -78,54 +79,60 @@ function Get-LocalIPAddress {
}
function Test-Dependencies {
Show-Header "Systemvoraussetzungen pruefen"
Show-Header "Systemvoraussetzungen prüfen"
Write-Host "Pruefe Abhaengigkeiten..." -ForegroundColor $ColorInfo
Write-Host "Prüfe Abhängigkeiten..." -ForegroundColor $ColorInfo
$pythonInstalled = Test-CommandExists "python"
if ($pythonInstalled) {
Write-Host "Python gefunden" -ForegroundColor $ColorSuccess
} else {
Write-Host "Python nicht gefunden" -ForegroundColor $ColorError
$dependencies = @{
"python" = "Python (3.6+)"
"pip" = "Python Package Manager"
"docker" = "Docker"
"docker-compose" = "Docker Compose"
"node" = "Node.js"
"npm" = "Node Package Manager"
"git" = "Git"
}
$pipInstalled = Test-CommandExists "pip"
if ($pipInstalled) {
Write-Host "Pip gefunden" -ForegroundColor $ColorSuccess
} else {
Write-Host "Pip nicht gefunden" -ForegroundColor $ColorError
$allInstalled = $true
foreach ($dep in $dependencies.GetEnumerator()) {
$installed = Test-CommandExists $dep.Key
if ($installed) {
Write-Host "$($dep.Value) gefunden" -ForegroundColor $ColorSuccess
} else {
Write-Host "$($dep.Value) nicht gefunden" -ForegroundColor $ColorError
$allInstalled = $false
}
}
$dockerInstalled = Test-CommandExists "docker"
if ($dockerInstalled) {
Write-Host "Docker gefunden" -ForegroundColor $ColorSuccess
} else {
Write-Host "Docker nicht gefunden" -ForegroundColor $ColorError
# Zusätzliche Informationen anzeigen
Write-Host ""
Write-Host "Zusätzliche Systeminformationen:" -ForegroundColor $ColorInfo
if (Test-CommandExists "python") {
$pythonVersion = python --version 2>&1
Write-Host "Python Version: $pythonVersion" -ForegroundColor $ColorCommand
}
$dockerComposeInstalled = Test-CommandExists "docker-compose"
if ($dockerComposeInstalled) {
Write-Host "Docker Compose gefunden" -ForegroundColor $ColorSuccess
} else {
Write-Host "Docker Compose nicht gefunden" -ForegroundColor $ColorError
if (Test-CommandExists "node") {
$nodeVersion = node --version 2>&1
Write-Host "Node.js Version: $nodeVersion" -ForegroundColor $ColorCommand
}
$nodeInstalled = Test-CommandExists "node"
if ($nodeInstalled) {
Write-Host "Node.js gefunden" -ForegroundColor $ColorSuccess
} else {
Write-Host "Node.js nicht gefunden" -ForegroundColor $ColorError
}
$npmInstalled = Test-CommandExists "npm"
if ($npmInstalled) {
Write-Host "NPM gefunden" -ForegroundColor $ColorSuccess
} else {
Write-Host "NPM nicht gefunden" -ForegroundColor $ColorError
if (Test-CommandExists "docker") {
$dockerVersion = docker --version 2>&1
Write-Host "Docker Version: $dockerVersion" -ForegroundColor $ColorCommand
}
Write-Host ""
Write-Host "Druecken Sie eine beliebige Taste, um fortzufahren..."
if ($allInstalled) {
Write-Host "✓ Alle Abhängigkeiten sind installiert!" -ForegroundColor $ColorSuccess
} else {
Write-Host "⚠ Einige Abhängigkeiten fehlen. Bitte installieren Sie diese vor der Verwendung." -ForegroundColor $ColorWarning
}
Write-Host ""
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
@ -137,7 +144,7 @@ function Setup-Hosts {
Write-Host "Bitte starten Sie das Skript als Administrator neu." -ForegroundColor $ColorWarning
Write-Host ""
Write-Host "Druecken Sie eine beliebige Taste, um fortzufahren..."
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
return
}
@ -148,11 +155,11 @@ function Setup-Hosts {
$hostsFile = "$env:windir\System32\drivers\etc\hosts"
Write-Host "Hosts-Datei: $hostsFile" -ForegroundColor $ColorInfo
# Pruefen, ob die Eintraege bereits existieren
# Prüfen, ob die Einträge bereits existieren
$frontendEntry = Select-String -Path $hostsFile -Pattern "m040tbaraspi001.de040.corpintra.net" -Quiet
$backendEntry = Select-String -Path $hostsFile -Pattern "raspberrypi" -Quiet
# Eintraege in die Hosts-Datei schreiben
# Einträge in die Hosts-Datei schreiben
Write-Host "Aktualisiere Hosts-Datei..." -ForegroundColor $ColorInfo
$hostsContent = Get-Content -Path $hostsFile
@ -161,7 +168,7 @@ function Setup-Hosts {
$hostsContent += ""
$hostsContent += "# MYP Frontend Host"
$hostsContent += "$localIP m040tbaraspi001.de040.corpintra.net m040tbaraspi001"
Write-Host "Frontend-Hostname hinzugefuegt" -ForegroundColor $ColorSuccess
Write-Host "Frontend-Hostname hinzugefügt" -ForegroundColor $ColorSuccess
} else {
Write-Host "Frontend-Hostname ist bereits konfiguriert" -ForegroundColor $ColorWarning
}
@ -170,7 +177,7 @@ function Setup-Hosts {
$hostsContent += ""
$hostsContent += "# MYP Backend Host"
$hostsContent += "$localIP raspberrypi"
Write-Host "Backend-Hostname hinzugefuegt" -ForegroundColor $ColorSuccess
Write-Host "Backend-Hostname hinzugefügt" -ForegroundColor $ColorSuccess
} else {
Write-Host "Backend-Hostname ist bereits konfiguriert" -ForegroundColor $ColorWarning
}
@ -191,7 +198,7 @@ function Setup-Hosts {
Write-Host " - Backend: raspberrypi" -ForegroundColor $ColorCommand
Write-Host ""
Write-Host "Druecken Sie eine beliebige Taste, um fortzufahren..."
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
@ -205,26 +212,31 @@ function Create-SSLCertificates {
$frontendCertFile = "$certDir/frontend.crt"
$frontendKeyFile = "$certDir/frontend.key"
Write-Host "Zertifikate werden fuer folgende Hostnamen erstellt:" -ForegroundColor $ColorInfo
Write-Host "Zertifikate werden für folgende Hostnamen erstellt:" -ForegroundColor $ColorInfo
# Hostname-Auswahl
Write-Host "1. Fuer lokale Entwicklung (localhost)" -ForegroundColor $ColorCommand
Write-Host "2. Fuer Raspberry Pi Deployment (raspberrypi)" -ForegroundColor $ColorCommand
Write-Host "3. Fuer Unternehmens-Setup (m040tbaraspi001.de040.corpintra.net)" -ForegroundColor $ColorCommand
Write-Host "1. Für lokale Entwicklung (localhost)" -ForegroundColor $ColorCommand
Write-Host "2. Für Raspberry Pi Deployment (raspberrypi)" -ForegroundColor $ColorCommand
Write-Host "3. Für Unternehmens-Setup (m040tbaraspi001.de040.corpintra.net)" -ForegroundColor $ColorCommand
$inputText = "Waehlen Sie eine Option (1-3)"
$choice = Read-Host $inputText
$choice = Read-Host "Wählen Sie eine Option (1-3, Standard: 1)"
$backendHostname = "localhost"
$frontendHostname = "localhost"
if ($choice -eq "2") {
$backendHostname = "raspberrypi"
$frontendHostname = "raspberrypi"
}
elseif ($choice -eq "3") {
$backendHostname = "raspberrypi"
$frontendHostname = "m040tbaraspi001.de040.corpintra.net"
switch ($choice) {
"2" {
$backendHostname = "raspberrypi"
$frontendHostname = "raspberrypi"
}
"3" {
$backendHostname = "raspberrypi"
$frontendHostname = "m040tbaraspi001.de040.corpintra.net"
}
default {
$backendHostname = "localhost"
$frontendHostname = "localhost"
}
}
Write-Host "Backend-Hostname: $backendHostname" -ForegroundColor $ColorInfo
@ -242,11 +254,11 @@ function Create-SSLCertificates {
$pythonInstalled = Test-CommandExists "python"
if ($pythonInstalled) {
# Ueberpruefen, ob cryptography installiert ist
# Überprüfen, ob cryptography installiert ist
$cryptographyInstalled = python -c "try: import cryptography; print('True'); except ImportError: print('False')" 2>$null
if ($cryptographyInstalled -ne "True") {
Write-Host "Installiere Python-Abhaengigkeit 'cryptography'..." -ForegroundColor $ColorWarning
Write-Host "Installiere Python-Abhängigkeit 'cryptography'..." -ForegroundColor $ColorWarning
Exec-Command "pip install cryptography" "Installiere cryptography-Paket"
}
@ -267,13 +279,13 @@ def create_self_signed_cert(cert_path, key_path, hostname="localhost"):
if cert_dir and not os.path.exists(cert_dir):
os.makedirs(cert_dir, exist_ok=True)
# Privaten Schluessel generieren
# Privaten Schlüssel generieren
private_key = rsa.generate_private_key(
public_exponent=65537,
key_size=4096,
)
# Schluesseldatei schreiben
# Schlüsseldatei schreiben
with open(key_path, "wb") as key_file:
key_file.write(private_key.private_bytes(
encoding=Encoding.PEM,
@ -283,9 +295,9 @@ def create_self_signed_cert(cert_path, key_path, hostname="localhost"):
# Aktuelles Datum und Ablaufdatum berechnen
now = datetime.datetime.now()
valid_until = now + datetime.timedelta(days=3650) # 10 Jahre gueltig
valid_until = now + datetime.timedelta(days=3650) # 10 Jahre gültig
# Name fuer das Zertifikat erstellen
# Name für das Zertifikat erstellen
subject = issuer = x509.Name([
x509.NameAttribute(NameOID.COMMON_NAME, hostname),
x509.NameAttribute(NameOID.ORGANIZATION_NAME, "Mercedes-Benz AG"),
@ -311,7 +323,8 @@ def create_self_signed_cert(cert_path, key_path, hostname="localhost"):
).add_extension(
x509.SubjectAlternativeName([
x509.DNSName(hostname),
x509.DNSName("localhost")
x509.DNSName("localhost"),
x509.IPAddress(ipaddress.IPv4Address("127.0.0.1"))
]),
critical=False,
).add_extension(
@ -339,10 +352,13 @@ def create_self_signed_cert(cert_path, key_path, hostname="localhost"):
with open(cert_path, "wb") as cert_file:
cert_file.write(cert.public_bytes(Encoding.PEM))
print(f"Selbstsigniertes SSL-Zertifikat fuer '{hostname}' erstellt:")
print(f"Selbstsigniertes SSL-Zertifikat für '{hostname}' erstellt:")
print(f"Zertifikat: {cert_path}")
print(f"Schluessel: {key_path}")
print(f"Gueltig fuer 10 Jahre.")
print(f"Schlüssel: {key_path}")
print(f"Gültig für 10 Jahre.")
# Import für IP-Adressen
import ipaddress
# Backend-Zertifikat erstellen
create_self_signed_cert('$backendCertFile', '$backendKeyFile', '$backendHostname')
@ -354,7 +370,7 @@ create_self_signed_cert('$frontendCertFile', '$frontendKeyFile', '$frontendHostn
$tempScriptPath = ".\temp_cert_script.py"
$certScript | Out-File -FilePath $tempScriptPath -Encoding utf8
# Python-Skript ausfuehren
# Python-Skript ausführen
try {
python $tempScriptPath
Write-Host "SSL-Zertifikate erfolgreich erstellt!" -ForegroundColor $ColorSuccess
@ -364,18 +380,18 @@ create_self_signed_cert('$frontendCertFile', '$frontendKeyFile', '$frontendHostn
Write-Host "Fehler beim Erstellen der SSL-Zertifikate: $errorMessage" -ForegroundColor $ColorError
}
finally {
# Temporaeres Skript loeschen
# Temporäres Skript löschen
if (Test-Path $tempScriptPath) {
Remove-Item -Path $tempScriptPath -Force
}
}
} else {
Write-Host "Python nicht gefunden. SSL-Zertifikate koennen nicht erstellt werden." -ForegroundColor $ColorError
Write-Host "Python nicht gefunden. SSL-Zertifikate können nicht erstellt werden." -ForegroundColor $ColorError
}
# Zertifikate im System installieren (optional)
if ($isAdmin) {
$installCerts = Read-Host "Moechten Sie die Zertifikate im System installieren? (j/n)"
$installCerts = Read-Host "Möchten Sie die Zertifikate im System installieren? (j/n, Standard: n)"
if ($installCerts -eq "j") {
if (Test-Path $backendCertFile) {
@ -392,13 +408,13 @@ create_self_signed_cert('$frontendCertFile', '$frontendKeyFile', '$frontendHostn
Write-Host "Hinweis: Um die Zertifikate im System zu installieren, starten Sie das Skript als Administrator." -ForegroundColor $ColorWarning
}
# Frontend fuer HTTPS konfigurieren
# Frontend für HTTPS konfigurieren
Write-Host ""
Write-Host "Moechten Sie das Frontend fuer HTTPS konfigurieren? (j/n)" -ForegroundColor $ColorInfo
Write-Host "Möchten Sie das Frontend für HTTPS konfigurieren? (j/n, Standard: j)" -ForegroundColor $ColorInfo
$configureFrontend = Read-Host
if ($configureFrontend -ne "n") {
Write-Host "Konfiguriere Frontend fuer HTTPS..." -ForegroundColor $ColorInfo
Write-Host "Konfiguriere Frontend für HTTPS..." -ForegroundColor $ColorInfo
# Kopiere Zertifikate ins Frontend-Verzeichnis
$frontendSslDir = "./frontend/ssl"
@ -416,7 +432,7 @@ create_self_signed_cert('$frontendCertFile', '$frontendKeyFile', '$frontendHostn
Write-Host "Zertifikate ins Frontend-Verzeichnis kopiert." -ForegroundColor $ColorSuccess
# Pruefen, ob .env.local existiert und aktualisieren
# Prüfen, ob .env.local existiert und aktualisieren
$envLocalPath = "./frontend/.env.local"
$envContent = ""
@ -446,7 +462,7 @@ create_self_signed_cert('$frontendCertFile', '$frontendKeyFile', '$frontendHostn
# Update existierende Konfiguration
$envContent = $envContent -replace $regex, $config
} else {
# Neue Konfiguration hinzufuegen
# Neue Konfiguration hinzufügen
$envContent += "`n$config"
}
}
@ -462,14 +478,14 @@ create_self_signed_cert('$frontendCertFile', '$frontendKeyFile', '$frontendHostn
Write-Host "Frontend: $frontendCertFile" -ForegroundColor $ColorCommand
Write-Host ""
Write-Host "Druecken Sie eine beliebige Taste, um fortzufahren..."
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
function Setup-Environment {
Show-Header "Umgebungs-Setup"
# Pruefen, ob Python und pip installiert sind
# Prüfen, ob Python und pip installiert sind
$pythonInstalled = Test-CommandExists "python"
$pipInstalled = Test-CommandExists "pip"
@ -477,25 +493,25 @@ function Setup-Environment {
Write-Host "Python oder pip ist nicht installiert. Bitte installieren Sie Python 3.6+ und versuchen Sie es erneut." -ForegroundColor $ColorError
Write-Host ""
Write-Host "Druecken Sie eine beliebige Taste, um fortzufahren..."
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
return
}
# Python-Abhaengigkeiten installieren
Write-Host "Installiere Backend-Abhaengigkeiten..." -ForegroundColor $ColorInfo
Exec-Command "pip install -r backend/requirements.txt" "Installiere Python-Abhaengigkeiten"
# Python-Abhängigkeiten installieren
Write-Host "Installiere Backend-Abhängigkeiten..." -ForegroundColor $ColorInfo
Exec-Command "pip install -r backend/requirements.txt" "Installiere Python-Abhängigkeiten"
# Pruefen, ob Node.js und npm installiert sind
# Prüfen, ob Node.js und npm installiert sind
$nodeInstalled = Test-CommandExists "node"
$npmInstalled = Test-CommandExists "npm"
if ($nodeInstalled -and $npmInstalled) {
# Frontend-Abhaengigkeiten installieren
Write-Host "Installiere Frontend-Abhaengigkeiten..." -ForegroundColor $ColorInfo
Exec-Command "cd frontend && npm install" "Installiere Node.js-Abhaengigkeiten"
# Frontend-Abhängigkeiten installieren
Write-Host "Installiere Frontend-Abhängigkeiten..." -ForegroundColor $ColorInfo
Exec-Command "cd frontend && npm install" "Installiere Node.js-Abhängigkeiten"
} else {
Write-Host "Node.js oder npm ist nicht installiert. Frontend-Abhaengigkeiten werden uebersprungen." -ForegroundColor $ColorWarning
Write-Host "Node.js oder npm ist nicht installiert. Frontend-Abhängigkeiten werden übersprungen." -ForegroundColor $ColorWarning
}
# Docker-Compose Datei aktualisieren
@ -513,110 +529,205 @@ function Setup-Environment {
}
}
# Datenbank initialisieren
Write-Host "Initialisiere Datenbank..." -ForegroundColor $ColorInfo
if (Test-Path "backend/app/models.py") {
Exec-Command "cd backend && python -c 'from app.models import init_db, create_initial_admin; init_db(); create_initial_admin()'" "Initialisiere Datenbank und Admin-Benutzer"
}
Write-Host ""
Write-Host "Umgebungs-Setup abgeschlossen!" -ForegroundColor $ColorSuccess
Write-Host ""
Write-Host "Druecken Sie eine beliebige Taste, um fortzufahren..."
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
function Start-Application {
Show-Header "Anwendung starten"
Write-Host "Wie moechten Sie die Anwendung starten?" -ForegroundColor $ColorInfo
Write-Host "Wie möchten Sie die Anwendung starten?" -ForegroundColor $ColorInfo
Write-Host "1. Backend-Server starten (Python)" -ForegroundColor $ColorCommand
Write-Host "2. Frontend-Server starten (Node.js)" -ForegroundColor $ColorCommand
Write-Host "3. Beide Server starten (in separaten Fenstern)" -ForegroundColor $ColorCommand
Write-Host "4. Mit Docker Compose starten" -ForegroundColor $ColorCommand
Write-Host "5. Zurueck zum Hauptmenue" -ForegroundColor $ColorCommand
Write-Host "5. Vollständige Installation und Start" -ForegroundColor $ColorCommand
Write-Host "6. Zurück zum Hauptmenü" -ForegroundColor $ColorCommand
$choice = Read-Host "Waehlen Sie eine Option (1-5)"
$choice = Read-Host "Wählen Sie eine Option (1-6)"
if ($choice -eq "1") {
Write-Host "Starte Backend-Server..." -ForegroundColor $ColorInfo
Start-Process -FilePath "python" -ArgumentList "backend/app/app.py" -NoNewWindow
Write-Host "Backend-Server laeuft jetzt im Hintergrund." -ForegroundColor $ColorSuccess
}
elseif ($choice -eq "2") {
Write-Host "Starte Frontend-Server..." -ForegroundColor $ColorInfo
Start-Process -FilePath "npm" -ArgumentList "run dev" -WorkingDirectory "frontend" -NoNewWindow
Write-Host "Frontend-Server laeuft jetzt im Hintergrund." -ForegroundColor $ColorSuccess
}
elseif ($choice -eq "3") {
Write-Host "Starte Backend-Server..." -ForegroundColor $ColorInfo
Start-Process -FilePath "python" -ArgumentList "backend/app/app.py" -NoNewWindow
Write-Host "Starte Frontend-Server..." -ForegroundColor $ColorInfo
Start-Process -FilePath "npm" -ArgumentList "run dev" -WorkingDirectory "frontend" -NoNewWindow
Write-Host "Beide Server laufen jetzt im Hintergrund." -ForegroundColor $ColorSuccess
}
elseif ($choice -eq "4") {
$dockerInstalled = Test-CommandExists "docker"
$dockerComposeInstalled = Test-CommandExists "docker-compose"
if ($dockerInstalled -and $dockerComposeInstalled) {
Write-Host "Starte Anwendung mit Docker Compose..." -ForegroundColor $ColorInfo
Exec-Command "docker-compose up -d" "Starte Docker Container"
Write-Host "Docker Container wurden gestartet." -ForegroundColor $ColorSuccess
} else {
Write-Host "Docker oder Docker Compose ist nicht installiert." -ForegroundColor $ColorError
switch ($choice) {
"1" {
Write-Host "Starte Backend-Server..." -ForegroundColor $ColorInfo
Start-Process -FilePath "python" -ArgumentList "backend/app/app.py" -NoNewWindow
Write-Host "Backend-Server läuft jetzt im Hintergrund." -ForegroundColor $ColorSuccess
}
"2" {
Write-Host "Starte Frontend-Server..." -ForegroundColor $ColorInfo
Start-Process -FilePath "npm" -ArgumentList "run dev" -WorkingDirectory "frontend" -NoNewWindow
Write-Host "Frontend-Server läuft jetzt im Hintergrund." -ForegroundColor $ColorSuccess
}
"3" {
Write-Host "Starte Backend-Server..." -ForegroundColor $ColorInfo
Start-Process -FilePath "python" -ArgumentList "backend/app/app.py" -NoNewWindow
Write-Host "Starte Frontend-Server..." -ForegroundColor $ColorInfo
Start-Process -FilePath "npm" -ArgumentList "run dev" -WorkingDirectory "frontend" -NoNewWindow
Write-Host "Beide Server laufen jetzt im Hintergrund." -ForegroundColor $ColorSuccess
}
"4" {
$dockerInstalled = Test-CommandExists "docker"
$dockerComposeInstalled = Test-CommandExists "docker-compose"
if ($dockerInstalled -and $dockerComposeInstalled) {
Write-Host "Starte Anwendung mit Docker Compose..." -ForegroundColor $ColorInfo
Exec-Command "docker-compose up -d" "Starte Docker Container"
Write-Host "Docker Container wurden gestartet." -ForegroundColor $ColorSuccess
} else {
Write-Host "Docker oder Docker Compose ist nicht installiert." -ForegroundColor $ColorError
}
}
"5" {
Write-Host "Führe vollständige Installation durch..." -ForegroundColor $ColorInfo
Setup-Environment
Create-SSLCertificates
Write-Host "Starte Anwendung..." -ForegroundColor $ColorInfo
Start-Process -FilePath "python" -ArgumentList "backend/app/app.py" -NoNewWindow
Start-Process -FilePath "npm" -ArgumentList "run dev" -WorkingDirectory "frontend" -NoNewWindow
Write-Host "Vollständige Installation und Start abgeschlossen!" -ForegroundColor $ColorSuccess
}
"6" {
return
}
default {
Write-Host "Ungültige Option." -ForegroundColor $ColorError
}
}
elseif ($choice -eq "5") {
return
}
else {
Write-Host "Ungueltige Option." -ForegroundColor $ColorError
}
Write-Host ""
Write-Host "Druecken Sie eine beliebige Taste, um fortzufahren..."
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
# Hauptmenue anzeigen
function Show-MainMenu {
Show-Header "Hauptmenue"
function Show-ProjectInfo {
Show-Header "Projekt-Informationen"
Write-Host "1. Systemvoraussetzungen pruefen" -ForegroundColor $ColorCommand
Write-Host "MYP (Mercedes-Benz Yard Printing) Platform" -ForegroundColor $ColorTitle
Write-Host "Version 3.0" -ForegroundColor $ColorInfo
Write-Host ""
Write-Host "Beschreibung:" -ForegroundColor $ColorInfo
Write-Host "Eine vollständige 3D-Drucker-Management-Plattform für Mercedes-Benz Werk 040 Berlin." -ForegroundColor $ColorCommand
Write-Host ""
Write-Host "Komponenten:" -ForegroundColor $ColorInfo
Write-Host "- Backend: Flask-basierte REST API" -ForegroundColor $ColorCommand
Write-Host "- Frontend: Next.js React-Anwendung" -ForegroundColor $ColorCommand
Write-Host "- Datenbank: SQLite" -ForegroundColor $ColorCommand
Write-Host "- Authentifizierung: GitHub OAuth + lokale Benutzer" -ForegroundColor $ColorCommand
Write-Host "- SSL/TLS: Selbstsignierte Zertifikate" -ForegroundColor $ColorCommand
Write-Host ""
Write-Host "Standard-Zugangsdaten:" -ForegroundColor $ColorInfo
Write-Host "- Admin E-Mail: admin@mercedes-benz.com" -ForegroundColor $ColorCommand
Write-Host "- Admin Passwort: 744563017196A" -ForegroundColor $ColorCommand
Write-Host ""
Write-Host "URLs:" -ForegroundColor $ColorInfo
Write-Host "- Backend: https://localhost:443 oder https://raspberrypi:443" -ForegroundColor $ColorCommand
Write-Host "- Frontend: https://localhost:3000" -ForegroundColor $ColorCommand
Write-Host ""
Write-Host "Weitere Informationen finden Sie in der CREDENTIALS.md Datei." -ForegroundColor $ColorWarning
Write-Host ""
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
function Clean-OldFiles {
Show-Header "Alte Dateien bereinigen"
Write-Host "Möchten Sie alte Skriptdateien und temporäre Dateien löschen? (j/n)" -ForegroundColor $ColorWarning
$cleanFiles = Read-Host
if ($cleanFiles -eq "j") {
$filesToDelete = @(
"setup_hosts.ps1",
"setup_hosts_copy.ps1",
"generate_ssl_certs.ps1",
"generate_ssl_certs_copy.ps1",
"setup_ssl.ps1",
"temp_cert_script.py"
)
foreach ($file in $filesToDelete) {
if (Test-Path $file) {
Remove-Item -Path $file -Force
Write-Host "✓ Gelöscht: $file" -ForegroundColor $ColorSuccess
}
}
Write-Host "Bereinigung abgeschlossen!" -ForegroundColor $ColorSuccess
} else {
Write-Host "Bereinigung übersprungen." -ForegroundColor $ColorInfo
}
Write-Host ""
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
# Hauptmenü anzeigen
function Show-MainMenu {
Show-Header "Hauptmenü"
Write-Host "1. Systemvoraussetzungen prüfen" -ForegroundColor $ColorCommand
Write-Host "2. Host-Konfiguration einrichten" -ForegroundColor $ColorCommand
Write-Host "3. SSL-Zertifikate erstellen" -ForegroundColor $ColorCommand
Write-Host "4. Umgebung einrichten (Abhaengigkeiten installieren)" -ForegroundColor $ColorCommand
Write-Host "4. Umgebung einrichten (Abhängigkeiten installieren)" -ForegroundColor $ColorCommand
Write-Host "5. Anwendung starten" -ForegroundColor $ColorCommand
Write-Host "6. Beenden" -ForegroundColor $ColorCommand
Write-Host "6. Projekt-Informationen anzeigen" -ForegroundColor $ColorCommand
Write-Host "7. Alte Dateien bereinigen" -ForegroundColor $ColorCommand
Write-Host "8. Beenden" -ForegroundColor $ColorCommand
Write-Host ""
$choice = Read-Host "Waehlen Sie eine Option (1-6)"
$choice = Read-Host "Wählen Sie eine Option (1-8)"
if ($choice -eq "1") {
Test-Dependencies
Show-MainMenu
}
elseif ($choice -eq "2") {
Setup-Hosts
Show-MainMenu
}
elseif ($choice -eq "3") {
Create-SSLCertificates
Show-MainMenu
}
elseif ($choice -eq "4") {
Setup-Environment
Show-MainMenu
}
elseif ($choice -eq "5") {
Start-Application
Show-MainMenu
}
elseif ($choice -eq "6") {
exit
}
else {
Write-Host "Ungueltige Option. Bitte versuchen Sie es erneut." -ForegroundColor $ColorError
Start-Sleep -Seconds 2
Show-MainMenu
switch ($choice) {
"1" {
Test-Dependencies
Show-MainMenu
}
"2" {
Setup-Hosts
Show-MainMenu
}
"3" {
Create-SSLCertificates
Show-MainMenu
}
"4" {
Setup-Environment
Show-MainMenu
}
"5" {
Start-Application
Show-MainMenu
}
"6" {
Show-ProjectInfo
Show-MainMenu
}
"7" {
Clean-OldFiles
Show-MainMenu
}
"8" {
Write-Host "Auf Wiedersehen!" -ForegroundColor $ColorSuccess
exit
}
default {
Write-Host "Ungültige Option. Bitte versuchen Sie es erneut." -ForegroundColor $ColorError
Start-Sleep -Seconds 2
Show-MainMenu
}
}
}