
import sys
import os

CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
PARENT_DIR = os.path.dirname(CURRENT_DIR)

for path in (os.getcwd(), CURRENT_DIR, PARENT_DIR):
    if path not in sys.path:
        sys.path.insert(0, path)

try:
    import update_manager
    from app import create_app
except ImportError as e:
    print(f"Import Error: {e}")
    sys.exit(1)

try:
    success, msg = update_manager.perform_update()
    if success:
        print(f"Update Success: {msg}")
        sys.exit(0)
    else:
        print(f"Update Error: {msg}")
        sys.exit(1)
except Exception as e:
    print(f"Update Exception: {e}")
    sys.exit(1)
