diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-11-17 20:55:28 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-11-17 20:55:28 +0000 |
commit | 2fe77ca953e916966a28e4cf3895565a464cc8fd (patch) | |
tree | 18a50e432b4fe343bc0d223ccd02d3011859e1c0 /lib/thandy/util.py | |
parent | e5ec1b2ce20f7578fea683229aadc95431fdb451 (diff) |
Add win32 registry support to thandy. untested.
git-svn-id: file:///home/or/svnrepo/updater/trunk@17319 55e972cd-5a19-0410-ae62-a4d7a52db4cd
Diffstat (limited to 'lib/thandy/util.py')
-rw-r--r-- | lib/thandy/util.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/thandy/util.py b/lib/thandy/util.py index f2bac17..0c0aa9d 100644 --- a/lib/thandy/util.py +++ b/lib/thandy/util.py @@ -109,3 +109,23 @@ def randChooseWeighted(lst): return lst[-1][1] +def getRegistryValue(keyname): + """Read the contents of a Windows registry key from a given base.""" + + hkey, rest = keyname.split("\\", 1) + key, value = rest.rsplit("\\", 1) + if not hkey.startswith("HKEY_"): + return None + + base = getattr(_winreg, hkey) + settings = None + + try: + try: + settings = _winreg.OpenKey(base, key) + return _winreg.QueryValueEx(settings, value)[0] + except (WindowsError, ValueError, TypeError): + return None + finally: + if settings is not None: + settings.close() |