178 lines
5.5 KiB
Python
178 lines
5.5 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
Skript zum Hinzufügen von Testdruckern zur Datenbank
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
from datetime import datetime
|
|
|
|
# Füge das Anwendungsverzeichnis zum Python-Pfad hinzu
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from models import get_db_session, Printer
|
|
|
|
def add_test_printers():
|
|
"""Fügt Testdrucker zur Datenbank hinzu"""
|
|
|
|
test_printers = [
|
|
{
|
|
"name": "Prusa i3 MK3S+",
|
|
"model": "Prusa i3 MK3S+",
|
|
"location": "Labor A - Arbeitsplatz 1",
|
|
"mac_address": "AA:BB:CC:DD:EE:01",
|
|
"plug_ip": "192.168.1.101",
|
|
"status": "available",
|
|
"active": True
|
|
},
|
|
{
|
|
"name": "Ender 3 V2",
|
|
"model": "Creality Ender 3 V2",
|
|
"location": "Labor A - Arbeitsplatz 2",
|
|
"mac_address": "AA:BB:CC:DD:EE:02",
|
|
"plug_ip": "192.168.1.102",
|
|
"status": "available",
|
|
"active": True
|
|
},
|
|
{
|
|
"name": "Ultimaker S3",
|
|
"model": "Ultimaker S3",
|
|
"location": "Labor B - Arbeitsplatz 1",
|
|
"mac_address": "AA:BB:CC:DD:EE:03",
|
|
"plug_ip": "192.168.1.103",
|
|
"status": "available",
|
|
"active": True
|
|
},
|
|
{
|
|
"name": "Bambu Lab X1 Carbon",
|
|
"model": "Bambu Lab X1 Carbon",
|
|
"location": "Labor B - Arbeitsplatz 2",
|
|
"mac_address": "AA:BB:CC:DD:EE:04",
|
|
"plug_ip": "192.168.1.104",
|
|
"status": "available",
|
|
"active": True
|
|
},
|
|
{
|
|
"name": "Formlabs Form 3",
|
|
"model": "Formlabs Form 3",
|
|
"location": "Labor C - Harz-Bereich",
|
|
"mac_address": "AA:BB:CC:DD:EE:05",
|
|
"plug_ip": "192.168.1.105",
|
|
"status": "offline",
|
|
"active": False
|
|
}
|
|
]
|
|
|
|
db_session = get_db_session()
|
|
|
|
try:
|
|
added_count = 0
|
|
|
|
for printer_data in test_printers:
|
|
# Prüfen, ob Drucker bereits existiert
|
|
existing = db_session.query(Printer).filter(
|
|
Printer.name == printer_data["name"]
|
|
).first()
|
|
|
|
if existing:
|
|
print(f"⚠️ Drucker '{printer_data['name']}' existiert bereits - überspringe")
|
|
continue
|
|
|
|
# Neuen Drucker erstellen
|
|
new_printer = Printer(
|
|
name=printer_data["name"],
|
|
model=printer_data["model"],
|
|
location=printer_data["location"],
|
|
mac_address=printer_data["mac_address"],
|
|
plug_ip=printer_data["plug_ip"],
|
|
status=printer_data["status"],
|
|
active=printer_data["active"],
|
|
created_at=datetime.now()
|
|
)
|
|
|
|
db_session.add(new_printer)
|
|
added_count += 1
|
|
print(f"✅ Drucker '{printer_data['name']}' hinzugefügt")
|
|
|
|
if added_count > 0:
|
|
db_session.commit()
|
|
print(f"\n🎉 {added_count} Testdrucker erfolgreich zur Datenbank hinzugefügt!")
|
|
else:
|
|
print("\n📋 Alle Testdrucker existieren bereits in der Datenbank")
|
|
|
|
# Zeige alle Drucker in der Datenbank
|
|
all_printers = db_session.query(Printer).all()
|
|
print(f"\n📊 Gesamt {len(all_printers)} Drucker in der Datenbank:")
|
|
print("-" * 80)
|
|
print(f"{'ID':<4} {'Name':<20} {'Modell':<20} {'Status':<12} {'Aktiv':<6}")
|
|
print("-" * 80)
|
|
|
|
for printer in all_printers:
|
|
active_str = "✅" if printer.active else "❌"
|
|
print(f"{printer.id:<4} {printer.name[:19]:<20} {(printer.model or 'Unbekannt')[:19]:<20} {printer.status:<12} {active_str:<6}")
|
|
|
|
db_session.close()
|
|
|
|
except Exception as e:
|
|
db_session.rollback()
|
|
db_session.close()
|
|
print(f"❌ Fehler beim Hinzufügen der Testdrucker: {str(e)}")
|
|
return False
|
|
|
|
return True
|
|
|
|
def remove_test_printers():
|
|
"""Entfernt alle Testdrucker aus der Datenbank"""
|
|
|
|
test_printer_names = [
|
|
"Prusa i3 MK3S+",
|
|
"Ender 3 V2",
|
|
"Ultimaker S3",
|
|
"Bambu Lab X1 Carbon",
|
|
"Formlabs Form 3"
|
|
]
|
|
|
|
db_session = get_db_session()
|
|
|
|
try:
|
|
removed_count = 0
|
|
|
|
for name in test_printer_names:
|
|
printer = db_session.query(Printer).filter(Printer.name == name).first()
|
|
if printer:
|
|
db_session.delete(printer)
|
|
removed_count += 1
|
|
print(f"🗑️ Drucker '{name}' entfernt")
|
|
|
|
if removed_count > 0:
|
|
db_session.commit()
|
|
print(f"\n🧹 {removed_count} Testdrucker erfolgreich entfernt!")
|
|
else:
|
|
print("\n📋 Keine Testdrucker zum Entfernen gefunden")
|
|
|
|
db_session.close()
|
|
|
|
except Exception as e:
|
|
db_session.rollback()
|
|
db_session.close()
|
|
print(f"❌ Fehler beim Entfernen der Testdrucker: {str(e)}")
|
|
return False
|
|
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
print("=== MYP Druckerverwaltung - Testdrucker-Verwaltung ===")
|
|
print()
|
|
|
|
if len(sys.argv) > 1 and sys.argv[1] == "--remove":
|
|
print("Entferne Testdrucker...")
|
|
remove_test_printers()
|
|
else:
|
|
print("Füge Testdrucker hinzu...")
|
|
print("(Verwende --remove um Testdrucker zu entfernen)")
|
|
print()
|
|
add_test_printers()
|
|
|
|
print("\nFertig! 🚀") |