Skip to content

Commit 5864aad

Browse files
committed
Add python.nsh
1 parent 02073c2 commit 5864aad

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

windows/python.nsh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* python.nsh
3+
*
4+
* Configure Python
5+
*/
6+
7+
!include StrFunc.nsh
8+
;${StrRep}
9+
10+
; On Windows NT-derived operating systems, Python.org installer for Python 2.4
11+
; can be installed for all users or current user only.
12+
; define the following symbol to install if Python is installed only for current user.
13+
; !define INSTALL_IF_PYTHON_FOR_CURRENT_USER
14+
15+
!define STRING_PYTHON_NOT_FOUND "Python is not installed on this system. $\nPlease install Python first. $\n$\nClick OK to cancel installation and remove installation Files."
16+
17+
!define STRING_PYTHON_CURRENT_USER_FOUND "Python is installed for the current user only. $\n$\nOpenBazaar does not support use with Python so configured. $\n$\nClick OK to cancel installation and remove installation Files."
18+
19+
var PythonRoot
20+
var PythonExecutable
21+
var StrNoUsablePythonFound
22+
23+
Function ValidatePythonVersion
24+
ClearErrors
25+
MessageBox MB_OK "$PythonExecutable Here"
26+
nsExec::ExecToStack '"$PythonExecutable" "-c" "import sys; ver=sys.version_info[:2]; exit({True:0,False:1}[ver<(2,7) or ver>(2,7)])"'
27+
FunctionEnd
28+
29+
; This must be a macro because the registry root key cannot be a variable
30+
!macro EnumeratePython id hk_root hk
31+
loop${id}:
32+
EnumRegKey $1 HKLM "SOFTWARE\Python" $0
33+
DetailPrint $1
34+
StrCmp $1 "" done${id}
35+
IntOp $0 $0 + 1
36+
ReadRegStr $7 ${hk_root} "${hk}\$1\InstallPath" ""
37+
StrCpy $PythonExecutable "$7\python.exe"
38+
Call ValidatePythonVersion
39+
Pop $7
40+
StrCmp $7 0 ok loop${id}
41+
done${id}:
42+
StrCpy $PythonExecutable ""
43+
!macroend
44+
45+
Function CheckForPython_new
46+
!insertmacro EnumeratePython 1 HKLM Software\Python\PythonCore
47+
!insertmacro EnumeratePython 2 HKLM Wow6432Node\Software\Python\PythonCore
48+
!insertmacro EnumeratePython 3 HKCU Software\Python\PythonCore
49+
!insertmacro EnumeratePython 4 HKCU Wow6432Node\Software\Python\PythonCore
50+
51+
ok:
52+
MessageBox MB_OK "Found Python executable at '$PythonExecutable'"
53+
Push $PythonExecutable
54+
${GetParent} $PythonExecutable $PythonRoot
55+
56+
FunctionEnd

0 commit comments

Comments
 (0)