Chromium Code Reviews| Index: pylib/gyp/MSVSVersion.py |
| diff --git a/pylib/gyp/MSVSVersion.py b/pylib/gyp/MSVSVersion.py |
| index 1d836b1ec3ed6e65e71926f8320f3cc5434a48a0..22d9327ca2f9c2b93c12815651346a55dff0541e 100644 |
| --- a/pylib/gyp/MSVSVersion.py |
| +++ b/pylib/gyp/MSVSVersion.py |
| @@ -165,8 +165,28 @@ def _RegistryQuery(key, value=None): |
| return text |
| +def _RegistryGetValueUsingWinReg(key, value): |
| + """Use the _winreg module to obtain the value of a registry key. |
| + |
| + Args: |
| + key: The registry key. |
| + value: The particular registry value to read. |
| + Return: |
| + contents of the registry key's value, or None for failure. Throws |
| + ImportError if _winreg is unavailable. |
| + """ |
| + import _winreg |
| + try: |
| + root,subkey = key.split('\\', 1) |
|
scottmg
2014/11/13 18:05:35
nit; space after ,
|
| + assert('HKLM' == root) # Only need HKLM for now |
|
scottmg
2014/11/13 18:05:35
nits;
- no ()
- root == 'HKLM', rather than yoda-s
|
| + with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey) as hkey: |
| + return _winreg.QueryValueEx(hkey, value)[0] |
| + except WindowsError: |
| + return None |
| + |
| + |
| def _RegistryGetValue(key, value): |
| - """Use reg.exe to obtain the value of a registry key. |
| + """Use _winreg or reg.exe to obtain the value of a registry key. |
|
scottmg
2014/11/13 18:05:35
add a comment explaining why we need to try both w
|
| Args: |
| key: The registry key. |
| @@ -174,6 +194,12 @@ def _RegistryGetValue(key, value): |
| Return: |
| contents of the registry key's value, or None on failure. |
| """ |
| + try: |
| + return _RegistryGetValueUsingWinReg(key, value) |
| + except ImportError: |
| + pass |
| + |
| + # Fallback to reg.exe if we fail to import _winreg. |
| text = _RegistryQuery(key, value) |
| if not text: |
| return None |
| @@ -184,19 +210,6 @@ def _RegistryGetValue(key, value): |
| return match.group(1) |
| -def _RegistryKeyExists(key): |
| - """Use reg.exe to see if a key exists. |
| - |
| - Args: |
| - key: The registry key to check. |
| - Return: |
| - True if the key exists |
| - """ |
| - if not _RegistryQuery(key): |
| - return False |
| - return True |
| - |
| - |
| def _CreateVersion(name, path, sdk_based=False): |
| """Sets up MSVS project generation. |