Odd COM problems with VC

Roger Burnham roger.burnham at gte.net
Wed Mar 8 16:43:00 EST 2000


On Wed, 08 Mar 2000 20:22:37 GMT, jim_kerr at my-deja.com wrote:

>  I'm trying to use Python's COM facilities to
>control a build in Visual C++.
>I've run into some problems that don't make sense
>to me at all (not surprising,
>since I don't know COM).

Jim,

I have a script to automate building all my projects:
----------------------------------------------------------

import sys
import win32ui
import win32com
from win32com.client import gencache
import string

# for example...
projects = {
    'C:\DevSrc\Python\Python-1.5.2b2\PCbuild\pcbuild.dsw':
    ('python15', 'python', 'pythonw'),

    'C:\DevSrc\Python\Python-1.5.1\Exts\Python and Extensions.dsw':
    ('win32ui', 'win32api', 'timer', 'pythonwin',),

}

def DoBuild(app, workSpace, projectList, configSuffix):
    if app is None:
        app = win32com.client.Dispatch('MSDev.Application')
        app.Visible = 1
        
    docs = app.Documents
    docs.CloseAll

    print 'Open workspace', workSpace
    docs.Open(workSpace, 'Auto', 1)
    tailLen = len(configSuffix)

    for projectName in projectList:
        print '   looking for', projectName, '...',
        projects = app.Projects
        for project in projects:
            projFound = 0
            if str(project.Name) == projectName:
                projFound = 1
                print
                print '   looking for config', configSuffix, '...',
                for config in project.Configurations:
                    confFound = 0
                    name = str(config.Name)
                    if name[-tailLen:] == configSuffix:
                        confFound = 1
                        print
                        print '   Building', name, '...'
                        app.ReBuildAll(config)
                        if app.Errors > 0:
                            win32ui.MessageBox('Error building %s' % name)
                            raise SystemExit
                        break
                if not confFound:
                    print '-- NOT Found'
                break
        if not projFound:
            print '-- NOT Found'
    
def main(config='Release'):
    mod = gencache.GetModuleForProgID('MSDev.Application')
    if mod is None:
        win32ui.MessageBox('''Could not import MSDev.Application:
        You probably need to run the COM makepy utility to
        regenerate the VC++ Shared Objects (6.0) interface''')
        raise ImportError
    app = win32com.client.Dispatch('MSDev.Application')
    app.Visible = 1
    projectList = projects.keys()
    projectList.sort()
    for workSpaceID in projectList:
        num, workSpace = string.split(workSpaceID)
        DoBuild(app, workSpace, projects[workSpaceID], config)

if __name__ == '__main__':
    import sys
    if len(sys.argv) < 2:
        config = 'Release'
    else:
        config = sys.argv[1]
    main(config)

----------------------------------------------------------


Cheers,
Roger Burnham   
Cambridge Research & Instrumentation   
rburnham at cri-inc.com   
http://www.cri-inc.com/   
http://starship.python.net/crew/roger/   
PGP Key: http://www.nai.com/default_pgp.asp   
PGP Fingerprint: 5372 729A 9557 5F36 177F  084A 6C64 BE27 0BC4 CF2D   



More information about the Python-list mailing list