-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
74 lines (64 loc) · 2.35 KB
/
start.py
File metadata and controls
74 lines (64 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
"""
Development startup script for Sadqa Tracker Backend
"""
import subprocess
import sys
import os
from pathlib import Path
def run_command(command, description):
"""Run a command and handle errors"""
print(f"\n🔄 {description}...")
try:
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
print(f"✅ {description} completed successfully")
if result.stdout:
print(result.stdout)
return True
except subprocess.CalledProcessError as e:
print(f"❌ {description} failed")
if e.stderr:
print(f"Error: {e.stderr}")
return False
def main():
print("🚀 Sadqa Tracker Backend Setup")
print("=" * 50)
# Check if .env exists
env_file = Path(".env")
if not env_file.exists():
print("\n⚠️ .env file not found!")
print("Please copy .env.example to .env and configure your settings:")
print(" cp .env.example .env")
print("Then edit .env with your database URL and Google OAuth credentials.")
return 1
# Check if virtual environment is activated
if not os.environ.get('VIRTUAL_ENV'):
print("\n⚠️ Virtual environment not detected!")
print("Please activate your virtual environment first:")
print(" python -m venv venv")
print(" # On Windows: venv\\Scripts\\activate")
print(" # On macOS/Linux: source venv/bin/activate")
return 1
# Install dependencies
if not run_command("pip install -r requirements.txt", "Installing dependencies"):
return 1
# Initialize database
print("\n🗄️ Database Setup")
run_command("alembic upgrade head", "Running database migrations")
# Start the server
print("\n🌟 Starting FastAPI server...")
print("API will be available at: http://0.0.0.0:8000")
print("Documentation will be available at: http://0.0.0.0:8000/docs")
print("Press Ctrl+C to stop the server")
try:
subprocess.run([
"python", "main.py"
], check=True)
except KeyboardInterrupt:
print("\n\n👋 Server stopped. Goodbye!")
return 0
except subprocess.CalledProcessError as e:
print(f"\n❌ Server failed to start: {e}")
return 1
if __name__ == "__main__":
sys.exit(main())