|
| 1 | +::=============================================================:: |
| 2 | +:: DEVELOPED 2013, REVISED 2013, Jeff Rimko. :: |
| 3 | +::=============================================================:: |
| 4 | + |
| 5 | +::=============================================================:: |
| 6 | +:: SECTION: Environment Setup :: |
| 7 | +::=============================================================:: |
| 8 | + |
| 9 | +@set TITLE=%~n0 "%~dp0" |
| 10 | +@cd /d %~dp0 && echo off && title %TITLE% |
| 11 | + |
| 12 | +::=============================================================:: |
| 13 | +:: SECTION: Main Body :: |
| 14 | +::=============================================================:: |
| 15 | + |
| 16 | +:: Check for Python. |
| 17 | +call:ChkDepVer^ |
| 18 | + "Python"^ |
| 19 | + "Python language interpreter."^ |
| 20 | + "www.python.org"^ |
| 21 | + "2.7"^ |
| 22 | + python -V |
| 23 | + |
| 24 | +pause |
| 25 | +exit /b 0 |
| 26 | + |
| 27 | +::=============================================================:: |
| 28 | +:: SECTION: Function Definitions :: |
| 29 | +::=============================================================:: |
| 30 | + |
| 31 | +::-------------------------------------------------------------:: |
| 32 | +:: Checks if a dependency is available. |
| 33 | +:: |
| 34 | +:: **Params**: |
| 35 | +:: - 1 - Name of dependency. |
| 36 | +:: - 2 - Description of dependency. |
| 37 | +:: - 3 - Reference website or where to obtain info. |
| 38 | +:: - 4 - Recommended version. |
| 39 | +:: - 5+ - Non-blocking command to check if installed; usually version display |
| 40 | +:: or help. |
| 41 | +:: |
| 42 | +:: **Attention**: |
| 43 | +:: Do not use quotes around the non-blocking command. |
| 44 | +:: Quotes may be included in the remaining params if they are needed for the |
| 45 | +:: non-blocking call. |
| 46 | +:: |
| 47 | +:: **Preconditions**: |
| 48 | +:: The global variable DEP_OK should be set to 1 before the first call to this |
| 49 | +:: function. |
| 50 | +:: |
| 51 | +:: **Postconditions**: |
| 52 | +:: The global variable DEP_OK will be set to 0 if a dependency check fails. |
| 53 | +:: This variable is not set back to 1 by this function, it may be explicitly |
| 54 | +:: set outside the function |
| 55 | +:: |
| 56 | +:: **Example**: |
| 57 | +:: call::ChkDep^ |
| 58 | +:: "Utility"^ |
| 59 | +:: "Does something."^ |
| 60 | +:: "www.website.com"^ |
| 61 | +:: "1.2.3"^ |
| 62 | +:: utility -h |
| 63 | +:: call::ChkDep^ |
| 64 | +:: "Utility"^ |
| 65 | +:: "Does something."^ |
| 66 | +:: "www.website.com"^ |
| 67 | +:: "1.2.3"^ |
| 68 | +:: utility -c "non-blocking cmd" |
| 69 | +::-------------------------------------------------------------:: |
| 70 | +:ChkDep |
| 71 | +echo Checking dependency for %~1... |
| 72 | +shift |
| 73 | +echo %~1 |
| 74 | +shift |
| 75 | +echo Reference: %~1 |
| 76 | +shift |
| 77 | +echo Recommended version: %~1 |
| 78 | +shift |
| 79 | +echo -------- |
| 80 | +set CMD=%1 |
| 81 | +shift |
| 82 | +:chkdep_shift_next |
| 83 | +if [%1] neq [] ( |
| 84 | + set CMD=%CMD% %1 |
| 85 | + shift |
| 86 | + goto:chkdep_shift_next |
| 87 | +) |
| 88 | +%CMD% > NUL 2>&1 |
| 89 | +if %ERRORLEVEL% neq 0 ( |
| 90 | + echo NOT FOUND! |
| 91 | + set DEP_OK=0 |
| 92 | + goto:eof |
| 93 | +) |
| 94 | +echo OK. |
| 95 | +goto:eof |
| 96 | + |
| 97 | +::-------------------------------------------------------------:: |
| 98 | +:: Checks if a dependency is available and is the required version. |
| 99 | +:: |
| 100 | +:: **Params**: |
| 101 | +:: - 1 - Name of dependency. |
| 102 | +:: - 2 - Description of dependency. |
| 103 | +:: - 3 - Reference website or where to obtain info. |
| 104 | +:: - 4 - Required version. |
| 105 | +:: - 5+ - Non-blocking command to check if installed; usually version display |
| 106 | +:: or help. |
| 107 | +:: |
| 108 | +:: **Attention**: |
| 109 | +:: Do not use quotes around the non-blocking command. |
| 110 | +:: Quotes may be included in the remaining params if they are needed for the |
| 111 | +:: non-blocking call. |
| 112 | +:: |
| 113 | +:: **Preconditions**: |
| 114 | +:: The global variable DEP_OK should be set to 1 before the first call to this |
| 115 | +:: function. |
| 116 | +:: |
| 117 | +:: **Postconditions**: |
| 118 | +:: The global variable DEP_OK will be set to 0 if a dependency check fails. |
| 119 | +:: This variable is not set back to 1 by this function, it may be explicitly |
| 120 | +:: set outside the function |
| 121 | +:: |
| 122 | +:: **Example**: |
| 123 | +:: call::ChkDepVer^ |
| 124 | +:: "Utility"^ |
| 125 | +:: "Does something."^ |
| 126 | +:: "www.website.com"^ |
| 127 | +:: "1.2.3"^ |
| 128 | +:: utility -h |
| 129 | +:: call::ChkDepVer^ |
| 130 | +:: "Utility"^ |
| 131 | +:: "Does something."^ |
| 132 | +:: "www.website.com"^ |
| 133 | +:: "1.2.3"^ |
| 134 | +:: utility -c "non-blocking cmd" |
| 135 | +::-------------------------------------------------------------:: |
| 136 | +:ChkDepVer |
| 137 | +echo Checking dependency for %~1... |
| 138 | +shift |
| 139 | +echo %~1 |
| 140 | +shift |
| 141 | +echo Reference: %~1 |
| 142 | +shift |
| 143 | +set DEP_VER=%~1 |
| 144 | +echo Required version: %DEP_VER% |
| 145 | +shift |
| 146 | +echo -------- |
| 147 | +set CMD=%1 |
| 148 | +shift |
| 149 | +:chkdepver_shift_next |
| 150 | +if [%1] neq [] ( |
| 151 | + set CMD=%CMD% %1 |
| 152 | + shift |
| 153 | + goto:chkdepver_shift_next |
| 154 | +) |
| 155 | +%CMD% > NUL 2>&1 |
| 156 | +if %ERRORLEVEL% neq 0 ( |
| 157 | + echo NOT FOUND! |
| 158 | + set DEP_OK=0 |
| 159 | + goto:eof |
| 160 | +) |
| 161 | +%CMD% 2>&1 | find "%DEP_VER%" >NUL |
| 162 | +if %ERRORLEVEL% neq 0 ( |
| 163 | + echo NOT FOUND! |
| 164 | + set DEP_OK=0 |
| 165 | + goto:eof |
| 166 | +) |
| 167 | +echo OK. |
| 168 | +goto:eof |
0 commit comments