[issue1455] VS2008, quick hack for distutils.msvccompiler
Martin v. Löwis added the comment: This issue is closed, and didn't really deal with VS 2005 at all, so we should avoid tracking any further changes in it. I personally don't care about the PCbuild8 folder at all. It can be removed, updated, replaced with that script - whatever people like most. You might want to ask Kristjan Jonsson (who created it originally) about its fate. __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1455] VS2008, quick hack for distutils.msvccompiler
zouguangxian added the comment: I succeed in building python26 with msvc 2005. I create a tool to convert pcbuild9 to pcbuild8. 1. delete pcbuild8 2. copy pcbuild9 to pcbuild8 3. run norm.py in pcbuild8, norm.py will change the format flag. Added file: http://bugs.python.org/file8994/norm.py __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __# -*- coding: UTF-8 -*- # vim: noexpandtab:nolist:sw=4 ts=4 sts=4: # $Id$ import os import sys import re top = '.' for root, dirs, files in os.walk(top): for name in files: path, ext = os.path.splitext( name ) if not ( ext and ext.lower() in ['.vcproj', '.sln'] ): continue filename = os.path.normpath( os.path.join( root, name ) ) print filename fin = open( filename, 'r' ) lines = fin.read() lines = re.sub( r'Version=9,00', r'Version=8.00', lines) lines = re.sub( r'Format Version 10.00', r'Format Version 9.00', lines) lines = re.sub( r'Visual Studio 2008', r'Visual Studio 2005', lines) fin.close() fout = open( filename, 'w' ) fout.write(lines) fout.close() break ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1455] VS2008, quick hack for distutils.msvccompiler
Amaury Forgeot d'Arc added the comment: I already do the same: pcbuild9 is easy to convert to vs2005, and the project is much better than the current pcbuild8. What do the others think? Should we update pcbuild8 with the content of pcbuild9, with the few changes proposed by weck? Or simply remove pcbuild8 and propose vs2005 users to run the attached script? -- nosy: +amaury.forgeotdarc __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1455] VS2008, quick hack for distutils.msvccompiler
Christian Heimes added the comment: I've applied the patch to the trunk in r59290 together with a fix for the cygwin compiler. distutils now support VS 2005 and VS 2008 (both tested) and cygwin (only tested for msvcr80). -- resolution: accepted - fixed status: open - closed __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1455] VS2008, quick hack for distutils.msvccompiler
Christian Heimes added the comment: I've created another patch to add VS 2008 support to distutils. The new patch requires you to copy the msvccompiler.py first: $ cd Lib/distutils $ svn copy msvccompiler.py msvc9compiler.py $ cd ../.. $ patch -p0 py3k_vs2008_4.patch Martin, if you are going to build Python 3.0a2 with VS 2008 then this patch should be applied. I've tested it with VS 2008 and it *may* be compatible with VS 2005, too. -- priority: normal - high Added file: http://bugs.python.org/file8813/py3k_vs2008_4.patch __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __Index: Lib/distutils/command/build_ext.py === --- Lib/distutils/command/build_ext.py (revision 59193) +++ Lib/distutils/command/build_ext.py (working copy) @@ -14,6 +14,10 @@ from distutils.extension import Extension from distutils import log +if os.name == 'nt': +from distutils.msvccompiler import get_build_version +MSVC_VERSION = int(get_build_version()) + # An extension name is just a dot-separated list of Python NAMEs (ie. # the same as a fully-qualified module name). extension_name_re = re.compile \ @@ -172,7 +176,12 @@ # Append the source distribution include and library directories, # this allows distutils on windows to work in the source tree self.include_dirs.append(os.path.join(sys.exec_prefix, 'PC')) -self.library_dirs.append(os.path.join(sys.exec_prefix, 'PCBuild')) +if MSVC_VERSION == 9: +self.library_dirs.append(os.path.join(sys.exec_prefix, 'PCBuild9')) +elif MSVC_VERSION == 8: +self.library_dirs.append(os.path.join(sys.exec_prefix, 'PCBuild8')) +else: +self.library_dirs.append(os.path.join(sys.exec_prefix, 'PCBuild')) # OS/2 (EMX) doesn't support Debug vs Release builds, but has the # import libraries in its Config subdirectory Index: Lib/distutils/msvc9compiler.py === --- Lib/distutils/msvc9compiler.py (revision 59193) +++ Lib/distutils/msvc9compiler.py (working copy) @@ -1,145 +1,154 @@ -distutils.msvccompiler +distutils.msvc9compiler Contains MSVCCompiler, an implementation of the abstract CCompiler class -for the Microsoft Visual Studio. +for the Microsoft Visual Studio 2008. + +The module is compatible with VS 2008. The module may also be compatible +with VS 2005 but it is untested yet. You can find legacy support for older +versions of VS in distutils.msvccompiler. # Written by Perry Stoll # hacked by Robin Becker and Thomas Heller to do a better job of # finding DevStudio (through the registry) +# ported to VS 2008 by Christian Heimes __revision__ = $Id$ -import sys, os -from distutils.errors import \ - DistutilsExecError, DistutilsPlatformError, \ - CompileError, LibError, LinkError -from distutils.ccompiler import \ - CCompiler, gen_preprocess_options, gen_lib_options +import os +import subprocess +import sys +from distutils.errors import (DistutilsExecError, DistutilsPlatformError, +CompileError, LibError, LinkError) +from distutils.ccompiler import (CCompiler, gen_preprocess_options, +gen_lib_options) from distutils import log -_can_read_reg = False -try: -import _winreg +import _winreg -_can_read_reg = True -hkey_mod = _winreg +RegOpenKeyEx = _winreg.OpenKeyEx +RegEnumKey = _winreg.EnumKey +RegEnumValue = _winreg.EnumValue +RegError = _winreg.error -RegOpenKeyEx = _winreg.OpenKeyEx -RegEnumKey = _winreg.EnumKey -RegEnumValue = _winreg.EnumValue -RegError = _winreg.error +HKEYS = (_winreg.HKEY_USERS, + _winreg.HKEY_CURRENT_USER, + _winreg.HKEY_LOCAL_MACHINE, + _winreg.HKEY_CLASSES_ROOT) -except ImportError: -try: -import win32api -import win32con -_can_read_reg = True -hkey_mod = win32con +VS_BASE = rSoftware\Microsoft\VisualStudio\%0.1f +WINSDK_BASE = rSoftware\Microsoft\Microsoft SDKs\Windows +NET_BASE = rSoftware\Microsoft\.NETFramework +ARCHS = {'DEFAULT' : 'x86', +'intel' : 'x86', 'x86' : 'x86', +'amd64' : 'x64', 'x64' : 'x64', +'itanium' : 'ia64', 'ia64' : 'ia64', +} -RegOpenKeyEx = win32api.RegOpenKeyEx -RegEnumKey = win32api.RegEnumKey -RegEnumValue = win32api.RegEnumValue -RegError = win32api.error -except ImportError: -log.info(Warning: Can't read registry to find the - necessary compiler setting\n - Make sure that Python modules _winreg, - win32api or win32con are installed.) -pass +# The globals VERSION, ARCH, MACROS and VC_ENV are defined later -if _can_read_reg: -HKEYS = (hkey_mod.HKEY_USERS, - hkey_mod.HKEY_CURRENT_USER, -
[issue1455] VS2008, quick hack for distutils.msvccompiler
zouguangxian added the comment: Why don't use Visual Studio 200x Command Prompt to get a shell window with correct environment settings? In this way msvccompiler.py can get LIB, INCLUDE, LIBPATH, PATH with os.environ.get. -- nosy: +weck __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1455] VS2008, quick hack for distutils.msvccompiler
Martin v. Löwis added the comment: It's tedious to require users to invoke such a shell, and it would produce an endless flood of support requests if we made that a requirement. So requiring to build in such a shell is absolutely unacceptable. __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1455] VS2008, quick hack for distutils.msvccompiler
Christian Heimes added the comment: Updated compiler and linker args from the project command lines. Added file: http://bugs.python.org/file8781/py3k_vs2008_3.patch __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __Index: Lib/distutils/msvccompiler.py === --- Lib/distutils/msvccompiler.py (revision 59043) +++ Lib/distutils/msvccompiler.py (working copy) @@ -1,145 +1,152 @@ -distutils.msvccompiler +distutils.msvc9compiler Contains MSVCCompiler, an implementation of the abstract CCompiler class -for the Microsoft Visual Studio. +for the Microsoft Visual Studio 2008. # Written by Perry Stoll # hacked by Robin Becker and Thomas Heller to do a better job of # finding DevStudio (through the registry) +# ported to VS 2008 by Christian Heimes __revision__ = $Id$ -import sys, os -from distutils.errors import \ - DistutilsExecError, DistutilsPlatformError, \ - CompileError, LibError, LinkError -from distutils.ccompiler import \ - CCompiler, gen_preprocess_options, gen_lib_options +import os +import subprocess +import sys +from distutils.errors import (DistutilsExecError, DistutilsPlatformError, +CompileError, LibError, LinkError) +from distutils.ccompiler import (CCompiler, gen_preprocess_options, +gen_lib_options) from distutils import log -_can_read_reg = False -try: -import _winreg +import _winreg -_can_read_reg = True -hkey_mod = _winreg +RegOpenKeyEx = _winreg.OpenKeyEx +RegEnumKey = _winreg.EnumKey +RegEnumValue = _winreg.EnumValue +RegError = _winreg.error -RegOpenKeyEx = _winreg.OpenKeyEx -RegEnumKey = _winreg.EnumKey -RegEnumValue = _winreg.EnumValue -RegError = _winreg.error +HKEYS = (_winreg.HKEY_USERS, + _winreg.HKEY_CURRENT_USER, + _winreg.HKEY_LOCAL_MACHINE, + _winreg.HKEY_CLASSES_ROOT) -except ImportError: -try: -import win32api -import win32con -_can_read_reg = True -hkey_mod = win32con +VS_BASE = rSoftware\Microsoft\VisualStudio\%0.1f +WINSDK_BASE = rSoftware\Microsoft\Microsoft SDKs\Windows +NET_BASE = rSoftware\Microsoft\.NETFramework +ARCHS = {'DEFAULT' : 'x86', +'intel' : 'x86', 'x86' : 'x86', +'amd64' : 'x64', 'x64' : 'x64', +'itanium' : 'ia64', 'ia64' : 'ia64', +} -RegOpenKeyEx = win32api.RegOpenKeyEx -RegEnumKey = win32api.RegEnumKey -RegEnumValue = win32api.RegEnumValue -RegError = win32api.error -except ImportError: -log.info(Warning: Can't read registry to find the - necessary compiler setting\n - Make sure that Python modules _winreg, - win32api or win32con are installed.) -pass +class Reg: +Helper class to read values from the registry + -if _can_read_reg: -HKEYS = (hkey_mod.HKEY_USERS, - hkey_mod.HKEY_CURRENT_USER, - hkey_mod.HKEY_LOCAL_MACHINE, - hkey_mod.HKEY_CLASSES_ROOT) - -def read_keys(base, key): -Return list of registry keys. -try: -handle = RegOpenKeyEx(base, key) -except RegError: -return None -L = [] -i = 0 -while True: +@classmethod +def get_value(cls, path, key): +for base in HKEYS: +d = cls.read_values(base, path) +if d and key in d: +return d[key] +raise KeyError(key) + +@classmethod +def read_keys(cls, base, key): +Return list of registry keys. try: -k = RegEnumKey(handle, i) +handle = RegOpenKeyEx(base, key) except RegError: -break -L.append(k) -i += 1 -return L +return None +L = [] +i = 0 +while True: +try: +k = RegEnumKey(handle, i) +except RegError: +break +L.append(k) +i += 1 +return L -def read_values(base, key): -Return dict of registry keys and values. - -All names are converted to lowercase. - -try: -handle = RegOpenKeyEx(base, key) -except RegError: -return None -d = {} -i = 0 -while True: +@classmethod +def read_values(cls, base, key): +Return dict of registry keys and values. + +All names are converted to lowercase. + try: -name, value, type = RegEnumValue(handle, i) +handle = RegOpenKeyEx(base, key) except RegError: -break -name = name.lower() -d[convert_mbcs(name)] = convert_mbcs(value) -i += 1 -return d +return None +d = {} +i = 0 +while True: +try: +name, value, type = RegEnumValue(handle, i) +except RegError: +break +name =
[issue1455] VS2008, quick hack for distutils.msvccompiler
Changes by Mark Hammond: -- nosy: +mhammond __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1455] VS2008, quick hack for distutils.msvccompiler
New submission from Christian Heimes: I've come up with a quick hack to support VS 2008. VS 2008 Standard Edition doesn't store the include and lib dirs in the registry any more. However I came up with a nice way to get the env settings from the vcvarsall.bat. How do you like it? Do we need support for VS6 and VS7.1 or can I remove the code from the module? -- assignee: loewis components: Distutils files: py3k_vs2008_hack.patch keywords: patch, py3k messages: 57599 nosy: loewis, tiran priority: normal severity: normal status: open title: VS2008, quick hack for distutils.msvccompiler type: rfe versions: Python 3.0 Added file: http://bugs.python.org/file8766/py3k_vs2008_hack.patch __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __Index: Lib/distutils/msvccompiler.py === --- Lib/distutils/msvccompiler.py (revision 59036) +++ Lib/distutils/msvccompiler.py (working copy) @@ -7,15 +7,17 @@ # Written by Perry Stoll # hacked by Robin Becker and Thomas Heller to do a better job of # finding DevStudio (through the registry) +# ported to VS 2008 by Christian Heimes __revision__ = $Id$ -import sys, os -from distutils.errors import \ - DistutilsExecError, DistutilsPlatformError, \ - CompileError, LibError, LinkError -from distutils.ccompiler import \ - CCompiler, gen_preprocess_options, gen_lib_options +import os +import subprocess +import sys +from distutils.errors import (DistutilsExecError, DistutilsPlatformError, +CompileError, LibError, LinkError) +from distutils.ccompiler import (CCompiler, gen_preprocess_options, +gen_lib_options) from distutils import log _can_read_reg = False @@ -102,44 +104,57 @@ return s class MacroExpander: +_vsbase = rSoftware\Microsoft\VisualStudio\%0.1f +winsdkbase = rSoftware\Microsoft\Microsoft SDKs\Windows +netframework = rSoftware\Microsoft\.NETFramework + def __init__(self, version): self.macros = {} +self.vsbase = self._vsbase % version self.load_macros(version) def set_macro(self, macro, path, key): for base in HKEYS: d = read_values(base, path) -if d: +if d and key in d: self.macros[$(%s) % macro] = d[key] -break +return +raise KeyError(key) def load_macros(self, version): -vsbase = rSoftware\Microsoft\VisualStudio\%0.1f % version -self.set_macro(VCInstallDir, vsbase + r\Setup\VC, productdir) -self.set_macro(VSInstallDir, vsbase + r\Setup\VS, productdir) -net = rSoftware\Microsoft\.NETFramework -self.set_macro(FrameworkDir, net, installroot) +self.set_macro(VCInstallDir, self.vsbase + r\Setup\VC, productdir) +self.set_macro(VSInstallDir, self.vsbase + r\Setup\VS, productdir) +self.set_macro(FrameworkDir, self.netframework, installroot) try: -if version 7.0: -self.set_macro(FrameworkSDKDir, net, sdkinstallrootv1.1) +if version = 9.0: +self.set_macro(FrameworkSDKDir, self.netframework, + sdkinstallrootv2.0) +elif version 7.0: +self.set_macro(FrameworkSDKDir, self.netframework, + sdkinstallrootv1.1) else: -self.set_macro(FrameworkSDKDir, net, sdkinstallroot) +self.set_macro(FrameworkSDKDir, self.netframework, + sdkinstallroot) except KeyError as exc: # raise DistutilsPlatformError( -Python was built with Visual Studio 2003; +Python was built with Visual Studio 2008; extensions must be built with a compiler than can generate compatible binaries. -Visual Studio 2003 was not found on this system. If you have Cygwin installed, +Visual Studio 2008 was not found on this system. If you have Cygwin installed, you can try compiling with MingW32, by passing -c mingw32 to setup.py.) -p = rSoftware\Microsoft\NET Framework Setup\Product -for base in HKEYS: -try: -h = RegOpenKeyEx(base, p) -except RegError: -continue -key = RegEnumKey(h, 0) -d = read_values(base, r%s\%s % (p, key)) -self.macros[$(FrameworkVersion)] = d[version] +if version = 0.9: +self.set_macro(FrameworkVersion, self.vsbase, clr version) +self.set_macro(WindowsSdkDir, self.winsdkbase, currentinstallfolder) +else: +p = rSoftware\Microsoft\NET Framework Setup\Product +for base in HKEYS: +try: +h = RegOpenKeyEx(base, p) +except RegError: +continue +key = RegEnumKey(h, 0) +
[issue1455] VS2008, quick hack for distutils.msvccompiler
Martin v. Löwis added the comment: There is always the debate whether distutils might be repackaged and backported to older Python releases, therefore people hesitate to remove support for older versions. As for finding it in the registry: are you sure it has no registry settings anymore? I find that hard to believe. __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1455] VS2008, quick hack for distutils.msvccompiler
Martin v. Löwis added the comment: As another note: you shouldn't remove support code for Itanium. Even though no Itanium binaries will be produced at the releases, I see no reason to rip the code out - people with Itanium machines should still be able to build Python, with some effort. __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1455] VS2008, quick hack for distutils.msvccompiler
Christian Heimes added the comment: Neither VS8 Professional nor VS9 Beta 2 Standard are storing the lib and include directories in the registry. I've searched in HKCU and HKLM. The best I could find was the path to a XML file in My Documents that contains the information. __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1455] VS2008, quick hack for distutils.msvccompiler
Martin v. Löwis added the comment: Ok. Running vsvars is fine, then. The change to get_build_architecture is broken in another way: as it parses the architecture out of sys.version, you still get Intel, not x86 (unless you also change PC/pyconfig.h - which may break code that relies on the specific format of sys.version) Otherwise, the patch looks fine. __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1455] VS2008, quick hack for distutils.msvccompiler
Changes by Martin v. Löwis: -- resolution: - accepted __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1455] VS2008, quick hack for distutils.msvccompiler
Christian Heimes added the comment: Ok, I'll take it from here. I'm going to wait until it's decided to use VS 2008 as the new default compiler. -- assignee: loewis - tiran __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1455] VS2008, quick hack for distutils.msvccompiler
Christian Heimes added the comment: UPDATES: * Cleanup and rewrite of the registry related code * Moved search code to find_vcvarsall(). * Added fallback using the VS90COMNTOOL env var for Express edition Added file: http://bugs.python.org/file8768/py3k_vs2008_2.patch __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1455 __Index: Lib/distutils/msvccompiler.py === --- Lib/distutils/msvccompiler.py (revision 59036) +++ Lib/distutils/msvccompiler.py (working copy) @@ -1,145 +1,152 @@ -distutils.msvccompiler +distutils.msvc9compiler Contains MSVCCompiler, an implementation of the abstract CCompiler class -for the Microsoft Visual Studio. +for the Microsoft Visual Studio 2008. # Written by Perry Stoll # hacked by Robin Becker and Thomas Heller to do a better job of # finding DevStudio (through the registry) +# ported to VS 2008 by Christian Heimes __revision__ = $Id$ -import sys, os -from distutils.errors import \ - DistutilsExecError, DistutilsPlatformError, \ - CompileError, LibError, LinkError -from distutils.ccompiler import \ - CCompiler, gen_preprocess_options, gen_lib_options +import os +import subprocess +import sys +from distutils.errors import (DistutilsExecError, DistutilsPlatformError, +CompileError, LibError, LinkError) +from distutils.ccompiler import (CCompiler, gen_preprocess_options, +gen_lib_options) from distutils import log -_can_read_reg = False -try: -import _winreg +import _winreg -_can_read_reg = True -hkey_mod = _winreg +RegOpenKeyEx = _winreg.OpenKeyEx +RegEnumKey = _winreg.EnumKey +RegEnumValue = _winreg.EnumValue +RegError = _winreg.error -RegOpenKeyEx = _winreg.OpenKeyEx -RegEnumKey = _winreg.EnumKey -RegEnumValue = _winreg.EnumValue -RegError = _winreg.error +HKEYS = (_winreg.HKEY_USERS, + _winreg.HKEY_CURRENT_USER, + _winreg.HKEY_LOCAL_MACHINE, + _winreg.HKEY_CLASSES_ROOT) -except ImportError: -try: -import win32api -import win32con -_can_read_reg = True -hkey_mod = win32con +VS_BASE = rSoftware\Microsoft\VisualStudio\%0.1f +WINSDK_BASE = rSoftware\Microsoft\Microsoft SDKs\Windows +NET_BASE = rSoftware\Microsoft\.NETFramework +ARCHS = {'DEFAULT' : 'x86', +'intel' : 'x86', 'x86' : 'x86', +'amd64' : 'x64', 'x64' : 'x64', +'itanium' : 'ia64', 'ia64' : 'ia64', +} -RegOpenKeyEx = win32api.RegOpenKeyEx -RegEnumKey = win32api.RegEnumKey -RegEnumValue = win32api.RegEnumValue -RegError = win32api.error -except ImportError: -log.info(Warning: Can't read registry to find the - necessary compiler setting\n - Make sure that Python modules _winreg, - win32api or win32con are installed.) -pass +class Reg: +Helper class to read values from the registry + -if _can_read_reg: -HKEYS = (hkey_mod.HKEY_USERS, - hkey_mod.HKEY_CURRENT_USER, - hkey_mod.HKEY_LOCAL_MACHINE, - hkey_mod.HKEY_CLASSES_ROOT) - -def read_keys(base, key): -Return list of registry keys. -try: -handle = RegOpenKeyEx(base, key) -except RegError: -return None -L = [] -i = 0 -while True: +@classmethod +def get_value(cls, path, key): +for base in HKEYS: +d = cls.read_values(base, path) +if d and key in d: +return d[key] +raise KeyError(key) + +@classmethod +def read_keys(cls, base, key): +Return list of registry keys. try: -k = RegEnumKey(handle, i) +handle = RegOpenKeyEx(base, key) except RegError: -break -L.append(k) -i += 1 -return L +return None +L = [] +i = 0 +while True: +try: +k = RegEnumKey(handle, i) +except RegError: +break +L.append(k) +i += 1 +return L -def read_values(base, key): -Return dict of registry keys and values. - -All names are converted to lowercase. - -try: -handle = RegOpenKeyEx(base, key) -except RegError: -return None -d = {} -i = 0 -while True: +@classmethod +def read_values(cls, base, key): +Return dict of registry keys and values. + +All names are converted to lowercase. + try: -name, value, type = RegEnumValue(handle, i) +handle = RegOpenKeyEx(base, key) except RegError: -break -name = name.lower() -d[convert_mbcs(name)] = convert_mbcs(value) -i += 1 -return d +return None +d = {} +i = 0 +while True: +try: +name, value,