Skip to main content

collective.recipe.template with network input support.

Project description

Fully networked template recipe, simulating collective.recipe.template with ability to download template over the network and check MD5 sum.

Usage

Getting started

You can start by a simple buildout:

>>> write('buildout.cfg',
... '''
... [buildout]
... parts = template
...
... [template]
... recipe = slapos.recipe.template
... url = template.in
... output = template.out
...
... [section]
... option = value
... ''')

And a simple template:

>>> write('template.in', '${section:option}')

We run buildout:

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

And the output file has been parsed by buildout itself:

>>> cat('template.out')
value

Full options

There is two non required options:

md5sum

Check the integrity of the input file.

mode

Specify the filesystem permissions in octal notation.

Check file integrity

Let’s write a file template:

>>> write('template.in', '${buildout:parts}')

Compute its MD5 sum:

>>> import md5
>>> md5sum = md5.new(open('template.in', 'r').read()).hexdigest()

Write the buildout.cfg using slapos.recipe.template:

>>> write('buildout.cfg',
... '''
... [buildout]
... parts = template
...
... [template]
... recipe = slapos.recipe.template
... url = template.in
... output = template.out
... md5sum = ''' + md5sum + '''
... ''')

And run buildout, and see the result :

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

If the md5sum doesn’t match, the buildout fail:

>>> write('buildout.cfg',
... '''
... [buildout]
... parts = template
...
... [template]
... recipe = slapos.recipe.template
... url = template.in
... output = template.out
... md5sum = 0123456789abcdef0123456789abcdef
... ''')
>>> print system(join('bin', 'buildout')),
While:
  Installing.
  Getting section template.
  Initializing part template.
Error: MD5 checksum mismatch for local resource at 'template.in'.

Specify filesystem permissions

You can specify the mode of the written file:

>>> write('template.in', '${buildout:installed}')

>>> write('buildout.cfg',
... '''
... [buildout]
... parts = template
...
... [template]
... recipe = slapos.recipe.template
... url = template.in
... output = template.out
... mode = 0627
... ''')

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

And the generated file with have the right permissions:

>>> import stat
>>> import os
>>> print oct(stat.S_IMODE(os.stat('template.out').st_mode))
0627

Section dependency

You can use other part of buildout in the template. This way this parts will be installed as dependency:

>>> write('template.in', '${dependency:foobar}')
>>> write('buildout.cfg', '''
... [buildout]
... parts = template
...
... [template]
... recipe = slapos.recipe.template
... url = template.in
... output = template.out
...
... [dependency]
... foobar = dependency content
... recipe = zc.buildout:debug
... ''')

>>> print system(join('bin', 'buildout')),
Uninstalling template.
Installing dependency.
  foobar='dependency content'
  recipe='zc.buildout:debug'
Installing template.

This way you can get options which are computed in the __init__ of the dependent recipe.

Let’s create a sample recipe modifying its option dict:

>>> write('setup.py',
... '''
... from setuptools import setup
...
... setup(name='samplerecipe',
...       entry_points = {
...           'zc.buildout': [
...                'default = main:Recipe',
...           ],
...       }
...      )
... ''')
>>> write('main.py',
... '''
... class Recipe(object):
...
...     def __init__(self, buildout, name, options):
...         options['data'] = 'foobar'
...
...     def install(self):
...         return []
... ''')

Let’s just use buildout.cfg using this egg :

>>> write('template.in', '${sample:data}')
>>> write('buildout.cfg',
... '''
... [buildout]
... develop = .
... parts = template
...
... [template]
... recipe = slapos.recipe.template
... url = template.in
... output = template.out
...
... [sample]
... recipe = samplerecipe
... ''')
>>> print system(join('bin', 'buildout')),
Develop: '/sample-buildout/.'
Uninstalling template.
Uninstalling dependency.
Installing sample.
Installing template.
>>> cat('template.out')
foobar

2.0 (2011-10-12)

  • Dropping collective.recipe.template dependency. [Romain Courteaud, Antoine Catton]

1.1 (2011-05-30)

  • Moved out from slapos.cookbook in order to minimise depenencies [Łukasz Nowak]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slapos.recipe.template-2.0.tar.gz (4.4 kB view details)

Uploaded Source

File details

Details for the file slapos.recipe.template-2.0.tar.gz.

File metadata

File hashes

Hashes for slapos.recipe.template-2.0.tar.gz
Algorithm Hash digest
SHA256 0d22b0c50a170122ea94e8e454ac8ffdf96e4b67fabe89d5d71582bfe38f61d6
MD5 15f8bf411bab8e8c9d6db6785ca587c5
BLAKE2b-256 e1a361837f51e2aaf721986cc31274a77623e3c89f8ff67850620c2e2f5a6937

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page