-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRun_primerool.bat
More file actions
154 lines (137 loc) · 5.34 KB
/
Copy pathRun_primerool.bat
File metadata and controls
154 lines (137 loc) · 5.34 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
@echo off
chcp 65001 >nul 2>&1
setlocal enabledelayedexpansion
:: Keep window open on any unexpected exit
if "%~1"=="--child" goto :main
cmd /k ""%~f0" --child"
exit /b
:main
:: Get the directory where this script is located
cd /d "%~dp0"
echo ============================================
echo Starting Primerool
echo ============================================
echo.
:: -----------------------------------------------
:: 1. Check / install Python
:: -----------------------------------------------
set "PYTHON_CMD="
set "PY_CHECK="
for /f "delims=" %%i in ('python -c "import venv; print('OK')" 2^>nul') do set "PY_CHECK=%%i"
if "!PY_CHECK!"=="OK" set "PYTHON_CMD=python"
if not defined PYTHON_CMD (
set "PY_CHECK="
for /f "delims=" %%i in ('py -c "import venv; print('OK')" 2^>nul') do set "PY_CHECK=%%i"
if "!PY_CHECK!"=="OK" set "PYTHON_CMD=py"
)
if not defined PYTHON_CMD (
echo Python is not installed on this computer.
echo Primerool requires Python and a few libraries to run.
echo.
echo The following will be downloaded and installed automatically:
echo - Python 3.12 (~25 MB download, ~100 MB installed)
echo - Flask (~2 MB)
echo - Primer3 (~5 MB)
echo - Requests (~1 MB)
echo.
echo Make sure you are connected to the internet.
echo.
echo [INFO] Commencing automatic Python 3.12 installation...
echo.
:: Try winget first (Windows 10 1709+ / Windows 11)
winget --version >nul 2>&1
if %errorlevel% equ 0 (
echo [INFO] Installing Python via winget...
winget install -e --id Python.Python.3.12 --accept-source-agreements --accept-package-agreements
) else (
:: Fallback: use the PowerShell helper script (avoids all quoting issues)
echo [INFO] winget not available. Running PowerShell installer script...
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0install_python.ps1"
if %errorlevel% neq 0 (
echo [ERROR] Python installation failed. Please install manually from:
echo https://www.python.org/downloads/windows/
echo Make sure to check "Add Python to PATH" during installation.
pause
exit /b 1
)
)
:: Find python.exe directly — check all common install locations
set "PYTHON_EXE="
if exist "%LOCALAPPDATA%\Programs\Python\Python312\python.exe" set "PYTHON_EXE=%LOCALAPPDATA%\Programs\Python\Python312\python.exe"
if exist "%LOCALAPPDATA%\Programs\Python\Python311\python.exe" set "PYTHON_EXE=%LOCALAPPDATA%\Programs\Python\Python311\python.exe"
if exist "%LOCALAPPDATA%\Programs\Python\Python310\python.exe" set "PYTHON_EXE=%LOCALAPPDATA%\Programs\Python\Python310\python.exe"
if exist "%PROGRAMFILES%\Python312\python.exe" set "PYTHON_EXE=%PROGRAMFILES%\Python312\python.exe"
if exist "%PROGRAMFILES%\Python311\python.exe" set "PYTHON_EXE=%PROGRAMFILES%\Python311\python.exe"
if exist "%PROGRAMFILES%\Python310\python.exe" set "PYTHON_EXE=%PROGRAMFILES%\Python310\python.exe"
if defined PYTHON_EXE (
echo [OK] Found Python at: %PYTHON_EXE%
:: Add its folder and Scripts subfolder to PATH for this session
for %%F in ("!PYTHON_EXE!") do set "PATH=%%~dpF;%%~dpFScripts;!PATH!"
set "PYTHON_CMD=python"
) else (
echo.
echo ============================================
echo Python was installed successfully!
echo ============================================
echo.
echo Please close this window and open
echo run_primerool.bat again to launch Primerool.
echo.
pause
exit /b 0
)
)
for /f "tokens=*" %%v in ('!PYTHON_CMD! --version 2^>^&1') do echo [OK] Found %%v
echo.
:: -----------------------------------------------
:: 2. Create virtual environment
:: -----------------------------------------------
if not exist "venv" (
echo [INFO] Creating virtual environment...
!PYTHON_CMD! -m venv venv
if %errorlevel% neq 0 (
echo [ERROR] Failed to create virtual environment.
pause
exit /b 1
)
echo [OK] Virtual environment created.
echo.
)
:: -----------------------------------------------
:: 3. Activate virtual environment
:: -----------------------------------------------
call venv\Scripts\activate.bat
if %errorlevel% neq 0 (
echo [ERROR] Failed to activate virtual environment.
pause
exit /b 1
)
:: -----------------------------------------------
:: 4. Install / update dependencies
:: -----------------------------------------------
if exist "requirements.txt" (
echo [INFO] Installing dependencies...
pip install -r requirements.txt
if %errorlevel% neq 0 (
echo [ERROR] pip install failed. Check your internet connection.
pause
exit /b 1
)
echo [OK] Dependencies ready.
echo.
)
:: -----------------------------------------------
:: 5. Launch app
:: -----------------------------------------------
echo [INFO] Booting native desktop window...
echo [INFO] Press Ctrl+C in this terminal to force quit.
echo.
:: Open browser after a short delay
:: (Browser opening removed for desktop app mode)
!PYTHON_CMD! src\app.py
if %errorlevel% neq 0 (
echo.
echo [ERROR] The application exited with an error (code %errorlevel%).
echo See the output above for details.
)
pause