163 lines
6.2 KiB
Python
163 lines
6.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test-Setup für Batch Uploader
|
|
=============================
|
|
|
|
Erstellt Test-Struktur und führt Validierungs-Tests durch.
|
|
Neue Struktur: Photos/Jahr/Name/Projekt/dateiname.endung
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
import tempfile
|
|
import shutil
|
|
from PIL import Image
|
|
import logging
|
|
|
|
# Test-Setup
|
|
TEST_DIR = Path("test_images")
|
|
BACKEND_URL = "http://localhost:5000"
|
|
|
|
def create_test_image(path: Path, size=(800, 600), color=(255, 0, 0)):
|
|
"""Erstellt ein Test-Bild"""
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
img = Image.new('RGB', size, color)
|
|
img.save(path, 'JPEG', quality=85)
|
|
print(f"✅ Erstellt: {path}")
|
|
|
|
def setup_test_structure():
|
|
"""Erstellt Test-Verzeichnis-Struktur mit Beispielbildern
|
|
|
|
Neue Struktur: Photos/Jahr/Name/Projekt/dateiname.endung
|
|
"""
|
|
print("🏗️ Erstelle Test-Struktur (Photos/Jahr/Name/Projekt/)...")
|
|
|
|
# Test-Struktur nach neuem Schema
|
|
test_structure = {
|
|
"2024/Max_Mustermann/Urlaub_Mallorca": [
|
|
("sonnenuntergang.jpg", (1200, 800), (255, 165, 0)),
|
|
("strand_spaziergang.jpg", (800, 600), (135, 206, 235)),
|
|
("hotel_pool.jpg", (800, 600), (0, 191, 255))
|
|
],
|
|
"2024/Max_Mustermann/Hochzeit_Anna": [
|
|
("zeremonie.jpg", (1000, 750), (255, 182, 193)),
|
|
("torte.jpg", (600, 600), (139, 69, 19)),
|
|
("party.jpg", (800, 600), (255, 215, 0))
|
|
],
|
|
"2024/Anna_Schmidt/Architektur_Berlin": [
|
|
("brandenburger_tor.jpg", (1000, 750), (128, 128, 128)),
|
|
("reichstag.jpg", (800, 600), (70, 70, 70)),
|
|
("potsdamer_platz.jpg", (900, 600), (105, 105, 105))
|
|
],
|
|
"2023/Familie_Mueller/Weihnachten": [
|
|
("weihnachtsbaum.jpg", (800, 600), (34, 139, 34)),
|
|
("geschenke.jpg", (600, 600), (255, 0, 0)),
|
|
("familienfoto.jpg", (800, 600), (255, 192, 203))
|
|
],
|
|
"2023/Thomas_Weber/Business_Trip": [
|
|
("konferenz.jpg", (800, 600), (0, 0, 139)),
|
|
("networking.jpg", (700, 500), (25, 25, 112))
|
|
]
|
|
}
|
|
|
|
# README-Inhalte für Projekte
|
|
readme_contents = {
|
|
"2024/Max_Mustermann/Urlaub_Mallorca": "Traumhafter Urlaub auf Mallorca mit Sonne, Strand und entspannten Momenten am Pool.",
|
|
"2024/Max_Mustermann/Hochzeit_Anna": "Unvergessliche Hochzeitsfeier von Anna und Max mit wunderschöner Zeremonie und ausgelassener Party.",
|
|
"2024/Anna_Schmidt/Architektur_Berlin": "Architektonische Highlights Berlins - eine fotografische Reise durch die Hauptstadt.",
|
|
"2023/Familie_Mueller/Weihnachten": "Besinnliche Weihnachtszeit mit der ganzen Familie, Geschenken und traditionellem Fest.",
|
|
"2023/Thomas_Weber/Business_Trip": "Geschäftsreise mit wichtigen Meetings, Konferenzen und wertvollen Networking-Gelegenheiten."
|
|
}
|
|
|
|
# Erstelle Struktur mit README-Dateien
|
|
for dir_path, images in test_structure.items():
|
|
# Verzeichnis erstellen
|
|
full_dir_path = TEST_DIR / dir_path
|
|
full_dir_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
# README.md erstellen wenn Inhalt vorhanden
|
|
if dir_path in readme_contents:
|
|
readme_path = full_dir_path / "README.md"
|
|
with open(readme_path, 'w', encoding='utf-8') as f:
|
|
f.write(f"# {dir_path.split('/')[-1].replace('_', ' ')}\n\n")
|
|
f.write(readme_contents[dir_path] + "\n\n")
|
|
f.write("## Details\n")
|
|
f.write(f"- Jahr: {dir_path.split('/')[0]}\n")
|
|
f.write(f"- Fotograf: {dir_path.split('/')[1].replace('_', ' ')}\n")
|
|
f.write(f"- Projekt: {dir_path.split('/')[2].replace('_', ' ')}\n")
|
|
print(f"📄 README erstellt: {readme_path}")
|
|
|
|
# Bilder erstellen
|
|
for image_name, size, color in images:
|
|
image_path = full_dir_path / image_name
|
|
create_test_image(image_path, size, color)
|
|
|
|
print(f"📁 Test-Struktur erstellt in: {TEST_DIR.absolute()}")
|
|
return TEST_DIR
|
|
|
|
def show_test_structure():
|
|
"""Zeigt die erstellte Test-Struktur"""
|
|
print("\n📁 Test-Struktur (Photos/Jahr/Name/Projekt/):")
|
|
print("test_images/")
|
|
|
|
for root, dirs, files in os.walk(TEST_DIR):
|
|
level = root.replace(str(TEST_DIR), '').count(os.sep)
|
|
indent = ' ' * 2 * level
|
|
subindent = ' ' * 2 * (level + 1)
|
|
|
|
if level > 0:
|
|
print(f"{indent}├── {os.path.basename(root)}/")
|
|
|
|
for file in sorted(files):
|
|
icon = "📄" if file == "README.md" else "📸"
|
|
if file.endswith(('.jpg', '.jpeg', '.png')) or file == "README.md":
|
|
print(f"{subindent}├── {icon} {file}")
|
|
|
|
def run_test_commands():
|
|
"""Zeigt Test-Kommandos"""
|
|
print(f"\n🧪 Test-Kommandos:")
|
|
print(f"cd {Path.cwd()}")
|
|
print()
|
|
|
|
commands = [
|
|
"# 1. Dry-Run Test (Neue Struktur)",
|
|
f"python3 batch_uploader.py {TEST_DIR} --dry-run --verbose",
|
|
"",
|
|
"# 2. Einzelnes Projekt testen",
|
|
f"python3 batch_uploader.py {TEST_DIR}/2024/Max_Mustermann/Urlaub_Mallorca --titel \"Mallorca Test\" --chunk-size 2",
|
|
"",
|
|
"# 3. Vollständiger Upload (Neue Struktur)",
|
|
f"python3 batch_uploader.py {TEST_DIR} --titel \"Test Sammlung\" --name \"Test User\" --verbose",
|
|
"",
|
|
"# 4. Backend Status prüfen",
|
|
"curl http://localhost:5000/api/groups",
|
|
"",
|
|
"# 5. Struktur-Test für spezifischen Namen",
|
|
f"python3 batch_uploader.py {TEST_DIR}/2024/Anna_Schmidt --dry-run --verbose"
|
|
]
|
|
|
|
for cmd in commands:
|
|
print(cmd)
|
|
|
|
def main():
|
|
"""Haupt-Test-Setup"""
|
|
if len(sys.argv) > 1 and sys.argv[1] == "--clean":
|
|
if TEST_DIR.exists():
|
|
shutil.rmtree(TEST_DIR)
|
|
print(f"🧹 {TEST_DIR} gelöscht")
|
|
return
|
|
|
|
# Setup
|
|
setup_test_structure()
|
|
show_test_structure()
|
|
run_test_commands()
|
|
|
|
print(f"\n✅ Test-Setup abgeschlossen!")
|
|
print(f"💡 Starte Backend mit: cd .. && ./prod.sh")
|
|
print(f"💡 Dann teste mit einem der obigen Kommandos")
|
|
print(f"💡 Cleanup mit: python3 test_setup.py --clean")
|
|
|
|
if __name__ == "__main__":
|
|
main() |