Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install z3c.recipe.template

How to install z3c.recipe.template

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install z3c.recipe.template
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.1 Available View build log
Windows (64-bit)
0.1 Available View build log
Mac OS X (10.5+)
0.1 Available View build log
Linux (32-bit)
0.1 Available View build log
Linux (64-bit)
0.1 Available View build log
 
License
ZPL 2.1
Dependencies
Lastest release
version 0.1 on Jan 5th, 2011

Introduction

This recipe can be used to generate textfiles from a (text) template. Different to collective.recipe.template you can also specify a path to the output file and the path will be created, if it does not exist.

A short example:

[buildout]

System Message: ERROR/3 (<string>, line 12)

Inconsistent literal block quoting.

parts = zope.conf

[message] recipe = collective.recipe.template input = templates/message.in output = ${buildout:parts-directory}/etc/message

mymessage = Hello, World!

In the template you can use the exact same variables as you can use in the buildout configuration. For example an input file can look like this:

System Message: WARNING/2 (<string>, line 25)

Literal block expected; none found.

My top level directory is ${buildout:directory} Executables are stored in ${buildout:bin-directory}

As an extension to the buildout syntax you can reference variables from the current buildout part directly. For example:

System Message: WARNING/2 (<string>, line 32)

Literal block expected; none found.

My message is: ${mymessage}

Why another template recipe?

Both iw.recipe.template and inquant.recipe.textfile claim to do the same thing. I have found them to be undocumented and too buggy for real world use, and neither are in a public repository where I could fix them. In addition this implementation leverages the buildout variable substitution code, making it a lot simpler.

collective.recipe.template actually lacks support for creating paths of target files to be generated (and tests).

Detailed Description

Simple creation of a file out of a template

Lets create a minimal buildout.cfg file:

>>> write('buildout.cfg',

System Message: ERROR/3 (<string>, line 62)

Inconsistent literal block quoting.

... ''' ... [buildout] ... parts = template ... offline = true ... ... [template] ... recipe = z3c.recipe.template ... input = template.in ... output = template ... ''')

We create a template file:

>>> write('template.in',

System Message: ERROR/3 (<string>, line 76)

Inconsistent literal block quoting.

... '''# ... My template knows about buildout path: ... ${buildout:directory} ... ''')

Now we can run buildout:

>>> print system(join('bin', 'buildout')),

System Message: ERROR/3 (<string>, line 84)

Inconsistent literal block quoting.

Installing template.

The template was indeed created:

>>> cat('template')

System Message: ERROR/3 (<string>, line 89)

Inconsistent literal block quoting.

# My template knows about buildout path: .../sample-buildout

The variable buildout:directory was also substituted by a path.

Creating a template in a variable path

Lets create a minimal buildout.cfg file. This time the output should happen in a variable path:

>>> write('buildout.cfg',

System Message: ERROR/3 (<string>, line 103)

Inconsistent literal block quoting.

... ''' ... [buildout] ... parts = template ... offline = true ... ... [template] ... recipe = z3c.recipe.template ... input = template.in ... output = ${buildout:parts-directory}/template ... ''')

Now we can run buildout:

>>> print system(join('bin', 'buildout')),

System Message: ERROR/3 (<string>, line 117)

Inconsistent literal block quoting.

Uninstalling template. Installing template.

The template was indeed created:

>>> cat('parts', 'template')

System Message: ERROR/3 (<string>, line 123)

Inconsistent literal block quoting.

# My template knows about buildout path: .../sample-buildout

Creating missing paths

If an output file should be created in a path that does not yet exist, then the missing items will be created for us:

>>> write('buildout.cfg',

System Message: ERROR/3 (<string>, line 135)

Inconsistent literal block quoting.

... ''' ... [buildout] ... parts = template ... offline = true ... ... [template] ... recipe = z3c.recipe.template ... input = template.in ... output = ${buildout:parts-directory}/etc/template ... ''')

>>> print system(join('bin', 'buildout')),
Uninstalling template.
Installing template.

Also creation of several subdirectories is supported:

>>> write('buildout.cfg',

System Message: ERROR/3 (<string>, line 154)

Inconsistent literal block quoting.

... ''' ... [buildout] ... parts = template ... offline = true ... ... [template] ... recipe = z3c.recipe.template ... input = template.in ... output = ${buildout:parts-directory}/foo/bar/template ... ''')

>>> print system(join('bin', 'buildout')),
Uninstalling template.
Installing template.
>>> cat('parts', 'foo', 'bar', 'template')
#
My template knows about buildout path:
.../sample-buildout

When changes happen to the output path, then the old path is removed on uninstall. Therefore the etc/ directory created above has vanished now:

>>> ls('parts')

System Message: ERROR/3 (<string>, line 179)

Inconsistent literal block quoting.

d foo

Changes

0.1 (2009-03-09)

Initial build based on collective.recipe.template

Subscribe to package updates

Last updated Jan 5th, 2011

Download Stats

Last month:2

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.