[Erp5-report] r41837 arnaud.fontaine - in /erp5/trunk/utils/erp5.extension.sectionextender:...
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Dec 28 17:22:14 CET 2010
Author: arnaud.fontaine
Date: Tue Dec 28 17:22:13 2010
New Revision: 41837
URL: http://svn.erp5.org?rev=41837&view=rev
Log:
* Improve the way to declare a section extender by having a single
option 'section-extender' and one section per line as its values.
Many thanks to Mustapha Benali for the review and suggestion.
* Add missing 'extensions' options to the buildout configuration file
given as example in README.txt.
Modified:
erp5/trunk/utils/erp5.extension.sectionextender/README.txt
erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/extension/sectionextender/__init__.py
Modified: erp5/trunk/utils/erp5.extension.sectionextender/README.txt
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.extension.sectionextender/README.txt?rev=41837&r1=41836&r2=41837&view=diff
==============================================================================
--- erp5/trunk/utils/erp5.extension.sectionextender/README.txt [utf8] (original)
+++ erp5/trunk/utils/erp5.extension.sectionextender/README.txt [utf8] Tue Dec 28 17:22:13 2010
@@ -5,9 +5,10 @@ Example configuration
---------------------
[buildout]
-supervisor-section-extender-target-section = supervisor-instance
-supervisor-section-extender-target-option = programs
-supervisor-section-extender-source-option = supervisor-program
+extensions = erp5.extension.sectionextender
+
+section-extender =
+ supervisor-instance:programs supervisor-program
parts =
supervisor-instance
@@ -34,3 +35,6 @@ With this configuration, 'supervisor-pro
'test1-instance' and 'test3-instance' will be added to
'${supervisor-instance:programs}', but not 'test2-instance' as it's
not in 'parts'.
+
+You can specify several sections to be extended by just adding them to
+'section-extender' (one per line).
Modified: 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=41837&r1=41836&r2=41837&view=diff
==============================================================================
--- erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/extension/sectionextender/__init__.py [utf8] (original)
+++ erp5/trunk/utils/erp5.extension.sectionextender/src/erp5/extension/sectionextender/__init__.py [utf8] Tue Dec 28 17:22:13 2010
@@ -13,34 +13,33 @@
#
##############################################################################
-def _get_extended_section_by_source(buildout_section_dict):
+import re
+
+def _get_extended_section_by_source(section_extender_lines):
"""
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
+ @param section_extender_lines: section extender lines
+ @type section_extender_lines: str
@rtype: list
@returns: target section, target option and source option for all sections
"""
+ section_extender_re = re.compile('\s*([^:]+):([^\s]+)\s*([^\s]+)\s*$')
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:
+ for section_extender_line in section_extender_lines.splitlines():
+ if not section_extender_line:
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
+ extended_section = section_extender_re.match(
+ section_extender_line).groups()
+ except AttributeError:
+ continue
+
+ extended_section_list.append(extended_section)
return extended_section_list
@@ -51,26 +50,34 @@ def ext(buildout):
(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.
+ Sections to be extended are specified in the 'buildout' section
+ following this format (there could be many lines:
+
+ section-extender =
+ TARGET-SECTION:TARGET-OPTION SOURCE-OPTION
+ TARGET-SECTION2:TARGET-OPTION2 SOURCE-OPTION2
+ ...
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
+ extensions = erp5.extension.sectionextender
+
+ section-extender =
+ supervisor-instance:programs supervisor-program
+ test1-section:test1-section-option test1-source-option
@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'])
+ # Get the sections to be extended otherwise do nothing
+ if 'section-extender' not in buildout['buildout']:
+ return
+
+ extended_section_list = _get_extended_section_by_source(
+ buildout['buildout']['section-extender'])
for part in buildout['buildout']['parts'].splitlines():
if not part:
More information about the Erp5-report
mailing list