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