activate.bat 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. @echo off
  2. rem This Source Code Form is subject to the terms of the Mozilla Public
  3. rem License, v. 2.0. If a copy of the MPL was not distributed with this
  4. rem file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. set VIRTUAL_ENV=%~dp0
  6. set VIRTUAL_ENV=%VIRTUAL_ENV:~0,-5%
  7. set CUDDLEFISH_ROOT=%VIRTUAL_ENV%
  8. SET PYTHONKEY=SOFTWARE\Python\PythonCore
  9. rem look for 32-bit windows and python, or 64-bit windows and python
  10. SET PYTHONVERSION=2.7
  11. call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath
  12. if "%PYTHONINSTALL%" NEQ "" goto FoundPython
  13. SET PYTHONVERSION=2.6
  14. call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath
  15. if "%PYTHONINSTALL%" NEQ "" goto FoundPython
  16. SET PYTHONVERSION=2.5
  17. call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath
  18. if "%PYTHONINSTALL%" NEQ "" goto FoundPython
  19. if not defined ProgramFiles(x86) goto win32
  20. rem look for 32-bit python on 64-bit windows
  21. SET PYTHONKEY=SOFTWARE\Wow6432Node\Python\PythonCore
  22. SET PYTHONVERSION=2.7
  23. call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath
  24. if "%PYTHONINSTALL%" NEQ "" goto FoundPython
  25. SET PYTHONVERSION=2.6
  26. call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath
  27. if "%PYTHONINSTALL%" NEQ "" goto FoundPython
  28. SET PYTHONVERSION=2.5
  29. call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath
  30. if "%PYTHONINSTALL%" NEQ "" goto FoundPython
  31. :win32
  32. SET PYTHONVERSION=
  33. set PYTHONKEY=
  34. echo Warning: Failed to find Python installation directory
  35. goto :EOF
  36. :FoundPython
  37. if defined _OLD_PYTHONPATH (
  38. set PYTHONPATH=%_OLD_PYTHONPATH%
  39. )
  40. if not defined PYTHONPATH (
  41. set PYTHONPATH=;
  42. )
  43. set _OLD_PYTHONPATH=%PYTHONPATH%
  44. set PYTHONPATH=%VIRTUAL_ENV%\python-lib;%PYTHONPATH%
  45. if not defined PROMPT (
  46. set PROMPT=$P$G
  47. )
  48. if defined _OLD_VIRTUAL_PROMPT (
  49. set PROMPT=%_OLD_VIRTUAL_PROMPT%
  50. )
  51. set _OLD_VIRTUAL_PROMPT=%PROMPT%
  52. set PROMPT=(%VIRTUAL_ENV%) %PROMPT%
  53. if defined _OLD_VIRTUAL_PATH goto OLDPATH
  54. goto SKIPPATH
  55. :OLDPATH
  56. PATH %_OLD_VIRTUAL_PATH%
  57. :SKIPPATH
  58. set _OLD_VIRTUAL_PATH=%PATH%
  59. PATH %VIRTUAL_ENV%\bin;%PYTHONINSTALL%;%PATH%
  60. set PYTHONKEY=
  61. set PYTHONINSTALL=
  62. set PYTHONVERSION=
  63. set key=
  64. set reg=
  65. set _tokens=
  66. python -c "from jetpack_sdk_env import welcome; welcome()"
  67. GOTO :EOF
  68. :CheckPython
  69. ::CheckPython(retVal, key)
  70. ::Reads the registry at %2% and checks if a Python exists there.
  71. ::Checks both HKLM and HKCU, then checks the executable actually exists.
  72. SET key=%2%
  73. SET "%~1="
  74. SET reg=reg
  75. if defined ProgramFiles(x86) (
  76. rem 32-bit cmd on 64-bit windows
  77. if exist %WINDIR%\sysnative\reg.exe SET reg=%WINDIR%\sysnative\reg.exe
  78. )
  79. rem On Vista+, the last line of output is:
  80. rem (default) REG_SZ the_value
  81. rem (but note the word "default" will be localized.
  82. rem On XP, the last line of output is:
  83. rem <NO NAME>\tREG_SZ\tthe_value
  84. rem (not sure if "NO NAME" is localized or not!)
  85. rem SO: we use ")>" as the tokens to split on, then nuke
  86. rem the REG_SZ and any tabs or spaces.
  87. FOR /F "usebackq tokens=2 delims=)>" %%A IN (`%reg% QUERY HKLM\%key% /ve 2^>NUL`) DO SET "%~1=%%A"
  88. rem Remove the REG_SZ
  89. set PYTHONINSTALL=%PYTHONINSTALL:REG_SZ=%
  90. rem Remove tabs (note the literal \t in the next line
  91. set PYTHONINSTALL=%PYTHONINSTALL: =%
  92. rem Remove spaces.
  93. set PYTHONINSTALL=%PYTHONINSTALL: =%
  94. if exist %PYTHONINSTALL%\python.exe goto :EOF
  95. rem It may be a 32bit Python directory built from source, in which case the
  96. rem executable is in the PCBuild directory.
  97. if exist %PYTHONINSTALL%\PCBuild\python.exe (set "PYTHONINSTALL=%PYTHONINSTALL%\PCBuild" & goto :EOF)
  98. rem Or maybe a 64bit build directory.
  99. if exist %PYTHONINSTALL%\PCBuild\amd64\python.exe (set "PYTHONINSTALL=%PYTHONINSTALL%\PCBuild\amd64" & goto :EOF)
  100. rem And try HKCU
  101. FOR /F "usebackq tokens=2 delims=)>" %%A IN (`%reg% QUERY HKCU\%key% /ve 2^>NUL`) DO SET "%~1=%%A"
  102. set PYTHONINSTALL=%PYTHONINSTALL:REG_SZ=%
  103. set PYTHONINSTALL=%PYTHONINSTALL: =%
  104. set PYTHONINSTALL=%PYTHONINSTALL: =%
  105. if exist %PYTHONINSTALL%\python.exe goto :EOF
  106. if exist %PYTHONINSTALL%\PCBuild\python.exe (set "PYTHONINSTALL=%PYTHONINSTALL%\PCBuild" & goto :EOF)
  107. if exist %PYTHONINSTALL%\PCBuild\amd64\python.exe (set "PYTHONINSTALL=%PYTHONINSTALL%\PCBuild\amd64" & goto :EOF)
  108. rem can't find it here, so arrange to try the next key
  109. set PYTHONINSTALL=
  110. GOTO :EOF