##// END OF EJS Templates
win32: move lookupreg() to windows.py...
Adrian Buehlmann -
r16807:80142f38 default
parent child Browse files
Show More
@@ -5,8 +5,7 b''
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 import encoding
9 import ctypes, errno, os, subprocess, random, _winreg
8 import ctypes, errno, os, subprocess, random
10 9
11 10 _kernel32 = ctypes.windll.kernel32
12 11 _advapi32 = ctypes.windll.advapi32
@@ -244,27 +243,6 b' def testpid(pid):'
244 243 _kernel32.CloseHandle(h)
245 244 return _kernel32.GetLastError() != _ERROR_INVALID_PARAMETER
246 245
247 def lookupreg(key, valname=None, scope=None):
248 ''' Look up a key/value name in the Windows registry.
249
250 valname: value name. If unspecified, the default value for the key
251 is used.
252 scope: optionally specify scope for registry lookup, this can be
253 a sequence of scopes to look up in order. Default (CURRENT_USER,
254 LOCAL_MACHINE).
255 '''
256 if scope is None:
257 scope = (_winreg.HKEY_CURRENT_USER, _winreg.HKEY_LOCAL_MACHINE)
258 elif not isinstance(scope, (list, tuple)):
259 scope = (scope,)
260 for s in scope:
261 try:
262 val = _winreg.QueryValueEx(_winreg.OpenKey(s, key), valname)[0]
263 # never let a Unicode string escape into the wild
264 return encoding.tolocal(val.encode('UTF-8'))
265 except EnvironmentError:
266 pass
267
268 246 def executablepath():
269 247 '''return full path of hg.exe'''
270 248 size = 600
@@ -6,14 +6,13 b''
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from i18n import _
9 import osutil
10 import errno, msvcrt, os, re, sys
9 import osutil, encoding
10 import errno, msvcrt, os, re, sys, _winreg
11 11
12 12 import win32
13 13 executablepath = win32.executablepath
14 14 getuser = win32.getuser
15 15 hidewindow = win32.hidewindow
16 lookupreg = win32.lookupreg
17 16 makedir = win32.makedir
18 17 nlinks = win32.nlinks
19 18 oslink = win32.oslink
@@ -316,4 +315,25 b' class cachestat(object):'
316 315 def cacheable(self):
317 316 return False
318 317
318 def lookupreg(key, valname=None, scope=None):
319 ''' Look up a key/value name in the Windows registry.
320
321 valname: value name. If unspecified, the default value for the key
322 is used.
323 scope: optionally specify scope for registry lookup, this can be
324 a sequence of scopes to look up in order. Default (CURRENT_USER,
325 LOCAL_MACHINE).
326 '''
327 if scope is None:
328 scope = (_winreg.HKEY_CURRENT_USER, _winreg.HKEY_LOCAL_MACHINE)
329 elif not isinstance(scope, (list, tuple)):
330 scope = (scope,)
331 for s in scope:
332 try:
333 val = _winreg.QueryValueEx(_winreg.OpenKey(s, key), valname)[0]
334 # never let a Unicode string escape into the wild
335 return encoding.tolocal(val.encode('UTF-8'))
336 except EnvironmentError:
337 pass
338
319 339 expandglobs = True
General Comments 0
You need to be logged in to leave comments. Login now