Mercurial > hg
changeset 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 | 3c33032d8906 |
children | 090b1a665901 |
files | mercurial/filemerge.py mercurial/util.py mercurial/util_win32.py |
diffstat | 3 files changed, 41 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/filemerge.py Sun Feb 03 19:29:05 2008 -0600 +++ b/mercurial/filemerge.py Sun Feb 03 19:29:05 2008 -0600 @@ -16,6 +16,13 @@ return ui.configbool("merge-tools", tool + "." + part, default) def _findtool(ui, tool): + k = _toolstr(ui, tool, "regkey") + if k: + p = util.lookup_reg(k, _toolstr(ui, tool, "regname")) + if p: + p = util.find_exe(p + _toolstr(ui, tool, "regappend")) + if p: + return p return util.find_exe(_toolstr(ui, tool, "executable", tool)) def _picktool(repo, ui, path, binary, symlink):
--- a/mercurial/util.py Sun Feb 03 19:29:05 2008 -0600 +++ b/mercurial/util.py Sun Feb 03 19:29:05 2008 -0600 @@ -1086,6 +1086,9 @@ else: nulldev = '/dev/null' + def lookup_reg(key, name=None, scope=None): + return None + def rcfiles(path): rcs = [os.path.join(path, 'hgrc')] rcdir = os.path.join(path, 'hgrc.d')
--- a/mercurial/util_win32.py Sun Feb 03 19:29:05 2008 -0600 +++ b/mercurial/util_win32.py Sun Feb 03 19:29:05 2008 -0600 @@ -187,6 +187,37 @@ return details[0] != winerror.ERROR_INVALID_PARAMETER return True +def lookup_reg(key, valname=None, scope=None): + ''' Look up a key/value name in the Windows registry. + + valname: value name. If unspecified, the default value for the key + is used. + scope: optionally specify scope for registry lookup, this can be + a sequence of scopes to look up in order. Default (CURRENT_USER, + LOCAL_MACHINE). + ''' + try: + from _winreg import HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, \ + QueryValueEx, OpenKey + except ImportError: + return None + + def query_val(scope, key): + try: + keyhandle = OpenKey(scope, key) + return QueryValueEx(keyhandle, valname)[0] + except EnvironmentError: + return None + + if scope is None: + scope = (HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE) + elif not isinstance(scope, (list, tuple)): + scope = (scope,) + for s in scope: + val = query_val(s, key, valname) + if val is not None: + return val + def system_rcpath_win32(): '''return default os-specific hgrc search path''' proc = win32api.GetCurrentProcess()