v1.0 - Version stable: multi-PC, détection UI-DETR-1, 3 modes exécution
- Frontend v4 accessible sur réseau local (192.168.1.40) - Ports ouverts: 3002 (frontend), 5001 (backend), 5004 (dashboard) - Ollama GPU fonctionnel - Self-healing interactif - Dashboard confiance Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
142
fix_screenshot_upload_v3.py
Normal file
142
fix_screenshot_upload_v3.py
Normal file
@@ -0,0 +1,142 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script de correction pour l'upload des screenshots manquants - Version 3.
|
||||
|
||||
Correction de la structure ZIP pour correspondre à ce que le serveur attend.
|
||||
"""
|
||||
|
||||
import os
|
||||
import json
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
# Ajouter le répertoire agent_v0 au path
|
||||
sys.path.insert(0, 'agent_v0')
|
||||
|
||||
from uploader import upload_session_zip
|
||||
|
||||
def fix_session_upload(session_dir: Path) -> bool:
|
||||
"""
|
||||
Corrige l'upload d'une session en incluant les screenshots.
|
||||
|
||||
Le serveur attend cette structure dans le ZIP :
|
||||
session_id/
|
||||
├── session_id.json
|
||||
└── shots/
|
||||
├── shot_0001.png
|
||||
└── ...
|
||||
|
||||
Args:
|
||||
session_dir: Répertoire de la session
|
||||
|
||||
Returns:
|
||||
True si correction réussie
|
||||
"""
|
||||
session_id = session_dir.name
|
||||
json_file = session_dir / f"{session_id}.json"
|
||||
shots_dir = session_dir / "shots"
|
||||
|
||||
if not json_file.exists():
|
||||
print(f"❌ JSON manquant pour {session_id}")
|
||||
return False
|
||||
|
||||
if not shots_dir.exists() or not list(shots_dir.glob("*.png")):
|
||||
print(f"⚠️ Pas de screenshots pour {session_id}")
|
||||
return False
|
||||
|
||||
# Créer un nouveau ZIP avec la structure attendue par le serveur
|
||||
zip_path = session_dir.parent / f"{session_id}_fixed.zip"
|
||||
|
||||
try:
|
||||
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf:
|
||||
# Ajouter le JSON dans le sous-répertoire session_id/
|
||||
zf.write(json_file, f"{session_id}/{json_file.name}")
|
||||
|
||||
# Ajouter tous les screenshots dans session_id/shots/
|
||||
for screenshot in shots_dir.glob("*.png"):
|
||||
zf.write(screenshot, f"{session_id}/shots/{screenshot.name}")
|
||||
|
||||
print(f"📦 Archive créée : {zip_path}")
|
||||
|
||||
# Debug : inspecter la structure
|
||||
print(f"🔍 Structure de {zip_path.name}:")
|
||||
with zipfile.ZipFile(zip_path, 'r') as zf:
|
||||
for name in sorted(zf.namelist())[:10]: # Afficher les 10 premiers
|
||||
print(f" 📄 {name}")
|
||||
if len(zf.namelist()) > 10:
|
||||
print(f" ... et {len(zf.namelist()) - 10} autres fichiers")
|
||||
|
||||
# Uploader la nouvelle archive
|
||||
if upload_session_zip(str(zip_path), session_id):
|
||||
print(f"✅ Upload réussi pour {session_id}")
|
||||
# Nettoyer l'archive temporaire
|
||||
zip_path.unlink()
|
||||
return True
|
||||
else:
|
||||
print(f"❌ Upload échoué pour {session_id}")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Erreur création ZIP pour {session_id}: {e}")
|
||||
return False
|
||||
|
||||
def test_single_session():
|
||||
"""Test avec une seule session pour debug."""
|
||||
print("🧪 Test avec une session unique...")
|
||||
|
||||
agent_sessions = Path("agent_v0/sessions")
|
||||
if not agent_sessions.exists():
|
||||
print("❌ Répertoire agent_v0/sessions non trouvé")
|
||||
return
|
||||
|
||||
# Prendre la première session avec screenshots
|
||||
for session_dir in agent_sessions.iterdir():
|
||||
if session_dir.is_dir() and session_dir.name.startswith('sess_'):
|
||||
shots_dir = session_dir / "shots"
|
||||
if shots_dir.exists() and list(shots_dir.glob("*.png")):
|
||||
print(f"🎯 Test avec {session_dir.name}")
|
||||
success = fix_session_upload(session_dir)
|
||||
print(f"📊 Résultat test : {'✅ Réussi' if success else '❌ Échoué'}")
|
||||
return success
|
||||
|
||||
print("❌ Aucune session avec screenshots trouvée")
|
||||
return False
|
||||
|
||||
def fix_all_sessions():
|
||||
"""Corrige toutes les sessions avec screenshots."""
|
||||
print("🚀 Correction de toutes les sessions avec screenshots...")
|
||||
|
||||
agent_sessions = Path("agent_v0/sessions")
|
||||
if not agent_sessions.exists():
|
||||
print("❌ Répertoire agent_v0/sessions non trouvé")
|
||||
return
|
||||
|
||||
fixed_count = 0
|
||||
total_count = 0
|
||||
|
||||
for session_dir in agent_sessions.iterdir():
|
||||
if session_dir.is_dir() and session_dir.name.startswith('sess_'):
|
||||
shots_dir = session_dir / "shots"
|
||||
if shots_dir.exists() and list(shots_dir.glob("*.png")):
|
||||
total_count += 1
|
||||
print(f"\n📸 Session {total_count}: {session_dir.name}")
|
||||
if fix_session_upload(session_dir):
|
||||
fixed_count += 1
|
||||
|
||||
print(f"\n📊 Résultat final : {fixed_count}/{total_count} sessions corrigées")
|
||||
|
||||
def main():
|
||||
"""Point d'entrée principal."""
|
||||
print("🚀 Correction des uploads de screenshots - Version 3")
|
||||
print("=" * 60)
|
||||
|
||||
# Test avec une session d'abord
|
||||
if test_single_session():
|
||||
print("\n✅ Test réussi ! Procédons à toutes les sessions...")
|
||||
fix_all_sessions()
|
||||
else:
|
||||
print("\n❌ Test échoué, arrêt du processus")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user