# C:\PYTHON\MediaTrack_Hybrid\run_orchestrator.py """ Orchestratore per MediaTrack Coordina il processo di build (se necessario) e deploy """ import subprocess import sys from pathlib import Path import argparse PROJECT_ROOT = Path(__file__).resolve().parent VENV_PYTHON = PROJECT_ROOT / "venv" / "Scripts" / "python.exe" DEPLOYER_SCRIPT = PROJECT_ROOT / "MediaTrack_deployer.py" def print_header(title: str): """Stampa un header formattato.""" print(f"\n{'='*70}\n {title}\n{'='*70}") def verify_environment(): """Verifica che l'ambiente sia pronto per il deploy.""" print_header("Verifica Ambiente") # Verifica che il deployer esista if not DEPLOYER_SCRIPT.exists(): print(f"❌ Deployer non trovato: {DEPLOYER_SCRIPT}") return False print(f"✅ Deployer trovato: {DEPLOYER_SCRIPT}") # Verifica Python if VENV_PYTHON.exists(): print(f"✅ Virtual environment trovato: {VENV_PYTHON}") else: print(f"ℹ️ Virtual environment non trovato, uso Python di sistema") return True def run_deployment(args): """Esegue il deployment.""" print_header("Avvio Deployment") # Determina quale Python usare py_exec = str(VENV_PYTHON) if VENV_PYTHON.exists() else sys.executable # Costruisci comando cmd = [py_exec, str(DEPLOYER_SCRIPT), "deploy"] if args.non_interactive: cmd.append("--non-interactive") if args.force: cmd.append("-f") print(f"Comando: {' '.join(cmd)}\n") # Esegui try: result = subprocess.run(cmd, check=True) return result.returncode == 0 except subprocess.CalledProcessError as e: print(f"\n❌ Deployment fallito con codice: {e.returncode}") return False def main(): """Entry point dell'orchestratore.""" parser = argparse.ArgumentParser( description="Orchestratore per MediaTrack - Coordina build e deploy" ) parser.add_argument( "--non-interactive", action="store_true", help="Esegue senza chiedere conferme" ) parser.add_argument( "-f", "--force", action="store_true", help="Forza il deploy anche senza modifiche" ) args = parser.parse_args() print_header("MediaTrack - Orchestratore di Deployment") # Fase 1: Verifica ambiente if not verify_environment(): print("\n❌ Verifica ambiente fallita.") sys.exit(1) # Fase 2: Deploy if not run_deployment(args): print("\n❌ Deployment fallito.") sys.exit(1) # Success print_header("🎉 Processo completato con successo!") print(f"\nMediaTrack è stato deployato sul server.") print(f"Gli utenti possono ora accedere alla versione aggiornata.\n") if __name__ == "__main__": main()