Commit 5be34ab6 authored by jim's avatar jim

When doing variable substitutions, you can omit the section name to

refer to a variable in the same section (e.g. ${:foo}).

When doing variable substitution, you can use the special option,
``_buildout_section_name_`` to get the section name.  This is most handy
for getting the current section name (e.g. ${:_buildout_section_name_}.


git-svn-id: http://svn.zope.org/repos/main/zc.buildout/trunk@103234 62d5b8a3-27da-0310-9561-8e5933582275
parent c7b9b755
......@@ -4,6 +4,13 @@ Change History
1.4.0 (2009-08-26)
==================
- When doing variable substitutions, you can omit the section name to
refer to a variable in the same section (e.g. ${:foo}).
- When doing variable substitution, you can use the special option,
``_buildout_section_name_`` to get the section name. This is most handy
for getting the current section name (e.g. ${:_buildout_section_name_}.
- Added annotate command for annotated sections. Displays sections
key-value pairs along with the value origin.
......
......@@ -1086,7 +1086,7 @@ class Options(UserDict.DictMixin):
_template_split = re.compile('([$]{[^}]*})').split
_simple = re.compile('[-a-zA-Z0-9 ._]+$').match
_valid = re.compile('\${[-a-zA-Z0-9 ._]+:[-a-zA-Z0-9 ._]+}$').match
_valid = re.compile('\${[-a-zA-Z0-9 ._]*:[-a-zA-Z0-9 ._]+}$').match
def _sub(self, template, seen):
value = self._template_split(template)
subs = []
......@@ -1112,9 +1112,16 @@ class Options(UserDict.DictMixin):
"has invalid characters."
% ref)
v = self.buildout[s[0]].get(s[1], None, seen)
section, option = s
if not section:
section = self.name
v = self.buildout[section].get(option, None, seen)
if v is None:
raise MissingOption("Referenced option does not exist:", *s)
if option == '_buildout_section_name_':
v = self.name
else:
raise MissingOption("Referenced option does not exist:",
section, option)
subs.append(v)
subs.append('')
......
......@@ -866,6 +866,37 @@ Section and option names in variable substitutions are only allowed to
contain alphanumeric characters, hyphens, periods and spaces. This
restriction might be relaxed in future releases.
We can ommit the section name in a variable substitution to refer to
the current section. We can also use the special option,
_buildout_section_name_ to get the current section name.
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... develop = recipes
... parts = data-dir debug
... log-level = INFO
...
... [debug]
... recipe = recipes:debug
... File 1 = ${data-dir:path}/file
... File 2 = ${:File 1}/log
... my_name = ${:_buildout_section_name_}
...
... [data-dir]
... recipe = recipes:mkdir
... path = mydata
... """)
>>> print system(buildout),
Develop: '/sample-buildout/recipes'
Uninstalling debug.
Updating data-dir.
Installing debug.
File 1 /sample-buildout/mydata/file
File 2 /sample-buildout/mydata/file/log
my_name debug
recipe recipes:debug
Automatic part selection and ordering
-------------------------------------
......@@ -897,8 +928,9 @@ It will still be treated as a part:
>>> print system(buildout),
Develop: '/sample-buildout/recipes'
Uninstalling debug.
Updating data-dir.
Updating debug.
Installing debug.
File 1 /sample-buildout/mydata/file
File 2 /sample-buildout/mydata/file/log
recipe recipes:debug
......
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