Commit 5251dd37 authored by Antoine Catton's avatar Antoine Catton Committed by Łukasz Nowak

Drop collective dependency.

Squashed commit of the following:

commit 1b0a4e9b58ffe5d831459cc77637cee1bcee30da
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Wed Oct 12 12:00:53 2011 +0200

    Do not tests buildout issue.

commit 51a6b9a187a0bbaa3522756993c5ff17e2b262e0
Author: Antoine Catton <acatton@tiolive.com>
Date:   Wed Oct 12 11:38:57 2011 +0200

    Update .gitignore with editor backup files.

commit 2235385913170d4546cd92b96d2ed1706e94fad1
Author: Antoine Catton <acatton@tiolive.com>
Date:   Wed Oct 12 11:37:39 2011 +0200

    Update .gitignore with buildout generated files.

commit 35bdbf798e504d9e947ed358dbe2f9a74143e2b8
Author: Antoine Catton <acatton@tiolive.com>
Date:   Wed Oct 12 11:36:44 2011 +0200

    Update changelog

commit 64a2d6d8b85850641172d6a79acd6d75c720d449
Author: Antoine Catton <acatton@tiolive.com>
Date:   Wed Oct 12 11:35:56 2011 +0200

    Reformatting egg's long_description

commit 4e53b6bc7791061a57783a7b55b76f96c56fa1c8
Author: Antoine Catton <acatton@tiolive.com>
Date:   Wed Oct 12 11:30:26 2011 +0200

    Add buildout.cfg in order to easily run tests

commit 7c8e7225d344770502ad5aa84d72d2c9b1dc4e05
Author: Antoine Catton <acatton@tiolive.com>
Date:   Wed Oct 12 11:29:40 2011 +0200

    Add tests

commit e03d69efe845d41a3321568ccbf0c6bc187867f0
Author: Antoine Catton <acatton@tiolive.com>
Date:   Wed Oct 12 11:27:14 2011 +0200

    Move slapos.recipe.template module in its own directory in order to add
    tests and so on.

commit be8900ed0f0cf6105ef30881d7c818cb6cc6a0f2
Author: Antoine Catton <acatton@tiolive.com>
Date:   Tue Oct 11 16:32:47 2011 +0200

    Add support of mode option

commit 943b9b62477f454cb25f5118595690a2a0eebcab
Author: Romain Courteaud <romain@nexedi.com>
Date:   Tue Oct 11 15:12:28 2011 +0200

    Use __getitem__ instead of dict.get

commit 0d1b1c68270139d2602b23db1b0943220f463cc8
Author: Antoine Catton <acatton@tiolive.com>
Date:   Tue Oct 11 15:10:26 2011 +0200

    Removing error message

commit a9d677ba9c67c3b06368b56b212898c79cd155ca
Author: Antoine Catton <acatton@tiolive.com>
Date:   Tue Oct 11 15:06:13 2011 +0200

    Use a part dependent hidden option name

commit 87ab4e4b35c3d4696395e24616a2fba6f084cccc
Author: Antoine Catton <acatton@tiolive.com>
Date:   Tue Oct 11 15:04:42 2011 +0200

    Add python 2.6 compatibility by removing with statements

commit 6ab6954b8fb924c96562d1fad83e226f2060bbd8
Author: Antoine Catton <acatton@tiolive.com>
Date:   Tue Oct 11 15:03:04 2011 +0200

    Remove the useless internal 'input' option

commit 022bd83d68460f5e94ab2381b1a33014ecfec93c
Author: Romain Courteaud <romain@nexedi.com>
Date:   Tue Oct 11 14:57:21 2011 +0200

    Drop collective.recipe.template dependency
parent 19f44d2b
...@@ -2,3 +2,15 @@ ...@@ -2,3 +2,15 @@
build build
dist dist
slapos.recipe.template.egg-info slapos.recipe.template.egg-info
# buildout files
bin
develop-eggs
eggs
parts
.installed.cfg
# Editor backupfiles
.*.swp
*~
*.bak
1.2 (unreleased) 1.2 (unreleased)
================ ================
* No changes yet. * Dropping collective.recipe.template dependency. [Romain Courteaud]
1.1 (2011-05-30) 1.1 (2011-05-30)
================ ================
......
======================
slapos.recipe.template slapos.recipe.template
====================== ======================
Fully networked template recipe, reusing collective.recipe.template with Fully networked template recipe, simulating collective.recipe.template with
ability to download template over the network ability to download template over the network and check MD5 sum.
Usage
-----
::
[buildout]
parts = template
[template]
recipe = slapos.cookbook:template
url = http://server/with/template
# optional md5sum
md5sum = 1234567890
output = ${buildout:directory}/result
All parameters except url and md5sum will be passed to
collective.recipe.template, so please visit
http://pypi.python.org/pypi/collective.recipe.template for full information.
[buildout]
parts = test
develop = .
[test]
recipe = zc.recipe.testrunner
eggs = slapos.recipe.template [test]
from setuptools import setup, find_packages from setuptools import setup, find_packages
import os
version = '1.2-dev' version = '1.2-dev'
name = 'slapos.recipe.template' name = 'slapos.recipe.template'
long_description = open("README.txt").read() + "\n" + \ long_description = open("README.txt").read() + "\n" + \
open(os.path.join('slapos', 'recipe',
'template', "README.txt")).read() + "\n" + \
open("CHANGES.txt").read() + "\n" open("CHANGES.txt").read() + "\n"
# extras_requires are not used because of # extras_requires are not used because of
...@@ -21,11 +24,13 @@ setup(name=name, ...@@ -21,11 +24,13 @@ setup(name=name,
packages=find_packages(), packages=find_packages(),
include_package_data=True, include_package_data=True,
install_requires=[ install_requires=[
'collective.recipe.template', # needed by template recipe
'setuptools', # namespaces 'setuptools', # namespaces
'zc.buildout', # plays with buildout 'zc.buildout', # plays with buildout
], ],
zip_safe=True, zip_safe=True,
extras_require ={
'test': 'zope.testing',
},
entry_points={ entry_points={
'zc.buildout': [ 'zc.buildout': [
'default = slapos.recipe.template:Recipe', 'default = slapos.recipe.template:Recipe',
......
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
...@@ -24,14 +24,45 @@ ...@@ -24,14 +24,45 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
import os
import collective.recipe.template
import zc.buildout import zc.buildout
class Recipe(collective.recipe.template.Recipe):
class Recipe(object):
def __init__(self, buildout, name, options): def __init__(self, buildout, name, options):
download = zc.buildout.download.Download(buildout['buildout'], download = zc.buildout.download.Download(buildout['buildout'],
hash_name=True) hash_name=True)
path, is_temp = download(options.pop('url'), path, is_temp = download(options.pop('url'),
md5sum=options.get('md5sum')) md5sum=options.get('md5sum'))
options['input'] = path
collective.recipe.template.Recipe.__init__(self, buildout, name, options) self.mode = None
if 'mode' in options:
# Mode is in octal notation
self.mode = int(options['mode'], 8)
hidden_option = '__template_content_%s__' % name
inputfile = open(path, 'r')
try:
# Using internal buildout templating system
options._cooked[hidden_option] = inputfile.read()
self.output_content = options[hidden_option]
finally:
inputfile.close()
self.output_filename = options['output']
def install(self):
outputfile = open(self.output_filename, 'w')
try:
outputfile.write(self.output_content)
finally:
outputfile.close()
if self.mode is not None:
os.chmod(self.output_filename, self.mode)
return self.output_filename
def update(self):
return self.install()
##############################################################################
#
# Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import unittest
import zc.buildout.testing
from zope.testing import doctest, renormalizing
def setUp(test):
zc.buildout.testing.buildoutSetUp(test)
zc.buildout.testing.install_develop('slapos.recipe.template', test)
zc.buildout.testing.install('zope.testing', test)
checker = renormalizing.RENormalizing([
zc.buildout.testing.normalize_path,
]
)
def test_suite():
files = ['README.txt',
]
return unittest.TestSuite([doctest.DocFileSuite(filename, setUp=setUp,
tearDown=zc.buildout.testing.buildoutTearDown,
optionflags=doctest.ELLIPSIS, checker=checker)
for filename in files])
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment