distutils should use new winreg module on NT

This patch changes msvccompiler.py so that the new winreg module is used if available. Otherwise, win32reg and win32con is used. *** msvccompiler.py Fri Mar 31 18:01:20 2000 --- msvccompiler.new.py Fri Mar 31 17:55:02 2000 *************** *** 16,21 **** --- 16,47 ---- from distutils.ccompiler import \ CCompiler, gen_preprocess_options, gen_lib_options + try: + import winreg + _HKEY_CLASSES_ROOT = winreg.HKEY_CLASSES_ROOT + _HKEY_LOCAL_MACHINE = winreg.HKEY_LOCAL_MACHINE + _HKEY_CURRENT_USER = winreg.HKEY_CURRENT_USER + _HKEY_USERS = winreg.HKEY_USERS + _RegOpenKeyEx = winreg.OpenKeyEx + _RegEnumKey = winreg.EnumKey + _RegEnumValue = winreg.EnumValue + _RegError = winreg.error + _can_read_reg = 1 + except ImportError: + try: + import win32api + import win32con + _HKEY_CLASSES_ROOT = win32con.HKEY_CLASSES_ROOT + _HKEY_LOCAL_MACHINE = win32con.HKEY_LOCAL_MACHINE + _HKEY_CURRENT_USER = win32con.HKEY_CURRENT_USER + _HKEY_USERS = win32con.HKEY_USERS + _RegOpenKeyEx = win32api.RegOpenKeyEx + _RegEnumKey = win32api.RegEnumKey + _RegEnumValue = win32api.RegEnumValue + _RegError = win32api.error + _can_read_reg = 1 + except ImportError: + _can_read_reg = 0 def get_devstudio_versions (): """Get list of devstudio versions from the Windows registry. Return a *************** *** 24,53 **** a registry-access module) or the appropriate registry keys weren't found.""" ! try: ! import win32api ! import win32con ! except ImportError: return [] K = 'Software\\Microsoft\\Devstudio' L = [] ! for base in (win32con.HKEY_CLASSES_ROOT, ! win32con.HKEY_LOCAL_MACHINE, ! win32con.HKEY_CURRENT_USER, ! win32con.HKEY_USERS): try: ! k = win32api.RegOpenKeyEx(base,K) i = 0 while 1: try: ! p = win32api.RegEnumKey(k,i) if p[0] in '123456789' and p not in L: L.append(p) ! except win32api.error: break i = i + 1 ! except win32api.error: pass L.sort() L.reverse() --- 50,76 ---- a registry-access module) or the appropriate registry keys weren't found.""" ! if not _can_read_reg: return [] K = 'Software\\Microsoft\\Devstudio' L = [] ! for base in (_HKEY_CLASSES_ROOT, ! _HKEY_LOCAL_MACHINE, ! _HKEY_CURRENT_USER, ! _HKEY_USERS): try: ! k = _RegOpenKeyEx(base,K) i = 0 while 1: try: ! p = _RegEnumKey(k,i) if p[0] in '123456789' and p not in L: L.append(p) ! except _RegError: break i = i + 1 ! except _RegError: pass L.sort() L.reverse() *************** *** 61,70 **** a list of strings; will be empty list if unable to access the registry or appropriate registry keys not found.""" ! try: ! import win32api ! import win32con ! except ImportError: return [] L = [] --- 84,90 ---- a list of strings; will be empty list if unable to access the registry or appropriate registry keys not found.""" ! if not _can_read_reg: return [] L = [] *************** *** 74,89 **** K = ('Software\\Microsoft\\Devstudio\\%s\\' + 'Build System\\Components\\Platforms\\Win32 (%s)\\Directories') % \ (version,platform) ! for base in (win32con.HKEY_CLASSES_ROOT, ! win32con.HKEY_LOCAL_MACHINE, ! win32con.HKEY_CURRENT_USER, ! win32con.HKEY_USERS): try: ! k = win32api.RegOpenKeyEx(base,K) i = 0 while 1: try: ! (p,v,t) = win32api.RegEnumValue(k,i) if string.upper(p) == path: V = string.split(v,';') for v in V: --- 94,109 ---- K = ('Software\\Microsoft\\Devstudio\\%s\\' + 'Build System\\Components\\Platforms\\Win32 (%s)\\Directories') % \ (version,platform) ! for base in (_HKEY_CLASSES_ROOT, ! _HKEY_LOCAL_MACHINE, ! _HKEY_CURRENT_USER, ! _HKEY_USERS): try: ! k = _RegOpenKeyEx(base,K) i = 0 while 1: try: ! (p,v,t) = _RegEnumValue(k,i) if string.upper(p) == path: V = string.split(v,';') for v in V: *************** *** 91,99 **** L.append(v) break i = i + 1 ! except win32api.error: break ! except win32api.error: pass return L --- 111,119 ---- L.append(v) break i = i + 1 ! except _RegError: break ! except _RegError: pass return L Disclaimer: I confirm that, to the best of my knowledge and belief, this contribution is free of any claims of third parties under copyright, patent or other rights or interests ("claims"). To the extent that I have any such claims, I hereby grant to CNRI a nonexclusive, irrevocable, royalty-free, worldwide license to reproduce, distribute, perform and/or display publicly, prepare derivative versions, and otherwise use this contribution as part of the Python software and its related documentation, or any derivative versions thereof, at no cost to CNRI or its licensed users, and to authorize others to do so. I acknowledge that CNRI may, at its sole discretion, decide whether or not to incorporate this contribution in the Python software and its related documentation. I further grant CNRI permission to use my name and other identifying information provided to CNRI by me for use in connection with the Python software and its related documentation. Thomas Heller
participants (1)
-
Thomas Heller