Using Python to automate builds

Kosta kosta.koeman at
Tue Aug 4 23:40:46 CEST 2009

On Aug 4, 2:34 pm, Dave Angel <da... at> wrote:
> Kosta wrote:
> > I am a Python newbie, tasked with automating (researching) building
> > Windows drivers using the WDK build environment.  I've been looking
> > into Python for this (instead of writing a bunch of batch files).
> > What I would like to do, is to open a cmd window, and start a Python
> > script.  This script would then (based upon input arguments), build
> > different flavors of the driver (fre, chk, x86, x64) and do some post
> > processing (create cat files, sign, etc.).
> > I was hoping to take advantage as much as possible of exisiting
> > infrastructure from the WDK.  I am able to call setenv.bat and provide
> > all the input parameters.  One of the things setenv.bat does is change
> > the path environment variable.  However, this is not captured by
> > Python.  I could duplicate the functionality, but I'd rather not.  Is
> > there a way to capture all enviroment variable changes being made by a
> > batch file from Python?
> > Thanks!
> An excellent question.  It's been a few years, but last time I remember
> looking, setenv.bat only changed environment variables, and didn't
> change current directory, or run any external programs..  If that's
> still true, I figure you have three options.
> I don't know of any way to capture them explicitly.  So here are the
> three choices I can come up with:
> 1) have the first python program invoke a new shell which runs setenv,
> then runs another python program.  This second python program would be
> where all the work is done, invoking compilers, linkers etc.  So the
> first python program invokes a batch file which looks something like:
>           call setenv.bat  arg1
>           python    arg2 arg3  arg4  arg5
>  This batch file could even be generated on the fly, just to simplify
> complex argument passing.
> 2) Have the python program invoke a batch file something like the
> following, and then analyze the resulting text file
>            call setenv.bat   arg1
>            set > tempfile.txt
> The contents of that tempfile could then be loaded into a dict similar
> to the usual environment.  Now the Python script can continue, and just
> use these environment variable instead of the original set
> 3) Have the python program parse the setenv.bat instead of running it.
> There was a post on this newsgroup announcing pyKook.  It's still in
> early form, but you might get ideas from it.  I haven't looked, I just
> pasted the announcement to look at later.
> + I have released pyKook 0.0.2.
> +
> +
> +
> Other possibilities:
> +      flexible small 'make'
> alternative
> +
> +
> DaveA- Hide quoted text -
> - Show quoted text -

Thanks Dave.  I had thought about those three options, and was
honestly hoping for a foruth (I know, some people are never
satisfied ;).  I'll look into pyKook.  Thank you for your help.

More information about the Python-list mailing list