[Erp5-report] r41779 arnaud.fontaine - in /erp5/trunk/utils/erp5.extension.sectionextender:...
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Dec 27 07:15:55 CET 2010
Author: arnaud.fontaine
Date: Mon Dec 27 07:15:55 2010
New Revision: 41779
URL: http://svn.erp5.org?rev=41779&view=rev
Log:
Add sectionextender extension for buildout, useful to handle properly
supervisor programs
Added:
erp5/trunk/utils/erp5.extension.sectionextender/
erp5/trunk/utils/erp5.extension.sectionextender/CHANGES.txt (with props)
erp5/trunk/utils/erp5.extension.sectionextender/README.txt (with props)
erp5/trunk/utils/erp5.extension.sectionextender/setup.py
erp5/trunk/utils/erp5.extension.sectionextender/src/
erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/
erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/__init__.py
erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/extension/
erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/extension/__init__.py
erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/extension/sectionextender/
erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/extension/sectionextender/__init__.py
Added: erp5/trunk/utils/erp5.extension.sectionextender/CHANGES.txt
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.extension.sectionextender/CHANGES.txt?rev=41779&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.extension.sectionextender/CHANGES.txt (added)
+++ erp5/trunk/utils/erp5.extension.sectionextender/CHANGES.txt [utf8] Mon Dec 27 07:15:55 2010
@@ -0,0 +1,4 @@
+0.1 (unreleased)
+----------------
+
+ - initial release
Propchange: erp5/trunk/utils/erp5.extension.sectionextender/CHANGES.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: erp5/trunk/utils/erp5.extension.sectionextender/README.txt
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.extension.sectionextender/README.txt?rev=41779&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.extension.sectionextender/README.txt (added)
+++ erp5/trunk/utils/erp5.extension.sectionextender/README.txt [utf8] Mon Dec 27 07:15:55 2010
@@ -0,0 +1,36 @@
+A buildout extension to allow any section of 'parts' to define options
+which will be appended to an option of another section.
+
+Example configuration
+---------------------
+
+[buildout]
+supervisor-section-extender-target-section = supervisor-instance
+supervisor-section-extender-target-option = programs
+supervisor-section-extender-source-option = supervisor-program
+
+parts =
+ supervisor-instance
+ test1-instance
+ test3-instance
+
+[supervisor-instance]
+recipe = collective.recipe.supervisor
+
+[test1-instance]
+recipe = recipe.foo.bar
+supervisor-program = 21 test1-instance test1-instance
+
+[test2-instance]
+recipe = recipe.foo.bar2
+supervisor-program = 22 test2-instance test2-instance
+
+[test3-instance]
+recipe = recipe.foo.bar3
+supervisor-program = 23 test3-instance test3-instance
+
+
+With this configuration, 'supervisor-program' options in
+'test1-instance' and 'test3-instance' will be added to
+'${supervisor-instance:programs}', but not 'test2-instance' as it's
+not in 'parts'.
Propchange: erp5/trunk/utils/erp5.extension.sectionextender/README.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: erp5/trunk/utils/erp5.extension.sectionextender/setup.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.extension.sectionextender/setup.py?rev=41779&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.extension.sectionextender/setup.py (added)
+++ erp5/trunk/utils/erp5.extension.sectionextender/setup.py [utf8] Mon Dec 27 07:15:55 2010
@@ -0,0 +1,29 @@
+from setuptools import setup, find_packages
+
+def read(name):
+ return open(name).read()
+
+name = 'erp5.extension.sectionextender'
+version = '0.1'
+long_description = (read('README.txt') + '\n' +
+ read('CHANGES.txt'))
+
+setup(name = name,
+ version = version,
+ author = 'Arnaud Fontaine',
+ author_email = 'arnaud.fontaine at nexedi.com',
+ description = 'Buildout extension to extend only sections in parts',
+ long_description=long_description,
+ license = "ZPL 2.1",
+ keywords = "buildout extension sections",
+ classifiers = ["License :: OSI Approved :: Zope Public License",
+ "Framework :: Buildout"],
+ package_dir = {'': 'src'},
+ packages = find_packages('src'),
+ namespace_packages = ['erp5', 'erp5.extension'],
+ include_package_data = True,
+ url='https://svn.erp5.org/repos/public/erp5/trunk/utils/erp5.extension.sectionextender/',
+ install_requires = ['setuptools'],
+ entry_points = {'zc.buildout.extension':
+ ['ext = %s:ext' % name]},
+ )
Added: erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/__init__.py?rev=41779&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/__init__.py (added)
+++ erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/__init__.py [utf8] Mon Dec 27 07:15:55 2010
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
Added: erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/extension/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/extension/__init__.py?rev=41779&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/extension/__init__.py (added)
+++ erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/extension/__init__.py [utf8] Mon Dec 27 07:15:55 2010
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
Added: erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/extension/sectionextender/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/extension/sectionextender/__init__.py?rev=41779&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/extension/sectionextender/__init__.py (added)
+++ erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/extension/sectionextender/__init__.py [utf8] Mon Dec 27 07:15:55 2010
@@ -0,0 +1,86 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
+# Copyright (c) 2006-2008 Zope Corporation and Contributors.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+def _get_extended_section_by_source(buildout_section_dict):
+ """
+ From the 'buildout' section, get all the sections, which are going
+ to be extended using this extension, along with their target and
+ source options.
+
+ @param buildout_section_dict: buildout section dict
+ @rtype: list
+ @returns: target section, target option and source option for all sections
+ """
+ extended_section_list = []
+
+ for option_name, option_value in buildout_section_dict.iteritems():
+ try:
+ prefix, suffix = option_name.split('-section-extender-target-section')
+ except ValueError:
+ continue
+
+ target_option_key = prefix + '-section-extender-target-option'
+ source_option_key = prefix + '-section-extender-source-option'
+
+ try:
+ extended_section_list.append((option_value,
+ buildout_section_dict[target_option_key],
+ buildout_section_dict[source_option_key]))
+ except KeyError:
+ print "WARNING: Ignoring section '%s' with missing target section or option" % name
+ continue
+
+ return extended_section_list
+
+def ext(buildout):
+ """
+ This extension allows any sections in 'parts' to define a (source)
+ option whose value will be added to the (target) option of a
+ (target) section, thus allowing to extend a section from another
+ one.
+
+ For each section to be extended ('PREFIX-section-extender-target-section'),
+ there has to be a target option ('PREFIX-section-extender-target-option'),
+ namely the name of the option in the extended section, _and_ a
+ source option ('PREFIX-section-extender-source-option'), which is
+ the option name set in sections.
+
+ For example, the following buildout configuration snippet allows to
+ extend the 'supervisor-instance' for the option 'programs' and can
+ be found in any sections as 'supervisor-program':
+
+ [buildout]
+ foo-section-extender-target-section = supervisor-instance
+ foo-section-extender-target-option = programs
+ foo-section-extender-source-option = supervisor-program
+
+ @param buildout: buildout configuration sections and their options
+ @type buildout: dict
+ """
+ # Get the sections to be extended
+ extended_section_list = _get_extended_section_by_source(buildout['buildout'])
+
+ for part in buildout['buildout']['parts'].splitlines():
+ if not part:
+ continue
+
+ for target_section, target_option, source_option in extended_section_list:
+ if source_option in buildout[part]:
+ # Set the value if it has never been set before
+ if target_option not in buildout[target_section]:
+ buildout[target_section][target_option] = buildout[part][source_option]
+ # Otherwise, just add on a new line
+ else:
+ buildout[target_section][target_option] += '\n' + buildout[part][source_option]
More information about the Erp5-report
mailing list