#!/usr/bin/env python3
"""
Quick restart script for cPanel deployment
"""

import os
import time
from pathlib import Path

def restart_application():
    """Restart the application by touching restart.txt"""
    print("🔄 Restarting application...")
    
    # Touch restart.txt to restart Passenger
    restart_file = Path('tmp/restart.txt')
    restart_file.parent.mkdir(exist_ok=True)
    restart_file.touch()
    
    print("✅ Application restart triggered")
    print("⏳ Please wait 10-15 seconds for the changes to take effect")

def test_media_access():
    """Test if media files are accessible"""
    print("\n🧪 Testing media file access...")
    
    # Test a known file
    test_files = [
        'media/kyc/id_documents/Untitled.png',
        'media/kyc/selfies/folder.jpg',
        'media/test/test.txt'
    ]
    
    for file_path in test_files:
        if Path(file_path).exists():
            print(f"✅ File exists: {file_path}")
        else:
            print(f"❌ File missing: {file_path}")

def main():
    print("🚀 HAVEN GRAZURI INVESTMENT LIMITED- Quick Restart")
    print("=" * 50)
    
    # Test media files first
    test_media_access()
    
    # Restart application
    restart_application()
    
    print("\n📝 Next steps:")
    print("1. Wait 10-15 seconds")
    print("2. Test the media URL that was failing")
    print("3. Check if the 404 error is resolved")

if __name__ == '__main__':
    main()