-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.bat
More file actions
220 lines (180 loc) · 6.46 KB
/
Copy pathsetup.bat
File metadata and controls
220 lines (180 loc) · 6.46 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
@echo off
setlocal EnableDelayedExpansion
title PY-AUTOMATE Setup
echo.
echo ==========================================
echo PY-AUTOMATE -- Environment Setup
echo ==========================================
echo.
:: ── Locate Python ─────────────────────────────────────────────────────────
set PYTHON=
for %%C in (python python3) do (
if not defined PYTHON (
where %%C >nul 2>&1
if !errorlevel! == 0 (
set PYTHON=%%C
)
)
)
if not defined PYTHON (
echo [ERROR] Python not found on PATH.
echo.
echo Install Python 3.9 or newer from https://www.python.org/downloads/
echo Make sure to check "Add Python to PATH" during installation.
echo.
pause
exit /b 1
)
:: Verify minimum version (3.9+)
for /f "tokens=2 delims= " %%V in ('"%PYTHON%" --version 2^>^&1') do set PY_VER=%%V
for /f "tokens=1,2 delims=." %%A in ("%PY_VER%") do (
set PY_MAJOR=%%A
set PY_MINOR=%%B
)
if %PY_MAJOR% LSS 3 (
echo [ERROR] Python 3.9+ required. Found %PY_VER%.
pause
exit /b 1
)
if %PY_MAJOR% EQU 3 if %PY_MINOR% LSS 9 (
echo [ERROR] Python 3.9+ required. Found %PY_VER%.
pause
exit /b 1
)
echo [OK] Python %PY_VER% found at:
for /f "delims=" %%P in ('where %PYTHON%') do echo %%P
echo.
:: ── Create virtual environment ─────────────────────────────────────────────
set VENV_DIR=%~dp0.venv
if exist "%VENV_DIR%\Scripts\activate.bat" (
echo [OK] Virtual environment already exists.
) else (
echo [..] Creating virtual environment in .venv ...
"%PYTHON%" -m venv "%VENV_DIR%"
if errorlevel 1 (
echo [ERROR] Failed to create virtual environment.
pause
exit /b 1
)
echo [OK] Virtual environment created.
)
echo.
:: ── Activate venv ──────────────────────────────────────────────────────────
call "%VENV_DIR%\Scripts\activate.bat"
:: ── Upgrade pip silently ───────────────────────────────────────────────────
echo [..] Upgrading pip ...
python -m pip install --upgrade pip --quiet
echo [OK] pip up to date.
echo.
:: ── Install core dependencies ──────────────────────────────────────────────
echo [..] Installing core dependencies ...
echo.
pip install flask flask-cors
if errorlevel 1 (
echo.
echo [ERROR] Dependency installation failed.
pause
exit /b 1
)
echo.
echo [OK] Core dependencies installed.
echo.
:: ── Create required project folders ───────────────────────────────────────
echo [..] Checking project folders ...
for %%D in (plugins workspaces history static templates) do (
if not exist "%~dp0%%D\" (
mkdir "%~dp0%%D"
echo [+] Created: %%D\
) else (
echo [OK] Exists: %%D\
)
)
echo.
:: ── Move static assets into Flask's expected layout ───────────────────────
:: Flask serves static files from /static and templates from /templates.
:: If index.html is sitting next to app.py, move it to templates/.
:: If styles.css / scripts.js are next to app.py, move them to static/.
set MOVED=0
if exist "%~dp0index.html" (
if not exist "%~dp0templates\index.html" (
move "%~dp0index.html" "%~dp0templates\index.html" >nul
echo [+] Moved index.html -> templates\index.html
set MOVED=1
)
)
for %%F in (styles.css scripts.js) do (
if exist "%~dp0%%F" (
if not exist "%~dp0static\%%F" (
move "%~dp0%%F" "%~dp0static\%%F" >nul
echo [+] Moved %%F -> static\%%F
set MOVED=1
)
)
)
if %MOVED% == 0 (
echo [OK] Static assets already in place.
)
echo.
:: ── Copy plugin files into plugins\ if they are next to app.py ────────────
set PLUGINS_MOVED=0
for %%F in ("%~dp0endmill_utils.py" "%~dp0laser_utils.py") do (
if exist "%%F" (
move "%%F" "%~dp0plugins\" >nul
echo [+] Moved %%~nxF -> plugins\
set PLUGINS_MOVED=1
)
)
if %PLUGINS_MOVED% == 0 (
echo [OK] Plugin files already in plugins\
)
echo.
:: ── Write launcher scripts ──────────────────────────────────────────────────
set LAUNCHER=%~dp0run.bat
if not exist "%LAUNCHER%" (
(
echo @echo off
echo call "%%~dp0.venv\Scripts\activate.bat"
echo start "" http://localhost:5000
echo python "%%~dp0app.py"
) > "%LAUNCHER%"
echo [+] Created run.bat -- CMD-window launcher.
) else (
echo [OK] run.bat already exists.
)
set VBS_LAUNCHER=%~dp0launch.vbs
if not exist "%VBS_LAUNCHER%" (
(
echo Dim sh, base
echo Set sh = CreateObject("WScript.Shell"^)
echo base = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\"^)^)
echo sh.Run """" ^& base ^& ".venv\Scripts\pythonw.exe"" """ ^& base ^& "app.py""", 0, False
echo WScript.Sleep 2000
echo sh.Run "http://localhost:5000"
) > "%VBS_LAUNCHER%"
echo [+] Created launch.vbs -- no-window launcher (recommended^).
) else (
echo [OK] launch.vbs already exists.
)
echo.
:: ── Summary ────────────────────────────────────────────────────────────────
echo ==========================================
echo Setup complete.
echo ==========================================
echo.
echo To start PY-AUTOMATE:
echo.
echo launch.vbs (double-click -- no CMD window, opens browser automatically)
echo run.bat (CMD window stays open -- useful if you need to see output)
echo.
echo Or manually:
echo.
echo .venv\Scripts\activate
echo python app.py
echo.
echo The app will be available at http://localhost:5000
echo.
echo Tip: enable "Server logs in console" in the Settings panel to see
echo Flask output inside the app's own output console.
echo.
pause
endlocal