[help] Driving Visual Studio From Python
Roger Burnham
rburnham at cri-inc.com
Fri Dec 14 10:35:12 EST 2001
Michael,
This might get you started:
---------------------file MakeVCProjs.py---------------------
import sys
import win32ui
import win32com
from win32com.client import gencache
import string
projects = {
r'00 C:\DevSrc\Python\Cri\CRILicenseDLL\CRILicenseDLL.dsw':
('CRILicenseDLL',),
r'01 C:\DevSrc\CRI\ColorEditToolRes\ColorEditToolRes.dsw':
('ColorEditToolRes',),
r'03 C:\DevSrc\CRI\FPAssistantRes\FPAssistantRes.dsw':
('FPAssistantRes',),
r'04 C:\DevSrc\CRI\LCCalibRes\LCCalibRes.dsw':
('LCCalibRes',),
r'04 C:\DevSrc\CRI\LCDiodeCalibRes\LCDiodeCalibRes.dsw':
('LCDiodeCalibRes',),
#...many elided...
}
def DoBuild(app, workSpace, projectList, configSuffix, force):
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
if force:
print ' Forcing build ', name, '...'
app.ReBuildAll(config)
else:
print ' Updating build ', name, '...'
app.Build(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', force=0):
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, force)
if __name__ == '__main__':
import sys
config = 'Release'
force = 0
for arg in sys.argv[1:]:
if arg in ('Release', 'Debug'):
config = arg
if arg in ('Force',):
force = 1
main(config, force)
---------------------file MakeVCProjs.py---------------------
On Tue, 27 Nov 2001 01:29:36 -0500, Michael Schneider
<Michael.L.Schneider at eds.com> wrote:
>This is a multi-part message in MIME format.
>--------------4A98C5CDD83E4669F72F9746
>Content-Type: text/plain; charset=us-ascii
>Content-Transfer-Encoding: 7bit
>
>Hello All,
>
>I am an old unix developer finally moving to Windows Visual C++. I have
>been using python on Unix since 96,
>and have been really happy with python as a scripting/tools language.
>
>I need to drive visual studio to create projects, add configurations,
>and add files to projects.
>
>The COM extensions make it look like it is possible to do this, but I
>am having trouble getting
>it going.
>
>I have ran makepy and added the visual studio type libs.
>
>I copied the following code from a post
>
>-----------------------------------------
>import win32com.client
>app = win32com.client.Dispatch( 'MSDev.Application')
>
>wnd = app.ActiveWindow
>if wnd.Type == 'Text':
> print wnd.Selection
>app = None
>------------------------------------------
>
>This prints on the selected test.
>
>I can't seem to get the syntax to obtain and print out project
>properties, or to add a project
>
>
>Could someone help my out by giving me the python code to try to get
>this to go, I am missing something
>very basic here.
>
>Thanks
>Mike
>
>PS. I added the MSDEV links to the visual studio docs
>++++++++++++++++++
>DeveStudio Link to add project
>
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcug98/html/vcrefaddprojectmethod.asp
>
>Link to Visual Studio Application Object
>
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcug98/html/_asug_application_object.asp
>
>--------------4A98C5CDD83E4669F72F9746
>Content-Type: text/x-vcard; charset=us-ascii;
> name="Michael.L.Schneider.vcf"
>Content-Transfer-Encoding: 7bit
>Content-Description: Card for Michael Schneider
>Content-Disposition: attachment;
> filename="Michael.L.Schneider.vcf"
>
>begin:vcard
>n:Schneider;Michael
>tel;work:513-576-2935
>x-mozilla-html:FALSE
>adr:;;;;;;
>version:2.1
>email;internet:Michael.L.Schneider at eds.com
>fn:Michael L Schneider
>end:vcard
>
>--------------4A98C5CDD83E4669F72F9746--
>
Roger Burnham
rburnham at blennylips.com
More information about the Python-list
mailing list