Templating recipe with remote resource support.
Project description
Template recipe which supports remote resource.
Inspired by collective.recipe.template, with minimum set of features, but with (hopefully) safer buildout-based templating.
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.2 (2011-10-12)
Include missing files in package. [Łukasz Nowak]
2.1 (2011-10-12)
Description update. [Łukasz Nowak]
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file slapos.recipe.template-2.2.tar.gz.
File metadata
- Download URL: slapos.recipe.template-2.2.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c02250fd3dc59de65bb7c4507b036b0c778dbc7fc5270e806a160ac4a52d4fef
|
|
| MD5 |
b2fc83fed9990b6dff262eada67dc0ff
|
|
| BLAKE2b-256 |
b0593567311807b36d91bc30e0997162f71fe9a97abfd0faec109671a0f5b8b1
|