Files
BDFR_Web/web_interface/start.py
T

119 lines
3.1 KiB
Python

#!/usr/bin/env python3
"""
BDFR Web Interface Startup Script
This script provides an easy way to start the BDFR web interface with
proper dependency management and error handling.
"""
import os
import sys
import subprocess
import importlib.util
from pathlib import Path
def check_python_version():
"""Check if Python version is compatible (3.8+)"""
if sys.version_info < (3, 8):
print("ERROR: Python 3.8 or higher is required")
print(f"Current version: {sys.version}")
sys.exit(1)
def install_dependencies():
"""Install required dependencies if missing"""
requirements_path = Path(__file__).parent / "requirements.txt"
if not requirements_path.exists():
print("❌ Error: requirements.txt not found")
sys.exit(1)
print("Checking and installing dependencies...")
try:
# Try to import required modules first
required_modules = [
'fastapi',
'uvicorn',
'websockets',
'jinja2'
]
missing_modules = []
for module in required_modules:
if not importlib.util.find_spec(module):
missing_modules.append(module)
if missing_modules:
print(f"Installing missing modules: {', '.join(missing_modules)}")
subprocess.check_call([
sys.executable, '-m', 'pip', 'install', '-r', str(requirements_path)
])
else:
print("All dependencies are already installed")
except subprocess.CalledProcessError as e:
print(f"❌ Error installing dependencies: {e}")
sys.exit(1)
except Exception as e:
print(f"❌ Error checking dependencies: {e}")
sys.exit(1)
def check_bdfr_module():
"""Check if BDFR module is available"""
try:
importlib.util.find_spec('bdfr')
print("BDFR module found")
except ImportError:
print("⚠️ Warning: BDFR module not found in Python path")
print("Make sure the parent directory is in your Python path or run from project root")
def start_server():
"""Start the FastAPI server"""
print("Starting BDFR Web Interface...")
print("Server will be available at: http://localhost:8000")
print("API documentation at: http://localhost:8000/docs")
print("Press Ctrl+C to stop the server")
print("-" * 50)
try:
# Start uvicorn server
subprocess.call([
sys.executable, '-m', 'uvicorn',
'app.main:app',
'--host', '0.0.0.0',
'--port', '8000',
'--reload'
])
except KeyboardInterrupt:
print("\n🛑 Server stopped by user")
except Exception as e:
print(f"❌ Error starting server: {e}")
sys.exit(1)
def main():
"""Main startup function"""
print("BDFR Web Interface Startup")
print("=" * 40)
# Change to web_interface directory
web_interface_dir = Path(__file__).parent
os.chdir(web_interface_dir)
# Pre-flight checks
check_python_version()
install_dependencies()
check_bdfr_module()
print("\n" + "=" * 40)
# Start the server
start_server()
if __name__ == "__main__":
main()