226 lines
8.7 KiB
Python
226 lines
8.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Finale Template-Validierung für MYP Admin Panel
|
|
Abschließende Verifikation aller Template-Endpoints nach Problembehebeung
|
|
|
|
Autor: MYP Team - Till Tomczak
|
|
Datum: 2025-06-19
|
|
"""
|
|
|
|
import re
|
|
import json
|
|
from typing import Dict, List, Set, Tuple
|
|
|
|
class FinalTemplateValidator:
|
|
"""
|
|
Finale Template-Validierung mit vollständiger Endpoint-Verifikation
|
|
"""
|
|
|
|
def __init__(self):
|
|
self.template_path = "/mnt/c/Users/TTOMCZA.EMEA/Dev/Projektarbeit-MYP/backend/templates/admin.html"
|
|
self.blueprint_path = "/mnt/c/Users/TTOMCZA.EMEA/Dev/Projektarbeit-MYP/backend/blueprints/admin_unified.py"
|
|
self.app_path = "/mnt/c/Users/TTOMCZA.EMEA/Dev/Projektarbeit-MYP/backend/app.py"
|
|
|
|
self.all_available_endpoints = set()
|
|
self.template_references = []
|
|
self.validation_results = []
|
|
|
|
def collect_all_endpoints(self):
|
|
"""
|
|
Sammle alle verfügbaren Endpoints aus allen Quellen
|
|
"""
|
|
print("🔍 Vollständige Endpoint-Sammlung")
|
|
|
|
# 1. Admin Blueprint Endpoints
|
|
with open(self.blueprint_path, 'r', encoding='utf-8') as f:
|
|
blueprint_content = f.read()
|
|
|
|
admin_routes = re.findall(
|
|
r'@admin_blueprint\.route\(["\']([^"\']+)["\'][^)]*\)\s*@admin_required\s*def\s+([a-zA-Z_][a-zA-Z0-9_]*)',
|
|
blueprint_content,
|
|
re.MULTILINE | re.DOTALL
|
|
)
|
|
for route_path, function_name in admin_routes:
|
|
self.all_available_endpoints.add(f"admin.{function_name}")
|
|
|
|
# 2. Admin API Blueprint Endpoints
|
|
api_routes = re.findall(
|
|
r'@admin_api_blueprint\.route\(["\']([^"\']+)["\'][^)]*\)\s*@admin_required\s*def\s+([a-zA-Z_][a-zA-Z0-9_]*)',
|
|
blueprint_content,
|
|
re.MULTILINE | re.DOTALL
|
|
)
|
|
for route_path, function_name in api_routes:
|
|
self.all_available_endpoints.add(f"admin_api.{function_name}")
|
|
|
|
# 3. Haupt-App Endpoints
|
|
with open(self.app_path, 'r', encoding='utf-8') as f:
|
|
app_content = f.read()
|
|
|
|
app_routes = re.findall(
|
|
r'@app\.route\(["\']([^"\']+)["\'][^)]*\)\s*(?:@[a-zA-Z_][a-zA-Z0-9_]*\s*)*def\s+([a-zA-Z_][a-zA-Z0-9_]*)',
|
|
app_content,
|
|
re.MULTILINE | re.DOTALL
|
|
)
|
|
for route_path, function_name in app_routes:
|
|
self.all_available_endpoints.add(function_name)
|
|
|
|
print(f" ✓ {len(self.all_available_endpoints)} Endpoints verfügbar")
|
|
|
|
def extract_template_references(self):
|
|
"""
|
|
Extrahiere alle url_for Referenzen aus dem Template
|
|
"""
|
|
print("\n🔍 Template-Referenz-Extraktion")
|
|
|
|
with open(self.template_path, 'r', encoding='utf-8') as f:
|
|
template_content = f.read()
|
|
|
|
# Finde alle url_for Aufrufe mit Zeilennummern
|
|
lines = template_content.split('\n')
|
|
for line_num, line in enumerate(lines, 1):
|
|
url_for_matches = re.findall(r"url_for\(['\"]([^'\"]+)['\"][^)]*\)", line)
|
|
for match in url_for_matches:
|
|
self.template_references.append({
|
|
'line': line_num,
|
|
'endpoint': match,
|
|
'context': line.strip()
|
|
})
|
|
|
|
print(f" ✓ {len(self.template_references)} Template-Referenzen gefunden")
|
|
|
|
def validate_all_references(self):
|
|
"""
|
|
Validiere alle Template-Referenzen gegen verfügbare Endpoints
|
|
"""
|
|
print("\n🔍 Referenz-Validierung")
|
|
|
|
valid_count = 0
|
|
invalid_count = 0
|
|
|
|
for ref in self.template_references:
|
|
endpoint = ref['endpoint']
|
|
is_valid = endpoint in self.all_available_endpoints
|
|
|
|
result = {
|
|
'line': ref['line'],
|
|
'endpoint': endpoint,
|
|
'is_valid': is_valid,
|
|
'context': ref['context']
|
|
}
|
|
|
|
if not is_valid:
|
|
# Versuche ähnliche Endpoints zu finden
|
|
suggestions = self._find_similar_endpoints(endpoint)
|
|
if suggestions:
|
|
result['suggestions'] = suggestions
|
|
invalid_count += 1
|
|
else:
|
|
valid_count += 1
|
|
|
|
self.validation_results.append(result)
|
|
|
|
print(f" ✅ Gültige Referenzen: {valid_count}")
|
|
print(f" ❌ Ungültige Referenzen: {invalid_count}")
|
|
|
|
return invalid_count == 0
|
|
|
|
def _find_similar_endpoints(self, target: str) -> List[str]:
|
|
"""
|
|
Finde ähnliche Endpoints für Vorschläge
|
|
"""
|
|
suggestions = []
|
|
target_parts = target.split('.')
|
|
target_func = target_parts[-1] if '.' in target else target
|
|
|
|
for available in self.all_available_endpoints:
|
|
available_parts = available.split('.')
|
|
available_func = available_parts[-1] if '.' in available else available
|
|
|
|
# Exakte Funktionsnamen-Übereinstimmung
|
|
if target_func == available_func:
|
|
suggestions.append(available)
|
|
# Ähnliche Namen
|
|
elif target_func in available_func or available_func in target_func:
|
|
suggestions.append(available)
|
|
|
|
return suggestions[:3]
|
|
|
|
def generate_final_report(self):
|
|
"""
|
|
Generiere finalen Validierungsbericht
|
|
"""
|
|
valid_refs = [r for r in self.validation_results if r['is_valid']]
|
|
invalid_refs = [r for r in self.validation_results if not r['is_valid']]
|
|
|
|
return {
|
|
'validation_summary': {
|
|
'total_endpoints_available': len(self.all_available_endpoints),
|
|
'total_template_references': len(self.template_references),
|
|
'valid_references': len(valid_refs),
|
|
'invalid_references': len(invalid_refs),
|
|
'validation_success': len(invalid_refs) == 0
|
|
},
|
|
'available_endpoints': sorted(list(self.all_available_endpoints)),
|
|
'template_references': self.template_references,
|
|
'validation_results': self.validation_results,
|
|
'invalid_references': invalid_refs,
|
|
'validation_status': 'PASSED' if len(invalid_refs) == 0 else 'FAILED'
|
|
}
|
|
|
|
def main():
|
|
"""
|
|
Finale Template-Validierung
|
|
"""
|
|
print("🎯 MYP Template-Validierung - Finale Überprüfung")
|
|
print("=" * 70)
|
|
|
|
validator = FinalTemplateValidator()
|
|
|
|
# Vollständige Validierung
|
|
validator.collect_all_endpoints()
|
|
validator.extract_template_references()
|
|
is_valid = validator.validate_all_references()
|
|
|
|
# Generiere finalen Bericht
|
|
report = validator.generate_final_report()
|
|
|
|
print("\n📊 FINALE VALIDIERUNGSERGEBNISSE")
|
|
print("=" * 70)
|
|
print(f"Status: {report['validation_status']}")
|
|
print(f"Verfügbare Endpoints: {report['validation_summary']['total_endpoints_available']}")
|
|
print(f"Template-Referenzen: {report['validation_summary']['total_template_references']}")
|
|
print(f"Gültige Referenzen: {report['validation_summary']['valid_references']}")
|
|
print(f"Ungültige Referenzen: {report['validation_summary']['invalid_references']}")
|
|
|
|
if report['invalid_references']:
|
|
print("\n❌ UNGÜLTIGE REFERENZEN:")
|
|
for ref in report['invalid_references']:
|
|
print(f" • Zeile {ref['line']}: {ref['endpoint']}")
|
|
print(f" Kontext: {ref['context']}")
|
|
if 'suggestions' in ref:
|
|
print(f" Vorschläge: {', '.join(ref['suggestions'])}")
|
|
print()
|
|
else:
|
|
print("\n✅ ALLE TEMPLATE-REFERENZEN SIND GÜLTIG!")
|
|
print(" Das Admin-Template ist vollständig korrekt konfiguriert.")
|
|
|
|
print("\n📋 TEMPLATE-REFERENZEN DETAILS:")
|
|
for ref in report['template_references']:
|
|
status = "✅" if ref['endpoint'] in report['available_endpoints'] else "❌"
|
|
print(f" {status} Zeile {ref['line']:3d}: {ref['endpoint']}")
|
|
|
|
# Speichere finalen Bericht
|
|
with open('/mnt/c/Users/TTOMCZA.EMEA/Dev/Projektarbeit-MYP/backend/template_validation_final_report.json', 'w', encoding='utf-8') as f:
|
|
json.dump(report, f, indent=2, ensure_ascii=False)
|
|
|
|
print(f"\n💾 Finaler Validierungsbericht gespeichert: template_validation_final_report.json")
|
|
|
|
if report['validation_status'] == 'PASSED':
|
|
print("\n🎉 TEMPLATE-VALIDIERUNG ERFOLGREICH ABGESCHLOSSEN!")
|
|
return True
|
|
else:
|
|
print("\n⚠️ TEMPLATE-VALIDIERUNG FEHLGESCHLAGEN - Korrekturen erforderlich")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
main() |