Mercurial > public > mercurial-scm > hg
comparison mercurial/util_win32.py @ 6006:3c9dbb743d20
merge: add registry look up bits to tool search
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 03 Feb 2008 19:29:05 -0600 |
parents | 821fc5c0656c |
children | e45de0f47215 |
comparison
equal
deleted
inserted
replaced
6005:3c33032d8906 | 6006:3c9dbb743d20 |
---|---|
185 return status == win32con.STILL_ACTIVE | 185 return status == win32con.STILL_ACTIVE |
186 except pywintypes.error, details: | 186 except pywintypes.error, details: |
187 return details[0] != winerror.ERROR_INVALID_PARAMETER | 187 return details[0] != winerror.ERROR_INVALID_PARAMETER |
188 return True | 188 return True |
189 | 189 |
190 def lookup_reg(key, valname=None, scope=None): | |
191 ''' Look up a key/value name in the Windows registry. | |
192 | |
193 valname: value name. If unspecified, the default value for the key | |
194 is used. | |
195 scope: optionally specify scope for registry lookup, this can be | |
196 a sequence of scopes to look up in order. Default (CURRENT_USER, | |
197 LOCAL_MACHINE). | |
198 ''' | |
199 try: | |
200 from _winreg import HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, \ | |
201 QueryValueEx, OpenKey | |
202 except ImportError: | |
203 return None | |
204 | |
205 def query_val(scope, key): | |
206 try: | |
207 keyhandle = OpenKey(scope, key) | |
208 return QueryValueEx(keyhandle, valname)[0] | |
209 except EnvironmentError: | |
210 return None | |
211 | |
212 if scope is None: | |
213 scope = (HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE) | |
214 elif not isinstance(scope, (list, tuple)): | |
215 scope = (scope,) | |
216 for s in scope: | |
217 val = query_val(s, key, valname) | |
218 if val is not None: | |
219 return val | |
220 | |
190 def system_rcpath_win32(): | 221 def system_rcpath_win32(): |
191 '''return default os-specific hgrc search path''' | 222 '''return default os-specific hgrc search path''' |
192 proc = win32api.GetCurrentProcess() | 223 proc = win32api.GetCurrentProcess() |
193 try: | 224 try: |
194 # This will fail on windows < NT | 225 # This will fail on windows < NT |