[Chicago] paster quickstart?

Kumar McMillan kumar.mcmillan at gmail.com
Sat Jun 7 19:41:58 CEST 2008

On Fri, Jun 6, 2008 at 11:15 PM, Lukasz Szybalski <szybalski at gmail.com> wrote:
> Hello,
> I read that I could use paster to create a skeleton for a project.?!@?
> That is great, but my next step is to tell my program to ask user for
> input filenames and based on that it will need to create 5 .py files
> for each filename.
> I need to substitute the names of few fields in the .py files and add
> some things depending on extension.
> Normally I would do it with some python template, but I heard I could
> do that with paster maybe? Is that true, is there a different tool I
> should be using?
> Where do I start?

You can start here : http://pythonpaste.org/script/developer.html

Then you may want to look at the CreateDistroCmd:

You will probably need one set of templates per extension, to dictate
each variation of a file layout.  Within each template dir, Paste
allows you to use variables in file names by putting plus signs
between the variable name, like:


that will use the var "input_file" to name the final .py file.  And
since it ends in py_tmpl, Paste will interpolate variables within the
file as well (i.e. {{your_var}} ).  In your command() method of your
Paste Command class you might prompt the user like this:

vars = {}
if self.interactive:
    vars['input_file'] = self.challenge('Enter input file')
    # check the command line... then
    raise BadCommand('You must provide an INPUT_FILE when non-interactive')

then I suppose you'd have to decide what template package to use based
on file extension and you'd render each in a loop per input file.  in
that loop, rendering looks something like:

template.check_vars(vars, self)
self.create_template(template, output_dir, vars)

btw, the paste list would probably be a great place to continue
discussing paste ;)

More information about the Chicago mailing list