#!/usr/bin/env python3
"""
Fix Passenger Configuration
============================
This script renames the corrupted passenger_wsgi.py file so Passenger 
will use the control panel settings instead.
"""
import os
import sys

def main():
    print("=" * 70)
    print("FIXING PASSENGER CONFIGURATION")
    print("=" * 70)
    
    # Check if passenger_wsgi.py exists
    if os.path.exists('passenger_wsgi.py'):
        print("\nFound passenger_wsgi.py - this file is causing the problem")
        print("Renaming it to passenger_wsgi.py.DISABLED...")
        
        try:
            os.rename('passenger_wsgi.py', 'passenger_wsgi.py.DISABLED')
            print("SUCCESS: passenger_wsgi.py renamed to passenger_wsgi.py.DISABLED")
            print("\nPassenger will now use the control panel settings:")
            print("  Application startup file: wsgi.py")
            print("  Application Entry point: app")
        except Exception as e:
            print(f"ERROR: Could not rename file: {e}")
            return 1
    else:
        print("\npassenger_wsgi.py not found - already fixed or doesn't exist")
    
    print("\n" + "=" * 70)
    print("NEXT STEPS:")
    print("=" * 70)
    print("1. Restart your Python application in the control panel")
    print("2. Visit: https://columbiawindows.com/product-finder/test")
    print("3. If it works, you're done!")
    print("=" * 70)
    
    return 0

if __name__ == '__main__':
    sys.exit(main())
