-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path_Check_Dependencies.bat
174 lines (165 loc) · 4.45 KB
/
_Check_Dependencies.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
::=============================================================::
:: DEVELOPED 2015, REVISED 2017, Jeff Rimko. ::
::=============================================================::
::=============================================================::
:: SECTION: Environment Setup ::
::=============================================================::
@set TITLE=%~n0 "%~dp0"
@cd /d %~dp0 && echo off && title %TITLE%
::=============================================================::
:: SECTION: Main Body ::
::=============================================================::
call:ChkDep^
"Python"^
"Python language interpreter."^
"www.python.org"^
"2.7/3.x"^
python -V
call:ChkDep^
"Verace"^
"Python library for checking string consistency between files."^
"github.com/jeffrimko/Verace"^
"latest"^
python -c "import verace"
pause
exit /b 0
::=============================================================::
:: SECTION: Function Definitions ::
::=============================================================::
::-------------------------------------------------------------::
:: Checks if a dependency is available.
::
:: **Params**:
:: - 1 - Name of dependency.
:: - 2 - Description of dependency.
:: - 3 - Reference website or where to obtain info.
:: - 4 - Recommended version.
:: - 5+ - Non-blocking command to check if installed; usually version display
:: or help.
::
:: **Attention**:
:: Do not use quotes around the non-blocking command.
:: Quotes may be included in the remaining params if they are needed for the
:: non-blocking call.
::
:: **Preconditions**:
:: The global variable DEP_OK should be set to 1 before the first call to this
:: function.
::
:: **Postconditions**:
:: The global variable DEP_OK will be set to 0 if a dependency check fails.
:: This variable is not set back to 1 by this function, it may be explicitly
:: set outside the function
::
:: **Example**:
:: call::ChkDep^
:: "Utility"^
:: "Does something."^
:: "www.website.com"^
:: "1.2.3"^
:: utility -h
:: call::ChkDep^
:: "Utility"^
:: "Does something."^
:: "www.website.com"^
:: "1.2.3"^
:: utility -c "non-blocking cmd"
::-------------------------------------------------------------::
:ChkDep
echo Checking dependency %~1...
shift
echo %~1
shift
echo Reference: %~1
shift
echo Recommended version: %~1
shift
echo --------
set CMD=%1
shift
:chkdep_shift_next
if [%1] neq [] (
set CMD=%CMD% %1
shift
goto:chkdep_shift_next
)
%CMD% > NUL 2>&1
if %ERRORLEVEL% neq 0 (
echo NOT FOUND!
set DEP_OK=0
goto:eof
)
echo OK.
goto:eof
::-------------------------------------------------------------::
:: Checks if a dependency is available and is the required version.
::
:: **Params**:
:: - 1 - Name of dependency.
:: - 2 - Description of dependency.
:: - 3 - Reference website or where to obtain info.
:: - 4 - Required version.
:: - 5+ - Non-blocking command to check if installed; usually version display
:: or help.
::
:: **Attention**:
:: Do not use quotes around the non-blocking command.
:: Quotes may be included in the remaining params if they are needed for the
:: non-blocking call.
::
:: **Preconditions**:
:: The global variable DEP_OK should be set to 1 before the first call to this
:: function.
::
:: **Postconditions**:
:: The global variable DEP_OK will be set to 0 if a dependency check fails.
:: This variable is not set back to 1 by this function, it may be explicitly
:: set outside the function
::
:: **Example**:
:: call::ChkDepVer^
:: "Utility"^
:: "Does something."^
:: "www.website.com"^
:: "1.2.3"^
:: utility -h
:: call::ChkDepVer^
:: "Utility"^
:: "Does something."^
:: "www.website.com"^
:: "1.2.3"^
:: utility -c "non-blocking cmd"
::-------------------------------------------------------------::
:ChkDepVer
echo Checking dependency for %~1...
shift
echo %~1
shift
echo Reference: %~1
shift
set DEP_VER=%~1
echo Required version: %DEP_VER%
shift
echo --------
set CMD=%1
shift
:chkdepver_shift_next
if [%1] neq [] (
set CMD=%CMD% %1
shift
goto:chkdepver_shift_next
)
%CMD% > NUL 2>&1
if %ERRORLEVEL% neq 0 (
echo NOT FOUND!
set DEP_OK=0
goto:eof
)
%CMD% 2>&1 | find "%DEP_VER%" >NUL
if %ERRORLEVEL% neq 0 (
echo NOT FOUND!
set DEP_OK=0
goto:eof
)
echo OK.
goto:eof