Skip to content

Commit 2bc661a

Browse files
author
Chris Maunder
committed
Added 'libraries' option for clean
1 parent f266f19 commit 2bc661a

File tree

2 files changed

+349
-211
lines changed

2 files changed

+349
-211
lines changed

devops/install/clean.bat

Lines changed: 156 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,12 @@
99
cls
1010
setlocal enabledelayedexpansion
1111

12-
pushd ..\..
13-
set rootDir=%cd%
14-
popd
15-
16-
set installScriptsDirPath=!rootDir!\devops\install
17-
set utilsScriptsDirPath=!rootDir!\devops\scripts
18-
set utilsScript=!utilsScriptsDirPath!\utils.bat
19-
20-
set externalModulesDir=!rootDir!\..\CodeProject.AI-Modules
21-
22-
REM echo rootdir = !rootdir!
23-
REM echo installScriptDirPath = !installScriptsDirPath!
24-
REM echo utilsScriptsDirPath = !utilsScriptsDirPath!
25-
REM echo utilsScript = !utilsScript!
26-
2712
set useColor=true
2813
set doDebug=false
2914
set lineWidth=70
3015

16+
REM List of modules we'll look after ===========================================
17+
3118
set dotNetModules=ObjectDetectionYOLOv5Net
3219
set pythonModules=ObjectDetectionYOLOv5-6.2
3320

@@ -43,63 +30,133 @@ set pythonExternalModules=CodeProject.AI-ALPR CodeProject.AI-ALPR-RKNN CodeProje
4330
set dotNetDemoModules=DotNetLongProcess DotNetSimple DotNetLongProcess
4431
set pythonDemoModules=PythonLongProcess PythonSimple PythonLongProcess
4532

33+
REM Setup ======================================================================
34+
35+
pushd ..\..
36+
set rootDir=%cd%
37+
popd
38+
39+
set installScriptsDirPath=!rootDir!\devops\install
40+
set utilsScriptsDirPath=!rootDir!\devops\scripts
41+
set utilsScript=!utilsScriptsDirPath!\utils.bat
42+
set externalModulesDir=!rootDir!\..\CodeProject.AI-Modules
43+
44+
REM Output usage ===============================================================
45+
4646
if "%1" == "" (
4747
call "!utilsScript!" WriteLine "Solution Cleaner" "White"
4848
call "!utilsScript!" WriteLine
49-
call "!utilsScript!" WriteLine "clean [build : assets : install : installall : downloads : all]"
49+
call "!utilsScript!" WriteLine "clean option"
50+
call "!utilsScript!" WriteLine
51+
call "!utilsScript!" WriteLine " where 'option' is one of:"
5052
call "!utilsScript!" WriteLine
51-
call "!utilsScript!" WriteLine " build - cleans build output (bin / obj)"
52-
call "!utilsScript!" WriteLine " install - removes installation stuff, current OS (Python, PIPs, downloads etc)"
53-
call "!utilsScript!" WriteLine " installall - removes installation stuff for all OSs"
5453
call "!utilsScript!" WriteLine " assets - removes assets that were downloaded and moved into place"
54+
call "!utilsScript!" WriteLine " build - cleans build output (bin / obj)"
5555
call "!utilsScript!" WriteLine " data - removes user data stored by modules"
5656
call "!utilsScript!" WriteLine " download-cache - removes download cache to force re-download"
57+
call "!utilsScript!" WriteLine " install - removes installation stuff, current OS (Python, PIPs, downloads etc)"
58+
call "!utilsScript!" WriteLine " install-all - removes installation stuff for all OSs"
59+
call "!utilsScript!" WriteLine " libraries - removes installed libraries (PIPs), current OS"
60+
call "!utilsScript!" WriteLine " libraries-all - removes installed libraries (PIPs), all OSs"
5761
call "!utilsScript!" WriteLine " all - removes build and installation stuff for all OSs"
5862
call "!utilsScript!" WriteLine
5963
exit /b
6064
)
6165

66+
REM Param checks ===============================================================
6267

63-
set cleanBuild=false
6468
set cleanAssets=false
69+
set cleanBuild=false
6570
set cleanUserData=false
6671
set cleanDownloadCache=false
6772
set cleanInstallCurrentOS=false
6873
set cleanInstallAll=false
74+
set cleanLibraries=false
75+
set cleanLibrariesAll=false
76+
6977
set cleanAll=false
7078

71-
if /i "%1" == "build" set cleanBuild=true
72-
if /i "%1" == "install" set cleanInstallCurrentOS=true
73-
if /i "%1" == "installall" set cleanInstallAll=true
7479
if /i "%1" == "assets" set cleanAssets=true
80+
if /i "%1" == "build" set cleanBuild=true
7581
if /i "%1" == "data" set cleanUserData=true
7682
if /i "%1" == "download-cache" set cleanDownloadCache=true
83+
if /i "%1" == "install" set cleanInstallCurrentOS=true
84+
if /i "%1" == "install-all" set cleanInstallAll=true
85+
if /i "%1" == "libraries" set cleanLibraries=true
86+
if /i "%1" == "libraries-all" set cleanLibrariesAll=true
7787
if /i "%1" == "all" set cleanAll=true
7888

79-
REM if /i "!cleanAll!" == "true" set cleanInstallAll=true
80-
REM if /i "!cleanInstallAll!" == "true" set cleanInstallCurrentOS=true
81-
REM if /i "!cleanInstallCurrentOS!" == "true" set cleanBuild=true
89+
REM Set directing variables ====================================================
8290

8391
if /i "!cleanAll!" == "true" (
84-
set cleanInstallAll=true
85-
set cleanBuild=true
86-
set cleanUserData=true
8792
set cleanAssets=true
93+
set cleanBuild=true
8894
set cleanDownloadCache=true
95+
set cleanInstallAll=true
96+
set cleanLibrariesAll=true
97+
set cleanUserData=true
8998
)
9099

91100
if /i "!cleanInstallCurrentOS!" == "true" (
92-
set cleanBuild=true
93101
set cleanAssets=true
102+
set cleanBuild=true
103+
set cleanLibraries=true
94104
set cleanUserData=true
95105
)
96106

97107
if /i "!cleanInstallAll!" == "true" (
98-
set cleanBuild=true
99108
set cleanAssets=true
109+
set cleanBuild=true
110+
set cleanLibrariesAll=true
100111
set cleanUserData=true
101112
)
102113

114+
REM Start cleaning =============================================================
115+
116+
if /i "%cleanAssets%" == "true" (
117+
118+
call "!utilsScript!" WriteLine
119+
call "!utilsScript!" WriteLine "Cleaning Assets" "White" "Blue" !lineWidth!
120+
call "!utilsScript!" WriteLine
121+
122+
REM Production modules
123+
call :RemoveDir "!rootDir!\src\modules\ObjectDetectionYOLOv5-6.2\assets"
124+
call :RemoveDir "!rootDir!\src\modules\ObjectDetectionYOLOv5-6.2\custom-models"
125+
call :RemoveDir "!rootDir!\src\modules\ObjectDetectionYOLOv5Net\assets"
126+
call :RemoveDir "!rootDir!\src\modules\ObjectDetectionYOLOv5Net\custom-models"
127+
call :RemoveDir "!rootDir!\src\modules\ObjectDetectionYOLOv5Net\LocalNugets"
128+
129+
REM External modules
130+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ALPR\paddleocr"
131+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ALPR-RKNN\paddleocr"
132+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-BackgroundRemover\models"
133+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-Cartoonizer\weights"
134+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-FaceProcessing\assets"
135+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-LlamaChat\models"
136+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ObjectDetectionYOLOv5-3.1\assets"
137+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ObjectDetectionYOLOv5-3.1\custom-models"
138+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ObjectDetectionYOLOv8\assets"
139+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ObjectDetectionYOLOv8\custom-models"
140+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ObjectDetectionCoral\assets"
141+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ObjectDetectionCoral\edgetpu_runtime"
142+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ObjectDetectionYoloRKNN\assets"
143+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ObjectDetectionYoloRKNN\custom-models"
144+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-OCR\paddleocr"
145+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-SceneClassifier\assets"
146+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-SoundClassifierTF\data"
147+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-Text2Image\assets"
148+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-TrainingObjectDetectionYOLOv5\assets"
149+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-TrainingObjectDetectionYOLOv5\datasets"
150+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-TrainingObjectDetectionYOLOv5\fiftyone"
151+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-TrainingObjectDetectionYOLOv5\training"
152+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-TrainingObjectDetectionYOLOv5\zoo"
153+
154+
REM Demo modules
155+
call :RemoveDir "!rootDir!\src\demos\modules\DotNetLongProcess\assets"
156+
call :RemoveDir "!rootDir!\src\demos\modules\DotNetSimple\assets"
157+
call :RemoveDir "!rootDir!\src\demos\modules\PythonLongProcess\assets"
158+
call :RemoveDir "!rootDir!\src\demos\modules\PythonSimple\assets"
159+
)
103160

104161
if /i "%cleanBuild%" == "true" (
105162

@@ -116,24 +173,19 @@ if /i "%cleanBuild%" == "true" (
116173
for %%x in (!dotNetModules!) do (
117174
call :RemoveDir "!rootDir!\src\modules\%%x\bin\"
118175
call :RemoveDir "!rootDir!\src\modules\%%x\obj\"
119-
del "!rootDir!\src\modules\%%x\%%x-*"
176+
call :DelDirPattern "!rootDir!\src\modules\%%x\%%x-*"
120177
)
121178
for %%x in (!dotNetExternalModules!) do (
122179
call :RemoveDir "!externalModulesDir!\%%x\bin\"
123180
call :RemoveDir "!externalModulesDir!\%%x\obj\"
124-
del "!rootDir!\src\modules\%%x\%%x-*"
181+
call :DelDirPattern "!rootDir!\src\modules\%%x\%%x-*"
125182
)
126183
for %%x in (!dotNetDemoModules!) do (
127184
call :RemoveDir "!rootDir!\src\demos\modules\%%x\bin\"
128185
call :RemoveDir "!rootDir!\src\demos\modules\%%x\obj\"
129-
del "!rootDir!\src\demos\modules\%%x\%%x-*"
186+
call :DelDirPattern "!rootDir!\src\demos\modules\%%x\%%x-*"
130187
)
131188

132-
call :CleanSubDirs "!rootDir!\Installers\Windows\" "\bin\Debug\"
133-
call :CleanSubDirs "!rootDir!\Installers\Windows\" "\bin\Release\"
134-
call :CleanSubDirs "!rootDir!\Installers\Windows\" "\obj\Debug\"
135-
call :CleanSubDirs "!rootDir!\Installers\Windows\" "\obj\Release\"
136-
137189
call :RemoveDir "!rootDir!\utils\ParseJSON\bin"
138190
call :RemoveDir "!rootDir!\utils\ParseJSON\obj"
139191
del "!rootDir!\utils\ParseJSON\ParseJSON.deps.json"
@@ -151,6 +203,26 @@ if /i "%cleanBuild%" == "true" (
151203
call :RemoveDir "!rootDir!\tests\QueueServiceTests\obj\"
152204
)
153205

206+
if /i "%cleanDownloadCache%" == "true" (
207+
208+
call "!utilsScript!" WriteLine
209+
call "!utilsScript!" WriteLine "Cleaning Downloads" "White" "Blue" !lineWidth!
210+
call "!utilsScript!" WriteLine
211+
212+
rem delete downloads for each module
213+
FOR /d %%a IN ("%rootDir%\downloads\*") DO (
214+
IF /i NOT "%%~nxa"=="modules" IF /i NOT "%%~nxa"=="models" call :RemoveDir "%%a"
215+
)
216+
rem delete module packages downloads
217+
FOR %%a IN ("%rootDir%\downloads\modules\*") DO (
218+
IF /i NOT "%%~nxa"=="readme.txt" call :RemoveFile "%%a"
219+
)
220+
rem delete model packages downloads
221+
FOR %%a IN ("%rootDir%\downloads\models\*") DO (
222+
IF /i NOT "%%~nxa"=="models.json" call :RemoveFile "%%a"
223+
)
224+
)
225+
154226
if /i "%cleanInstallCurrentOS%" == "true" (
155227

156228
call "!utilsScript!" WriteLine
@@ -172,15 +244,6 @@ if /i "%cleanInstallCurrentOS%" == "true" (
172244
)
173245
)
174246

175-
if /i "%cleanUserData%" == "true" (
176-
177-
call "!utilsScript!" WriteLine
178-
call "!utilsScript!" WriteLine "Cleaning User data" "White" "Blue" !lineWidth!
179-
call "!utilsScript!" WriteLine
180-
181-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-FaceProcessing\datastore"
182-
)
183-
184247
if /i "%cleanInstallAll%" == "true" (
185248

186249
call "!utilsScript!" WriteLine
@@ -202,73 +265,58 @@ if /i "%cleanInstallAll%" == "true" (
202265
)
203266
)
204267

205-
if /i "%cleanAssets%" == "true" (
268+
if /i "%cleanLibraries%" == "true" (
206269

207270
call "!utilsScript!" WriteLine
208-
call "!utilsScript!" WriteLine "Cleaning Assets" "White" "Blue" !lineWidth!
271+
call "!utilsScript!" WriteLine "Cleaning Libraries, current OS" "White" "Blue" !lineWidth!
209272
call "!utilsScript!" WriteLine
210273

211-
REM Production modules
212-
call :RemoveDir "!rootDir!\src\modules\ObjectDetectionYOLOv5-6.2\assets"
213-
call :RemoveDir "!rootDir!\src\modules\ObjectDetectionYOLOv5-6.2\custom-models"
214-
call :RemoveDir "!rootDir!\src\modules\ObjectDetectionYOLOv5Net\assets"
215-
call :RemoveDir "!rootDir!\src\modules\ObjectDetectionYOLOv5Net\custom-models"
216-
call :RemoveDir "!rootDir!\src\modules\ObjectDetectionYOLOv5Net\LocalNugets"
217-
218-
REM External modules
219-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ALPR\paddleocr"
220-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ALPR-RKNN\paddleocr"
221-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-BackgroundRemover\models"
222-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-Cartoonizer\weights"
223-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-FaceProcessing\assets"
224-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-LlamaChat\models"
225-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ObjectDetectionYOLOv5-3.1\assets"
226-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ObjectDetectionYOLOv5-3.1\custom-models"
227-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ObjectDetectionYOLOv8\assets"
228-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ObjectDetectionYOLOv8\custom-models"
229-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ObjectDetectionCoral\assets"
230-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ObjectDetectionCoral\edgetpu_runtime"
231-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ObjectDetectionYoloRKNN\assets"
232-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-ObjectDetectionYoloRKNN\custom-models"
233-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-OCR\paddleocr"
234-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-SceneClassifier\assets"
235-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-SoundClassifierTF\data"
236-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-Text2Image\assets"
237-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-TrainingObjectDetectionYOLOv5\assets"
238-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-TrainingObjectDetectionYOLOv5\datasets"
239-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-TrainingObjectDetectionYOLOv5\fiftyone"
240-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-TrainingObjectDetectionYOLOv5\training"
241-
call :RemoveDir "!externalModulesDir!\CodeProject.AI-TrainingObjectDetectionYOLOv5\zoo"
274+
call :DelDirPattern "!rootDir!\runtimes\bin\windows\python*\venv\Lib\site-packages\*"
242275

243-
REM Demo modules
244-
call :RemoveDir "!rootDir!\src\demos\modules\DotNetLongProcess\assets"
245-
call :RemoveDir "!rootDir!\src\demos\modules\DotNetSimple\assets"
246-
call :RemoveDir "!rootDir!\src\demos\modules\PythonLongProcess\assets"
247-
call :RemoveDir "!rootDir!\src\demos\modules\PythonSimple\assets"
276+
REM Clean module python venvs
277+
for %%x in (!pythonModules!) do (
278+
call :DelDirPattern "!rootDir!\modules\%%x\bin\windows\python*\venv\Lib\site-packages\*"
279+
)
280+
for %%x in (!pythonExternalModules!) do (
281+
call :DelDirPattern "!externalModulesDir!\%%x\bin\windows\python*\venv\Lib\site-packages\*"
282+
)
283+
for %%x in (!pythonDemoModules!) do (
284+
call :DelDirPattern "!rootDir!\src\demos\modules\%%x\bin\windows\python*\venv\Lib\site-packages\*"
285+
)
248286
)
249287

250-
if /i "%cleanDownloadCache%" == "true" (
288+
if /i "%cleanLibrariesAll%" == "true" (
251289

252290
call "!utilsScript!" WriteLine
253-
call "!utilsScript!" WriteLine "Cleaning Downloads" "White" "Blue" !lineWidth!
291+
call "!utilsScript!" WriteLine "Cleaning Libraries, all OSs" "White" "Blue" !lineWidth!
254292
call "!utilsScript!" WriteLine
255293

256-
rem delete downloads for each module
257-
FOR /d %%a IN ("%rootDir%\downloads\*") DO (
258-
IF /i NOT "%%~nxa"=="modules" IF /i NOT "%%~nxa"=="models" call :RemoveDir "%%a"
294+
REM Clean module python venvs
295+
for %%x in (!pythonModules!) do (
296+
call :DelDirPattern "!rootDir!\modules\%%x\bin\*"
259297
)
260-
rem delete module packages downloads
261-
FOR %%a IN ("%rootDir%\downloads\modules\*") DO (
262-
IF /i NOT "%%~nxa"=="readme.txt" call :RemoveFile "%%a"
298+
for %%x in (!pythonExternalModules!) do (
299+
call :DelDirPattern "!externalModulesDir!\%%x\bin\*"
263300
)
264-
rem delete model packages downloads
265-
FOR %%a IN ("%rootDir%\downloads\models\*") DO (
266-
IF /i NOT "%%~nxa"=="models.json" call :RemoveFile "%%a"
301+
for %%x in (!pythonDemoModules!) do (
302+
call :DelDirPattern "!rootDir!\src\demos\modules\%%x\bin\*"
267303
)
268304
)
269305

306+
if /i "%cleanUserData%" == "true" (
307+
308+
call "!utilsScript!" WriteLine
309+
call "!utilsScript!" WriteLine "Cleaning User data" "White" "Blue" !lineWidth!
310+
call "!utilsScript!" WriteLine
311+
312+
call :RemoveDir "!externalModulesDir!\CodeProject.AI-FaceProcessing\datastore"
313+
)
314+
270315
goto:eof
271316

317+
318+
REM Functions ==================================================================
319+
272320
:RemoveFile
273321
SetLocal EnableDelayedExpansion
274322

@@ -285,6 +333,17 @@ goto:eof
285333
)
286334
)
287335

336+
:DelDirPattern
337+
SetLocal EnableDelayedExpansion
338+
339+
set pathPattern=%~1
340+
341+
if /i "!doDebug!" == "true" (
342+
call "!utilsScript!" WriteLine "Marked for removal: !pathPattern!" "!color_error!"
343+
) else (
344+
del "!pathPattern!"
345+
call "!utilsScript!" WriteLine "Removed !pathPattern!" "!color_success!"
346+
)
288347

289348
:RemoveDir
290349
SetLocal EnableDelayedExpansion

0 commit comments

Comments
 (0)