michael@0: @echo off michael@0: rem This Source Code Form is subject to the terms of the Mozilla Public michael@0: rem License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: rem file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: set VIRTUAL_ENV=%~dp0 michael@0: set VIRTUAL_ENV=%VIRTUAL_ENV:~0,-5% michael@0: set CUDDLEFISH_ROOT=%VIRTUAL_ENV% michael@0: michael@0: SET PYTHONKEY=SOFTWARE\Python\PythonCore michael@0: michael@0: rem look for 32-bit windows and python, or 64-bit windows and python michael@0: michael@0: SET PYTHONVERSION=2.7 michael@0: call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath michael@0: if "%PYTHONINSTALL%" NEQ "" goto FoundPython michael@0: michael@0: SET PYTHONVERSION=2.6 michael@0: call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath michael@0: if "%PYTHONINSTALL%" NEQ "" goto FoundPython michael@0: michael@0: SET PYTHONVERSION=2.5 michael@0: call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath michael@0: if "%PYTHONINSTALL%" NEQ "" goto FoundPython michael@0: michael@0: if not defined ProgramFiles(x86) goto win32 michael@0: michael@0: rem look for 32-bit python on 64-bit windows michael@0: michael@0: SET PYTHONKEY=SOFTWARE\Wow6432Node\Python\PythonCore michael@0: michael@0: SET PYTHONVERSION=2.7 michael@0: call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath michael@0: if "%PYTHONINSTALL%" NEQ "" goto FoundPython michael@0: michael@0: SET PYTHONVERSION=2.6 michael@0: call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath michael@0: if "%PYTHONINSTALL%" NEQ "" goto FoundPython michael@0: michael@0: SET PYTHONVERSION=2.5 michael@0: call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath michael@0: if "%PYTHONINSTALL%" NEQ "" goto FoundPython michael@0: michael@0: :win32 michael@0: michael@0: SET PYTHONVERSION= michael@0: set PYTHONKEY= michael@0: echo Warning: Failed to find Python installation directory michael@0: goto :EOF michael@0: michael@0: :FoundPython michael@0: michael@0: if defined _OLD_PYTHONPATH ( michael@0: set PYTHONPATH=%_OLD_PYTHONPATH% michael@0: ) michael@0: if not defined PYTHONPATH ( michael@0: set PYTHONPATH=; michael@0: ) michael@0: set _OLD_PYTHONPATH=%PYTHONPATH% michael@0: set PYTHONPATH=%VIRTUAL_ENV%\python-lib;%PYTHONPATH% michael@0: michael@0: if not defined PROMPT ( michael@0: set PROMPT=$P$G michael@0: ) michael@0: michael@0: if defined _OLD_VIRTUAL_PROMPT ( michael@0: set PROMPT=%_OLD_VIRTUAL_PROMPT% michael@0: ) michael@0: michael@0: set _OLD_VIRTUAL_PROMPT=%PROMPT% michael@0: set PROMPT=(%VIRTUAL_ENV%) %PROMPT% michael@0: michael@0: if defined _OLD_VIRTUAL_PATH goto OLDPATH michael@0: goto SKIPPATH michael@0: :OLDPATH michael@0: PATH %_OLD_VIRTUAL_PATH% michael@0: michael@0: :SKIPPATH michael@0: set _OLD_VIRTUAL_PATH=%PATH% michael@0: PATH %VIRTUAL_ENV%\bin;%PYTHONINSTALL%;%PATH% michael@0: set PYTHONKEY= michael@0: set PYTHONINSTALL= michael@0: set PYTHONVERSION= michael@0: set key= michael@0: set reg= michael@0: set _tokens= michael@0: python -c "from jetpack_sdk_env import welcome; welcome()" michael@0: GOTO :EOF michael@0: michael@0: :CheckPython michael@0: ::CheckPython(retVal, key) michael@0: ::Reads the registry at %2% and checks if a Python exists there. michael@0: ::Checks both HKLM and HKCU, then checks the executable actually exists. michael@0: SET key=%2% michael@0: SET "%~1=" michael@0: SET reg=reg michael@0: if defined ProgramFiles(x86) ( michael@0: rem 32-bit cmd on 64-bit windows michael@0: if exist %WINDIR%\sysnative\reg.exe SET reg=%WINDIR%\sysnative\reg.exe michael@0: ) michael@0: rem On Vista+, the last line of output is: michael@0: rem (default) REG_SZ the_value michael@0: rem (but note the word "default" will be localized. michael@0: rem On XP, the last line of output is: michael@0: rem \tREG_SZ\tthe_value michael@0: rem (not sure if "NO NAME" is localized or not!) michael@0: rem SO: we use ")>" as the tokens to split on, then nuke michael@0: rem the REG_SZ and any tabs or spaces. michael@0: FOR /F "usebackq tokens=2 delims=)>" %%A IN (`%reg% QUERY HKLM\%key% /ve 2^>NUL`) DO SET "%~1=%%A" michael@0: rem Remove the REG_SZ michael@0: set PYTHONINSTALL=%PYTHONINSTALL:REG_SZ=% michael@0: rem Remove tabs (note the literal \t in the next line michael@0: set PYTHONINSTALL=%PYTHONINSTALL: =% michael@0: rem Remove spaces. michael@0: set PYTHONINSTALL=%PYTHONINSTALL: =% michael@0: if exist %PYTHONINSTALL%\python.exe goto :EOF michael@0: rem It may be a 32bit Python directory built from source, in which case the michael@0: rem executable is in the PCBuild directory. michael@0: if exist %PYTHONINSTALL%\PCBuild\python.exe (set "PYTHONINSTALL=%PYTHONINSTALL%\PCBuild" & goto :EOF) michael@0: rem Or maybe a 64bit build directory. michael@0: if exist %PYTHONINSTALL%\PCBuild\amd64\python.exe (set "PYTHONINSTALL=%PYTHONINSTALL%\PCBuild\amd64" & goto :EOF) michael@0: michael@0: rem And try HKCU michael@0: FOR /F "usebackq tokens=2 delims=)>" %%A IN (`%reg% QUERY HKCU\%key% /ve 2^>NUL`) DO SET "%~1=%%A" michael@0: set PYTHONINSTALL=%PYTHONINSTALL:REG_SZ=% michael@0: set PYTHONINSTALL=%PYTHONINSTALL: =% michael@0: set PYTHONINSTALL=%PYTHONINSTALL: =% michael@0: if exist %PYTHONINSTALL%\python.exe goto :EOF michael@0: if exist %PYTHONINSTALL%\PCBuild\python.exe (set "PYTHONINSTALL=%PYTHONINSTALL%\PCBuild" & goto :EOF) michael@0: if exist %PYTHONINSTALL%\PCBuild\amd64\python.exe (set "PYTHONINSTALL=%PYTHONINSTALL%\PCBuild\amd64" & goto :EOF) michael@0: rem can't find it here, so arrange to try the next key michael@0: set PYTHONINSTALL= michael@0: michael@0: GOTO :EOF