[Distutils] WinNT and distutils

Robin Becker robin@jessikat.demon.co.uk
Fri, 28 Jan 2000 12:58:53 +0000


In article <Pine.LNX.4.10.10001280132550.13880-100000@nebula.lyra.org>, Greg Stein <gstein@lyra.org> writes
>On 28 Jan 2000, Michael Hudson wrote:
>>...
>> How hard are registry files to parse? They're just text aren't they?
>> (not on windows, can't tell). Would a simple parser written in Python
>> be even vaguely possible?
>
>Registry files are binary files. You're thinking of a .reg file which can
>be passed to regsvr32. .reg files have syntax similar to .ini files.
>
>In short: no, you cannot parse them. You must have access to the Win32
>registry functions.
>
>There has been discussion about putting them into Python 1.6.
>
>Cheers,
>-g
>


I offer this as a way to go if win32 is installed.

import string
def msvc_get_paths(path, vNum='6.0', platform='x86'):
        "Get a devstudio path (include, library or bin)"
        try:
                import win32api
                import win32con
        except ImportError:
                return None

        L = []
        if path=='bin': path = 'Path'
        path = string.upper(path + ' Dirs')
        for base in (win32con.HKEY_CLASSES_ROOT,win32con.HKEY_LOCAL_MACHINE,
                     win32con.HKEY_CURRENT_USER,win32con.HKEY_USERS):
                try:
                        k = 'Software\\Microsoft\\Devstudio\\%s\\Build System\\Components\\Platforms\\Win32
(%s)\\Directories' \
                                % (vNum,platform)
                        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:
                                                        if v=='' or v in L: continue
                                                        L.append(v)
                                                break
                                        i = i + 1
                                except win32api.error:
                                        break
                except win32api.error:
                        pass
        return L
-- 
Robin Becker