-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.bat
More file actions
176 lines (156 loc) · 5.14 KB
/
deploy.bat
File metadata and controls
176 lines (156 loc) · 5.14 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
@echo off
:: RPCortex Deploy Script (Windows)
:: Copies OS files to a connected MicroPython device using mpremote.
:: Can deploy from the source tree (default) or a compiled dist\ image.
::
:: Usage:
:: deploy.bat -- deploy source from repo root
:: deploy.bat --compiled -- deploy compiled dist\ image
:: deploy.bat --compiled --out C:\path\dist -- deploy a custom dist dir
:: deploy.bat --port COM3 -- specify serial port explicitly
::
:: mpremote install:
:: pip install mpremote
::
:: Notes:
:: Run compile.bat first if deploying --compiled.
:: \Nebula\ and \Users\ on the device are never touched -- user data is safe.
setlocal enabledelayedexpansion
set "REPO_DIR=%~dp0"
if "%REPO_DIR:~-1%"=="\" set "REPO_DIR=%REPO_DIR:~0,-1%"
set "DIST_DIR=%REPO_DIR%\dist"
set "PORT_ARG="
set "COMPILED=0"
:: ---------------------------------------------------------------------------
:: Argument parsing
:: ---------------------------------------------------------------------------
:parse_args
if "%~1"=="" goto args_done
if /i "%~1"=="--compiled" (
set "COMPILED=1"
shift & goto parse_args
)
if /i "%~1"=="--out" (
set "DIST_DIR=%~2"
shift & shift & goto parse_args
)
if /i "%~1"=="--port" (
set "PORT_ARG=connect %~2"
shift & shift & goto parse_args
)
if /i "%~1"=="--help" (
findstr /b "::" "%~f0"
exit /b 0
)
echo Unknown option: %~1 (run with --help for usage)
exit /b 1
:args_done
:: ---------------------------------------------------------------------------
:: Prereq check
:: ---------------------------------------------------------------------------
where mpremote >nul 2>&1
if errorlevel 1 (
echo.
echo [!] mpremote not found in PATH.
echo Install it with: pip install mpremote
echo.
exit /b 1
)
if "%COMPILED%"=="1" (
if not exist "%DIST_DIR%" (
echo [!] Compiled dist not found: %DIST_DIR%
echo Run compile.bat first, or use --out to specify a path.
exit /b 1
)
set "SRC_DIR=%DIST_DIR%"
echo.
echo Deploying COMPILED image from: %DIST_DIR%
) else (
set "SRC_DIR=%REPO_DIR%"
echo.
echo Deploying SOURCE from: %REPO_DIR%
)
if "%PORT_ARG%"=="" (
echo Port: auto-detect
) else (
echo Port: %PORT_ARG%
)
echo.
set "MPR=mpremote %PORT_ARG%"
set /a uploaded=0
set /a errors=0
:: ---------------------------------------------------------------------------
:: Helper subroutines
:: ---------------------------------------------------------------------------
goto :skip_subs
:ensure_dir
%MPR% mkdir ":%~1" >nul 2>&1
exit /b 0
:upload_file
:: %1 = local path, %2 = remote path, %3 = display label
%MPR% cp "%~1" ":%~2" >nul 2>&1
if errorlevel 1 (
echo [!] FAILED: %~3
set /a errors+=1
) else (
echo [+] %~3
set /a uploaded+=1
)
exit /b 0
:skip_subs
:: ---------------------------------------------------------------------------
:: Create remote directory tree
:: ---------------------------------------------------------------------------
echo -- Creating remote directories --
call :ensure_dir /Core
call :ensure_dir /Core/Launchpad
call :ensure_dir /Packages
call :ensure_dir /Packages/Launchpad
call :ensure_dir /Packages/Editor
echo.
:: ---------------------------------------------------------------------------
:: main.py
:: ---------------------------------------------------------------------------
echo -- Entry point --
call :upload_file "%SRC_DIR%\main.py" "/main.py" "main.py"
echo.
:: ---------------------------------------------------------------------------
:: Core files (.py and .mpy)
:: ---------------------------------------------------------------------------
echo -- Core modules --
for %%F in ("%SRC_DIR%\Core\*.py" "%SRC_DIR%\Core\*.mpy") do (
if exist "%%F" call :upload_file "%%F" "/Core/%%~nxF" "Core\%%~nxF"
)
echo.
:: ---------------------------------------------------------------------------
:: Launchpad command files
:: ---------------------------------------------------------------------------
echo -- Launchpad --
for %%F in ("%SRC_DIR%\Core\Launchpad\*.*") do (
if exist "%%F" call :upload_file "%%F" "/Core/Launchpad/%%~nxF" "Core\Launchpad\%%~nxF"
)
echo.
:: ---------------------------------------------------------------------------
:: Package stubs
:: ---------------------------------------------------------------------------
echo -- Package stubs --
for %%F in ("%SRC_DIR%\Packages\Launchpad\*.*") do (
if exist "%%F" call :upload_file "%%F" "/Packages/Launchpad/%%~nxF" "Packages\Launchpad\%%~nxF"
)
for %%F in ("%SRC_DIR%\Packages\Editor\*.*") do (
if exist "%%F" call :upload_file "%%F" "/Packages/Editor/%%~nxF" "Packages\Editor\%%~nxF"
)
echo.
:: ---------------------------------------------------------------------------
:: Summary
:: ---------------------------------------------------------------------------
echo -------------------------------------------
if %errors% gtr 0 (
echo [!] %errors% file(s) failed to upload -- check output above.
)
echo Uploaded : %uploaded% files
echo.
echo Deploy complete. Reboot the device to apply.
echo.
if %errors% gtr 0 exit /b 1
exit /b 0