-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.bat
198 lines (175 loc) · 6.32 KB
/
test.bat
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
::
:: This script calls docker commands to create an image, volumes, start a container from
:: the image, execute commands in that container, then copy outputs to the local
:: filesystem.
::
:: Note: this script uses a provided config file to
:: 1. create the volumes `data` and `output` (if they do not exist)
:: 2. build the image `tutor` (if it does not exist)
:: 3. start a container with volumes attached and
:: 4. run the chosen command with chosen configuration file
:: 5. compute output files in the `output` volume
:: 6. copy output files to the host machine
:: -----------------------------------------------------------
:: Main
:: -----------------------------------------------------------
@echo off
set SCRIPT_NAME=%0
set CMD=%1
set HOST_CONFIG_FILE=%2
set /a arg_count=0
for %%x in (%*) do Set /A arg_count+=1
call:header arg_count = %arg_count%; SCRIPT_NAME = %SCRIPT_NAME%; CMD = %CMD%; HOST_CONFIG_FILE = %HOST_CONFIG_FILE%
call:time_stamp
:: Arguments: none
if %arg_count% == 0 call:usage
if %CMD% == wrangle_species_list call:wrangle_species_list
call:set_defaults
call:header Defaults IMAGE_NAME, CONTAINER_NAME = %IMAGE_NAME%, %CONTAINER_NAME%
call:set_commands COMMANDS,COMMAND_COUNTER
call:header Set %COMMAND_COUNTER% elements of array: 0 and 15 are %COMMANDS[0]% and %COMMANDS[15]%
set command_path=/git/lmpy/lmpy/tools
call:time_stamp End
EXIT /B 0
:: -----------------------------------------------------------
:: Functions
:: -----------------------------------------------------------
:usage
:: Commands that are substrings of other commands will match the superstring and
:: possibly print the wrong Usage string.
echo.
echo Usage: %SCRIPT_NAME% cmd
echo or: %SCRIPT_NAME% cmd parameters_file
echo.
echo This %SCRIPT_NAME% script creates an environment for a BiotaPhy command to be run with
echo user-configured arguments in a docker container.
echo The `cmd` argument can be one of the following, without a parameter file
echo build_image
echo rebuild_data
echo cleanup
echo cleanup_most
echo cleanup_all
echo list_commands
echo list_outputs
echo list_volumes
echo or one of the following commands requiring a parameters file:
echo wrangle_occurrences
echo split_occurrence_data
echo wrangle_species_list
echo wrangle_tree
echo create_sdm
echo build_grid
echo encode_layers
echo calculate_pam_stats
echo.
exit /b 0
:: -----------------------------------------------------------
:set_defaults
set IMAGE_NAME=tutor
set CONTAINER_NAME=tutor_container
set VOLUME_MOUNT=/volumes
set IN_VOLUME=data
set ENV_VOLUME=env
set OUT_VOLUME=output
set VOLUME_SAVE_LABEL=saveme
set VOLUME_DISCARD_LABEL=discard
:: Linux forward slash path separator for container
set VOLUME_MOUNT=/volumes
set CONTAINER_CONFIG_DIR=%VOLUME_MOUNT%/%IN_VOLUME%/config
:: Windows backslash path separator
set HOST_CONFIG_DIR=%IN_VOLUME%\config
SetLocal EnableExtensions EnableDelayedExpansion
if Defined HOST_CONFIG_FILE (
if Exist %HOST_CONFIG_FILE% (
FOR %%i IN ("%HOST_CONFIG_FILE%") DO (
set filename=%%~nxi
)
echo full name is %CONTAINER_CONFIG_DIR%/%filename%
set CONTAINER_CONFIG_FILE=%CONTAINER_CONFIG_DIR%/%filename%
::CONTAINER_CONFIG_FILE=$(echo $HOST_CONFIG_FILE | sed "s:^$host_dir:$container_dir:g")
echo container file returned as %CONTAINER_CONFIG_FILE%
) else (
echo File %HOST_CONFIG_FILE% does not exist
)
) else (
echo File %HOST_CONFIG_FILE% undefined
)
:: Logfile
set LOG=%CMD%.log
if EXIST %LOG% DEL %LOG%
exit /b 0
:: -----------------------------------------------------------
:: Set 1st specified variable to a concatenated fully qualified drive\path name
:: from the 2nd and 3rd variables, with no redundant backslashes. Convert all
:: forward slashes to backslashes. Removes quotes.
::set_fqdp
::set %1=%~f2
::exit /b %_ERROR_SUCCESS_%
:: -----------------------------------------------------------
:header
ECHO =================================================
ECHO %*
ECHO =================================================
EXIT /B 0
:: -----------------------------------------------------------
:time_stamp
echo %TIME% %*
echo %TIME% %* > %LOG%
exit /b 0
:: -----------------------------------------------------------
:set_commands
:: args: COMMANDS, COMMAND_COUNTER
set %~1[0]=build_image
set %~1[1]=rebuild_data
set %~1[2]=cleanup
set %~1[3]=cleanup_most
set %~1[4]=cleanup_all
set %~1[5]=list_commands
set %~1[6]=list_outputs
set %~1[7]=list_volumes
set %~1[8]=wrangle_occurrences
set %~1[9]=split_occurrence_data
set %~1[10]=wrangle_species_list
set %~1[11]=wrangle_tree
set %~1[12]=create_sdm
set %~1[13]=build_grid
set %~1[14]=encode_layers
set %~1[15]=calculate_pam_stats
set /A %~2=15
call:time_stamp finished set_commands3
exit /b 0
:: -----------------------------------------------------------
:: recreate this linux command
:: CONTAINER_CONFIG_FILE=$(echo $HOST_CONFIG_FILE | sed "s:^$host_dir:$container_dir:g")
:: arg1 = CONTAINER_CONFIG_FILE
:convert_filename
SetLocal EnableDelayedExpansion
FOR %%i IN ("%HOST_CONFIG_FILE%") DO (
set filename=%%~nxi
echo filename is %filename%
)
echo full name is %CONTAINER_CONFIG_DIR%/%filename%
set %~1=%CONTAINER_CONFIG_DIR%/%filename%
EndLocal
exit /b 0
:: -----------------------------------------------------------
:create_volumes
# Create named RO input volumes for use by any container
# Small input data, part of repository
for /f "tokens=3 usebackq" %%i in (`docker volume ls ^| find "%IN_VOLUME%"`) do
set input_vol=%%i
::for /f "tokens=* usebackq" %%i in (`docker volume ls ^| find "%IN_VOLUME%"`) do
::set input_vol_exists!count!=%%i
::set /a count=!count!+1
)
echo input_vol is %input_vol%
exit /b 0
:: -----------------------------------------------------------
:build_image_fill_data
exit /b 0
:: -----------------------------------------------------------
:start_container
exit /b 0
:: -----------------------------------------------------------
:wrangle_species_list
exit /b 0