|
1 | 1 | @IF NOT DEFINED DEBUG_HELPER @ECHO OFF |
| 2 | +echo Looking for Python 2.x |
2 | 3 | SETLOCAL |
3 | 4 | :: If python.exe is in %Path%, just validate |
4 | 5 | FOR /F "delims=" %%a IN ('where python 2^> NUL') DO ( |
@@ -14,18 +15,18 @@ FOR %%K IN ( "HKCU\Software", "HKLM\SOFTWARE", "HKLM\Software\Wow6432Node") DO ( |
14 | 15 | :: If validate returns 0 just jump to the end |
15 | 16 | IF NOT ERRORLEVEL 1 GOTO :validate |
16 | 17 | ) |
17 | | -EXIT /B 1 |
| 18 | +goto :no-python |
18 | 19 |
|
19 | 20 | :: Helper subroutine to handle quotes in %1 |
20 | 21 | :find-main-branch |
21 | 22 | SET main_key="%~1\Python\PythonCore" |
22 | | -REG QUERY %main_key% /s | findstr "2." | findstr InstallPath > NUL 2> NUL |
| 23 | +REG QUERY %main_key% /s 2> NUL | findstr "2." | findstr InstallPath > NUL 2> NUL |
23 | 24 | IF NOT ERRORLEVEL 1 CALL :find-key %main_key% |
24 | 25 | EXIT /B |
25 | 26 |
|
26 | 27 | :: Query registry sub-tree for InstallPath |
27 | 28 | :find-key |
28 | | -FOR /F "delims=" %%a IN ('REG QUERY %1 /s ^| findstr "2." ^| findstr InstallPath') DO IF NOT ERRORLEVEL 1 CALL :find-path %%a |
| 29 | +FOR /F "delims=" %%a IN ('REG QUERY %1 /s 2> NUL ^| findstr "2." ^| findstr InstallPath') DO IF NOT ERRORLEVEL 1 CALL :find-path %%a |
29 | 30 | EXIT /B |
30 | 31 |
|
31 | 32 | :: Parse the value of %1 as the path for python.exe |
@@ -39,13 +40,20 @@ EXIT /B 1 |
39 | 40 |
|
40 | 41 | :: Check if %p% holds a path to a real python2 executable |
41 | 42 | :validate |
42 | | -IF NOT EXIST "%p%python.exe" EXIT /B 1 |
| 43 | +IF NOT EXIST "%p%python.exe" goto :no-python |
43 | 44 | :: Check if %p% is python2 |
44 | 45 | "%p%python.exe" -V 2>&1 | findstr /R "^Python.2.*" > NUL |
45 | | -IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL% |
| 46 | +IF ERRORLEVEL 1 goto :no-python2 |
46 | 47 | :: We can wrap it up |
47 | 48 | ENDLOCAL & SET pt=%p%& SET need_path_ext=%need_path% |
48 | 49 | SET VCBUILD_PYTHON_LOCATION=%pt%python.exe |
49 | 50 | IF %need_path_ext%==1 SET Path=%Path%;%pt% |
50 | 51 | SET need_path_ext= |
51 | | -EXIT /B %ERRORLEVEL% |
| 52 | +EXIT /B %ERRORLEVEL% |
| 53 | + |
| 54 | +:no-python2 |
| 55 | +echo Python found in %p%, but it is not v2.x. |
| 56 | +exit /B 1 |
| 57 | +:no-python |
| 58 | +echo Could not find Python. |
| 59 | +exit /B 1 |