-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.ps1
More file actions
108 lines (100 loc) · 4.57 KB
/
start.ps1
File metadata and controls
108 lines (100 loc) · 4.57 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# PLCSim Campaign Test Manager - Main Menu
# Interactive script to run various project tasks
# Configuration
$VENV_DIR = ".venv"
while ($true) {
Clear-Host
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host " API Manager" -ForegroundColor Green
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Select an option:" -ForegroundColor Yellow
Write-Host ""
Write-Host "1) Create/Activate virtual environment" -ForegroundColor White
Write-Host "2) Install dependencies" -ForegroundColor White
Write-Host "3) Start API" -ForegroundColor White
Write-Host "4) Exit" -ForegroundColor White
Write-Host ""
$choice = Read-Host "Enter your choice [1-4]"
switch ($choice) {
"1" {
Write-Host ""
if (Test-Path "$VENV_DIR") {
Write-Host "Virtual environment already exists. Activating..." -ForegroundColor Yellow
.\$VENV_DIR\Scripts\Activate.ps1
Write-Host "Virtual environment activated!" -ForegroundColor Green
Write-Host "Python version: $(python --version)" -ForegroundColor Cyan
} else {
Write-Host "Creating virtual environment..." -ForegroundColor Yellow
python -m venv $VENV_DIR
Write-Host "Virtual environment created!" -ForegroundColor Green
Write-Host "Activating virtual environment..." -ForegroundColor Yellow
.\$VENV_DIR\Scripts\Activate.ps1
Write-Host "Virtual environment activated!" -ForegroundColor Green
Write-Host "Python version: $(python --version)" -ForegroundColor Cyan
Write-Host ""
Write-Host "Installing dependencies..." -ForegroundColor Yellow
python -m pip install --upgrade pip
}
Write-Host ""
Write-Host "Press any key to continue..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
"2" {
Write-Host ""
Write-Host "--- Install Dependencies ---" -ForegroundColor Cyan
Write-Host ""
Write-Host "Installing dependencies..." -ForegroundColor Green
python -m pip install --upgrade -r requirements.txt
Write-Host ""
Write-Host "Dependencies installed!" -ForegroundColor Green
Write-Host ""
Write-Host "Press any key to continue..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
"3" {
Write-Host ""
Write-Host "Reading configuration from config.json..." -ForegroundColor Yellow
# Lire config.json
$config = Get-Content "config.json" | ConvertFrom-Json
$host_ip = $config.api.ip
$host_port = $config.api.port
# Demander le mode de développement
Write-Host ""
Write-Host "Development mode:" -ForegroundColor Cyan
Write-Host "1) Developer mode (--reload enabled)"
Write-Host "2) Production mode (--reload disabled)"
Write-Host ""
$dev_mode = Read-Host "Choose mode [1-2] (default: 1)"
# Définir le flag reload
if ($dev_mode -eq "2") {
$reload_flag = ""
$mode_text = "production"
} else {
$reload_flag = "--reload"
$mode_text = "developer"
}
Write-Host ""
Write-Host "Starting API in $mode_text mode..." -ForegroundColor Green
Write-Host "Server will be available at http://$($host_ip):$($host_port)" -ForegroundColor Cyan
Write-Host "Press Ctrl+C to stop the server" -ForegroundColor Yellow
Write-Host ""
uvicorn api.main:app $reload_flag --host $host_ip --port $host_port
Write-Host ""
Write-Host "Press any key to continue..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
"4" {
Write-Host ""
Write-Host "Goodbye!" -ForegroundColor Green
exit 0
}
default {
Write-Host ""
Write-Host "Invalid option. Please try again." -ForegroundColor Red
Write-Host ""
Write-Host "Press any key to continue..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
}
}