**Änderungen:** - ✅ app.py: Hinzugefügt, um CSRF-Fehler zu behandeln - ✅ models.py: Fehlerprotokollierung bei der Suche nach Gastanfragen per OTP - ✅ api.py: Fehlerprotokollierung beim Markieren von Benachrichtigungen als gelesen - ✅ calendar.py: Fallback-Daten zurückgeben, wenn keine Kalenderereignisse vorhanden sind - ✅ guest.py: Status-Check-Seite für Gäste aktualisiert - ✅ hardware_integration.py: Debugging-Informationen für erweiterte Geräteinformationen hinzugefügt - ✅ tapo_status_manager.py: Rückgabewert für Statusabfrage hinzugefügt **Ergebnis:** - Verbesserte Fehlerbehandlung und Protokollierung für eine robustere Anwendung - Bessere Nachverfolgbarkeit von Fehlern und Systemverhalten 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
178 lines
6.3 KiB
Python
178 lines
6.3 KiB
Python
#!/usr/bin/env python3.11
|
|
"""
|
|
Setup-Script für die 6 Standarddrucker in TBA Marienfelde.
|
|
Dieses Script erstellt die Standarddrucker falls sie noch nicht existieren.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
from datetime import datetime
|
|
|
|
# Pfad zum Backend-Verzeichnis hinzufügen
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from models import Printer, get_cached_session, init_database
|
|
from utils.logging_config import get_logger
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
def setup_standard_printers():
|
|
"""Erstellt die 6 Standarddrucker für TBA Marienfelde."""
|
|
|
|
# Standard-Drucker-Konfiguration
|
|
standard_printers = [
|
|
{
|
|
'name': '3D-Drucker-001',
|
|
'location': 'TBA Marienfelde',
|
|
'model': 'Standard',
|
|
'ip_address': '192.168.0.100',
|
|
'plug_ip': '192.168.0.100',
|
|
'active': True,
|
|
'status': 'idle'
|
|
},
|
|
{
|
|
'name': '3D-Drucker-002',
|
|
'location': 'TBA Marienfelde',
|
|
'model': 'Standard',
|
|
'ip_address': '192.168.0.101',
|
|
'plug_ip': '192.168.0.101',
|
|
'active': True,
|
|
'status': 'idle'
|
|
},
|
|
{
|
|
'name': '3D-Drucker-003',
|
|
'location': 'TBA Marienfelde',
|
|
'model': 'Standard',
|
|
'ip_address': '192.168.0.102',
|
|
'plug_ip': '192.168.0.102',
|
|
'active': True,
|
|
'status': 'idle'
|
|
},
|
|
{
|
|
'name': '3D-Drucker-004',
|
|
'location': 'TBA Marienfelde',
|
|
'model': 'Standard',
|
|
'ip_address': '192.168.0.103',
|
|
'plug_ip': '192.168.0.103',
|
|
'active': True,
|
|
'status': 'idle'
|
|
},
|
|
{
|
|
'name': '3D-Drucker-005',
|
|
'location': 'TBA Marienfelde',
|
|
'model': 'Standard',
|
|
'ip_address': '192.168.0.104',
|
|
'plug_ip': '192.168.0.104',
|
|
'active': True,
|
|
'status': 'idle'
|
|
},
|
|
{
|
|
'name': '3D-Drucker-006',
|
|
'location': 'TBA Marienfelde',
|
|
'model': 'Standard',
|
|
'ip_address': '192.168.0.106',
|
|
'plug_ip': '192.168.0.106',
|
|
'active': True,
|
|
'status': 'idle'
|
|
}
|
|
]
|
|
|
|
try:
|
|
# Datenbank initialisieren falls nötig
|
|
init_database()
|
|
|
|
with get_cached_session() as db_session:
|
|
# Prüfen ob Drucker bereits existieren
|
|
existing_printers = db_session.query(Printer).filter(
|
|
Printer.location == "TBA Marienfelde"
|
|
).all()
|
|
|
|
existing_names = [p.name for p in existing_printers]
|
|
|
|
created_count = 0
|
|
updated_count = 0
|
|
|
|
for printer_config in standard_printers:
|
|
printer_name = printer_config['name']
|
|
|
|
# Prüfen ob Drucker bereits existiert
|
|
existing_printer = db_session.query(Printer).filter_by(name=printer_name).first()
|
|
|
|
if existing_printer:
|
|
# Drucker existiert bereits - aktualisieren falls nötig
|
|
logger.info(f"Drucker '{printer_name}' existiert bereits - prüfe Updates...")
|
|
|
|
# Wichtige Felder aktualisieren
|
|
existing_printer.location = printer_config['location']
|
|
existing_printer.active = printer_config['active']
|
|
existing_printer.model = printer_config.get('model')
|
|
existing_printer.updated_at = datetime.now()
|
|
|
|
updated_count += 1
|
|
logger.info(f"Drucker '{printer_name}' aktualisiert")
|
|
|
|
else:
|
|
# Neuen Drucker erstellen
|
|
new_printer = Printer(
|
|
name=printer_config['name'],
|
|
location=printer_config['location'],
|
|
model=printer_config.get('model'),
|
|
ip_address=printer_config.get('ip_address'),
|
|
plug_ip=printer_config.get('plug_ip'),
|
|
active=printer_config['active'],
|
|
status=printer_config['status'],
|
|
created_at=datetime.now(),
|
|
updated_at=datetime.now()
|
|
)
|
|
|
|
db_session.add(new_printer)
|
|
created_count += 1
|
|
logger.info(f"Neuer Drucker '{printer_name}' erstellt")
|
|
|
|
# Änderungen werden automatisch durch get_cached_session() committed
|
|
|
|
# Zusammenfassung
|
|
total_printers = db_session.query(Printer).filter(
|
|
Printer.location == "TBA Marienfelde"
|
|
).count()
|
|
|
|
logger.info(f"✅ Setup abgeschlossen:")
|
|
logger.info(f" - {created_count} neue Drucker erstellt")
|
|
logger.info(f" - {updated_count} Drucker aktualisiert")
|
|
logger.info(f" - {total_printers} Drucker insgesamt in TBA Marienfelde")
|
|
|
|
print(f"✅ Setup erfolgreich abgeschlossen!")
|
|
print(f" 📊 {created_count} neue Drucker erstellt")
|
|
print(f" 🔄 {updated_count} Drucker aktualisiert")
|
|
print(f" 🏭 {total_printers} Drucker insgesamt in TBA Marienfelde")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
logger.error(f"❌ Fehler beim Setup der Standarddrucker: {str(e)}")
|
|
print(f"❌ Fehler beim Setup: {str(e)}")
|
|
return False
|
|
|
|
def main():
|
|
"""Hauptfunktion für das Setup-Script."""
|
|
print("🚀 MYP Standarddrucker-Setup wird gestartet...")
|
|
print("📍 Standort: TBA Marienfelde")
|
|
print("🖨️ Anzahl Drucker: 6")
|
|
print()
|
|
|
|
success = setup_standard_printers()
|
|
|
|
if success:
|
|
print()
|
|
print("🎉 Setup erfolgreich abgeschlossen!")
|
|
print("💡 Die Kalender-Seite zeigt jetzt nur die 6 Standarddrucker an.")
|
|
return 0
|
|
else:
|
|
print()
|
|
print("💥 Setup fehlgeschlagen!")
|
|
print("🔍 Prüfen Sie die Logs für weitere Details.")
|
|
return 1
|
|
|
|
if __name__ == "__main__":
|
|
exit_code = main()
|
|
sys.exit(exit_code) |