Files
RadioPhotonic_PCB_PC_software/run_device_main.bat
2026-06-02 17:44:15 +03:00

72 lines
1.7 KiB
Batchfile

@echo off
setlocal
set "PROJECT_DIR=%~dp0"
pushd "%PROJECT_DIR%" >nul || (
echo Failed to switch to project directory: %PROJECT_DIR%
pause
exit /b 1
)
set "VENV_DIR=.venv"
set "VENV_PYTHON=%VENV_DIR%\Scripts\python.exe"
rem --- If the venv already exists, just run the app (works fully offline) ---
if exist "%VENV_PYTHON%" goto run
rem --- First run only: create venv and install dependencies (needs internet) ---
echo Virtual environment not found. Creating it (internet required, one time only)...
call :find_python
if errorlevel 1 goto :error
"%PYTHON_EXE%" %PYTHON_ARGS% -m venv "%VENV_DIR%"
if errorlevel 1 goto :error
if exist "requirements.txt" (
echo Installing dependencies...
"%VENV_PYTHON%" -m pip install --disable-pip-version-check -r requirements.txt
if errorlevel 1 (
echo.
echo Failed to install dependencies. Check your internet connection and run again.
rem Remove the half-baked venv so the next run retries cleanly.
rmdir /s /q "%VENV_DIR%"
goto :error
)
) else (
echo requirements.txt not found. Skipping dependency installation.
)
:run
echo Starting laser_control.gui.main...
"%VENV_PYTHON%" -m laser_control.gui.main
set "EXIT_CODE=%ERRORLEVEL%"
popd >nul
if not "%EXIT_CODE%"=="0" pause
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
pause
exit /b %EXIT_CODE%