Show More
@@ -5,8 +5,7 b'' | |||||
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | import encoding |
|
8 | import ctypes, errno, os, subprocess, random | |
9 | import ctypes, errno, os, subprocess, random, _winreg |
|
|||
10 |
|
9 | |||
11 | _kernel32 = ctypes.windll.kernel32 |
|
10 | _kernel32 = ctypes.windll.kernel32 | |
12 | _advapi32 = ctypes.windll.advapi32 |
|
11 | _advapi32 = ctypes.windll.advapi32 | |
@@ -244,27 +243,6 b' def testpid(pid):' | |||||
244 | _kernel32.CloseHandle(h) |
|
243 | _kernel32.CloseHandle(h) | |
245 | return _kernel32.GetLastError() != _ERROR_INVALID_PARAMETER |
|
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 | def executablepath(): |
|
246 | def executablepath(): | |
269 | '''return full path of hg.exe''' |
|
247 | '''return full path of hg.exe''' | |
270 | size = 600 |
|
248 | size = 600 |
@@ -6,14 +6,13 b'' | |||||
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from i18n import _ |
|
8 | from i18n import _ | |
9 | import osutil |
|
9 | import osutil, encoding | |
10 | import errno, msvcrt, os, re, sys |
|
10 | import errno, msvcrt, os, re, sys, _winreg | |
11 |
|
11 | |||
12 | import win32 |
|
12 | import win32 | |
13 | executablepath = win32.executablepath |
|
13 | executablepath = win32.executablepath | |
14 | getuser = win32.getuser |
|
14 | getuser = win32.getuser | |
15 | hidewindow = win32.hidewindow |
|
15 | hidewindow = win32.hidewindow | |
16 | lookupreg = win32.lookupreg |
|
|||
17 | makedir = win32.makedir |
|
16 | makedir = win32.makedir | |
18 | nlinks = win32.nlinks |
|
17 | nlinks = win32.nlinks | |
19 | oslink = win32.oslink |
|
18 | oslink = win32.oslink | |
@@ -316,4 +315,25 b' class cachestat(object):' | |||||
316 | def cacheable(self): |
|
315 | def cacheable(self): | |
317 | return False |
|
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 | expandglobs = True |
|
339 | expandglobs = True |
General Comments 0
You need to be logged in to leave comments.
Login now