66 lines
1.3 KiB
Batchfile
66 lines
1.3 KiB
Batchfile
@echo off
|
|
setlocal
|
|
|
|
set "PROJECT_DIR=%~dp0"
|
|
pushd "%PROJECT_DIR%" >nul || (
|
|
echo Failed to switch to project directory: %PROJECT_DIR%
|
|
exit /b 1
|
|
)
|
|
|
|
set "VENV_DIR=.venv"
|
|
set "VENV_PYTHON=%VENV_DIR%\Scripts\python.exe"
|
|
set "VENV_ACTIVATE=%VENV_DIR%\Scripts\activate.bat"
|
|
|
|
if exist "%VENV_PYTHON%" goto venv_ready
|
|
|
|
echo Creating virtual environment...
|
|
call :find_python
|
|
if errorlevel 1 goto :error
|
|
|
|
"%PYTHON_EXE%" %PYTHON_ARGS% -m venv "%VENV_DIR%"
|
|
if errorlevel 1 goto :error
|
|
|
|
:venv_ready
|
|
|
|
call "%VENV_ACTIVATE%"
|
|
if errorlevel 1 goto :error
|
|
|
|
if exist "requirements.txt" (
|
|
echo Installing dependencies...
|
|
python -m pip install --disable-pip-version-check -r requirements.txt
|
|
if errorlevel 1 goto :error
|
|
) else (
|
|
echo requirements.txt not found. Skipping dependency installation.
|
|
)
|
|
|
|
echo Starting _device_main.py...
|
|
python _device_main.py
|
|
set "EXIT_CODE=%ERRORLEVEL%"
|
|
|
|
popd >nul
|
|
exit /b %EXIT_CODE%
|
|
|
|
:find_python
|
|
where py >nul 2>&1
|
|
if not errorlevel 1 (
|
|
set "PYTHON_EXE=py"
|
|
set "PYTHON_ARGS=-3"
|
|
exit /b 0
|
|
)
|
|
|
|
where python >nul 2>&1
|
|
if not errorlevel 1 (
|
|
set "PYTHON_EXE=python"
|
|
set "PYTHON_ARGS="
|
|
exit /b 0
|
|
)
|
|
|
|
echo Python 3 was not found. Install Python and try again.
|
|
exit /b 1
|
|
|
|
:error
|
|
set "EXIT_CODE=%ERRORLEVEL%"
|
|
echo Script failed with exit code %EXIT_CODE%.
|
|
popd >nul
|
|
exit /b %EXIT_CODE%
|