forked from video-db/Director
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-backend.bat
More file actions
93 lines (83 loc) · 2.25 KB
/
start-backend.bat
File metadata and controls
93 lines (83 loc) · 2.25 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
@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
cd /d "%~dp0backend" || exit /b 1
if not exist "venv\Scripts\activate.bat" (
echo Backend not initialized. Run setup.bat first.
exit /b 1
)
call :ensure_backend_env
if errorlevel 1 exit /b 1
echo Backend: http://127.0.0.1:8000 (Ctrl+C to stop)
call venv\Scripts\activate.bat
set "DB_TYPE=sqlite"
set SQLITE_DB_PATH=director.db
pip check >nul 2>&1
if errorlevel 1 (
echo Backend dependencies incomplete. Reinstalling requirements...
pip install --upgrade pip setuptools wheel >nul 2>&1
pip install -r requirements.txt || goto :deps_fail
if exist requirements-dev.txt (
pip install -r requirements-dev.txt || goto :deps_fail
)
pip check || goto :deps_fail
)
python director\db\sqlite\initialize.py >nul 2>&1
if errorlevel 1 (
echo SQLite initialization failed.
exit /b 1
)
python director\entrypoint\api\server.py
exit /b %errorlevel%
:ensure_backend_env
set "ENV_FILE=.env"
if not exist "%ENV_FILE%" (
if exist .env.sample (
copy /y .env.sample .env >nul
) else (
(
echo VIDEO_DB_API_KEY=
echo.
echo # Database
)> "%ENV_FILE%"
)
)
call :set_env_value "%ENV_FILE%" "DB_TYPE" "sqlite"
exit /b %errorlevel%
:set_env_value
setlocal ENABLEDELAYEDEXPANSION
set "ENV_FILE=%~1"
set "ENV_KEY=%~2"
set "ENV_VALUE=%~3"
if not exist "%ENV_FILE%" (
>"%ENV_FILE%" echo %ENV_KEY%=%ENV_VALUE%
endlocal & exit /b 0
)
set "TEMP_FILE=%ENV_FILE%.tmp"
set "VAR_WRITTEN="
(
for /f "usebackq delims=" %%L in ("%ENV_FILE%") do (
set "LINE=%%L"
set "WRITE_LINE=1"
for /f "tokens=1* delims==" %%K in ("!LINE!") do (
set "KEY=%%K"
if /i "!KEY!"=="%ENV_KEY%" (
if not defined VAR_WRITTEN (
echo %ENV_KEY%=%ENV_VALUE%
set "VAR_WRITTEN=1"
)
set "WRITE_LINE="
)
)
if defined WRITE_LINE (
echo !LINE!
)
)
if not defined VAR_WRITTEN (
echo %ENV_KEY%=%ENV_VALUE%
)
) >"%TEMP_FILE%"
move /Y "%TEMP_FILE%" "%ENV_FILE%" >nul
endlocal & exit /b 0
:deps_fail
echo Failed to reinstall backend dependencies. Review the messages above.
exit /b 1