Commit 4732c1eb authored by J. Goutin's avatar J. Goutin Committed by GitHub

Fix #707 MSVC patch and Python 2

#707
Fix Python 2 Compatibility, and improve registry lookup (Key may not always be in 64bit registry node).
parent 6a4e5446
...@@ -356,23 +356,12 @@ class RegistryInfo: ...@@ -356,23 +356,12 @@ class RegistryInfo:
def __init__(self, platform_info): def __init__(self, platform_info):
self.pi = platform_info self.pi = platform_info
@property
def microsoft(self):
"""
Microsoft software registry key.
"""
return os.path.join(
'Software',
'' if self.pi.current_is_x86() else 'Wow6432Node',
'Microsoft',
)
@property @property
def visualstudio(self): def visualstudio(self):
""" """
Microsoft Visual Studio root registry key. Microsoft Visual Studio root registry key.
""" """
return os.path.join(self.microsoft, 'VisualStudio') return 'VisualStudio'
@property @property
def sxs(self): def sxs(self):
...@@ -400,15 +389,14 @@ class RegistryInfo: ...@@ -400,15 +389,14 @@ class RegistryInfo:
""" """
Microsoft Visual C++ for Python registry key. Microsoft Visual C++ for Python registry key.
""" """
path = r'DevDiv\VCForPython' return r'DevDiv\VCForPython'
return os.path.join(self.microsoft, path)
@property @property
def microsoft_sdk(self): def microsoft_sdk(self):
""" """
Microsoft SDK registry key. Microsoft SDK registry key.
""" """
return os.path.join(self.microsoft, 'Microsoft SDKs') return 'Microsoft SDKs'
@property @property
def windows_sdk(self): def windows_sdk(self):
...@@ -429,11 +417,29 @@ class RegistryInfo: ...@@ -429,11 +417,29 @@ class RegistryInfo:
""" """
Microsoft Windows Kits Roots registry key. Microsoft Windows Kits Roots registry key.
""" """
return os.path.join(self.microsoft, r'Windows Kits\Installed Roots') return r'Windows Kits\Installed Roots'
def microsoft(self, key, x86=False):
"""
Return key in Microsoft software registry.
Parameters
----------
key: str
Registry key path where look.
x86: str
Force x86 software registry.
Return
------
str: value
"""
node64 = '' if self.pi.current_is_x86() or x86 else r'\Wow6432Node'
return os.path.join('Software', node64, 'Microsoft', key)
def lookup(self, key, name): def lookup(self, key, name):
""" """
Look for values in registry. Look for values in registry in Microsoft software registry.
Parameters Parameters
---------- ----------
...@@ -446,18 +452,23 @@ class RegistryInfo: ...@@ -446,18 +452,23 @@ class RegistryInfo:
------ ------
str: value str: value
""" """
KEY_READ = winreg.KEY_READ
openkey = winreg.OpenKey
ms = self.microsoft
for hkey in self.HKEYS: for hkey in self.HKEYS:
try: try:
bkey = winreg.OpenKey(hkey, key, 0, winreg.KEY_READ) bkey = openkey(hkey, ms(key), 0, KEY_READ)
except OSError: except (OSError, IOError):
continue if not self.pi.current_is_x86():
except IOError: try:
continue bkey = openkey(hkey, ms(key, True), 0, KEY_READ)
except (OSError, IOError):
continue
else:
continue
try: try:
return winreg.QueryValueEx(bkey, name)[0] return winreg.QueryValueEx(bkey, name)[0]
except OSError: except (OSError, IOError):
pass
except IOError:
pass pass
...@@ -500,7 +511,7 @@ class SystemInfo: ...@@ -500,7 +511,7 @@ class SystemInfo:
for key in vckeys: for key in vckeys:
try: try:
bkey = winreg.OpenKey(hkey, key, 0, winreg.KEY_READ) bkey = winreg.OpenKey(hkey, key, 0, winreg.KEY_READ)
except IOError: except (OSError, IOError):
continue continue
subkeys, values, _ = winreg.QueryInfoKey(bkey) subkeys, values, _ = winreg.QueryInfoKey(bkey)
for i in range(values): for i in range(values):
...@@ -813,7 +824,7 @@ class EnvironmentInfo: ...@@ -813,7 +824,7 @@ class EnvironmentInfo:
Microsoft Visual C++ & Microsoft Foundation Class Includes Microsoft Visual C++ & Microsoft Foundation Class Includes
""" """
return [os.path.join(self.si.VCInstallDir, 'Include'), return [os.path.join(self.si.VCInstallDir, 'Include'),
os.path.join(self.si.VCInstallDir, 'ATLMFC\Include')] os.path.join(self.si.VCInstallDir, r'ATLMFC\Include')]
@property @property
def VCLibraries(self): def VCLibraries(self):
...@@ -1199,5 +1210,5 @@ class EnvironmentInfo: ...@@ -1199,5 +1210,5 @@ class EnvironmentInfo:
if name: if name:
return '%s\\' % name[0] return '%s\\' % name[0]
return '' return ''
except IOError: except (OSError, IOError):
return '' return ''
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment