#!/usr/bin/env python3 """ SciPaperLoader Diagnostic Menu A simple menu-based interface to run common diagnostic operations. """ import os import sys import subprocess from pathlib import Path # Add project root to path SCRIPT_DIR = Path(__file__).parent PROJECT_ROOT = SCRIPT_DIR.parent.parent sys.path.insert(0, str(PROJECT_ROOT)) def clear_screen(): """Clear the terminal screen.""" os.system('cls' if os.name == 'nt' else 'clear') def run_script(script_name): """Run a Python script and wait for it to complete.""" script_path = SCRIPT_DIR / script_name print(f"\nRunning {script_name}...\n") try: # Add execute permission if needed if not os.access(script_path, os.X_OK): os.chmod(script_path, os.stat(script_path).st_mode | 0o100) subprocess.run([sys.executable, str(script_path)], check=True) except subprocess.CalledProcessError as e: print(f"\nError running {script_name}: {e}") except FileNotFoundError: print(f"\nError: Script {script_name} not found at {script_path}") input("\nPress Enter to continue...") def main_menu(): """Display the main menu and handle user selection.""" while True: clear_screen() print("=" * 50) print(" SciPaperLoader Diagnostic Menu") print("=" * 50) print("1. Check scraper state") print("2. Inspect running tasks") print("3. Full diagnostic report") print("4. Test paper reversion") print("5. Emergency stop (stop all tasks)") print("6. Quick fix (stop & restart workers)") print("0. Exit") print("=" * 50) choice = input("Enter your choice (0-6): ") if choice == "0": clear_screen() print("Exiting diagnostic menu.") break elif choice == "1": run_script("check_state.py") elif choice == "2": run_script("inspect_tasks.py") elif choice == "3": run_script("diagnose_scraper.py") elif choice == "4": run_script("test_reversion.py") elif choice == "5": confirm = input("Are you sure you want to emergency stop all tasks? (y/n): ") if confirm.lower() == 'y': run_script("emergency_stop.py") elif choice == "6": confirm = input("Are you sure you want to stop all tasks and restart workers? (y/n): ") if confirm.lower() == 'y': run_script("quick_fix.py") else: print("\nInvalid choice. Press Enter to try again.") input() if __name__ == "__main__": try: main_menu() except KeyboardInterrupt: print("\nExiting due to user interrupt.") sys.exit(0)