Commit 37923d03 authored by Jim Fulton's avatar Jim Fulton

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_}.
parent 31886b77
...@@ -4,6 +4,13 @@ Change History ...@@ -4,6 +4,13 @@ Change History
1.4.0 (2009-08-26) 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 - Added annotate command for annotated sections. Displays sections
key-value pairs along with the value origin. key-value pairs along with the value origin.
......
...@@ -1086,7 +1086,7 @@ class Options(UserDict.DictMixin): ...@@ -1086,7 +1086,7 @@ class Options(UserDict.DictMixin):
_template_split = re.compile('([$]{[^}]*})').split _template_split = re.compile('([$]{[^}]*})').split
_simple = re.compile('[-a-zA-Z0-9 ._]+$').match _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): def _sub(self, template, seen):
value = self._template_split(template) value = self._template_split(template)
subs = [] subs = []
...@@ -1112,9 +1112,16 @@ class Options(UserDict.DictMixin): ...@@ -1112,9 +1112,16 @@ class Options(UserDict.DictMixin):
"has invalid characters." "has invalid characters."
% ref) % 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: 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(v)
subs.append('') subs.append('')
......
...@@ -866,6 +866,37 @@ Section and option names in variable substitutions are only allowed to ...@@ -866,6 +866,37 @@ Section and option names in variable substitutions are only allowed to
contain alphanumeric characters, hyphens, periods and spaces. This contain alphanumeric characters, hyphens, periods and spaces. This
restriction might be relaxed in future releases. 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 Automatic part selection and ordering
------------------------------------- -------------------------------------
...@@ -897,8 +928,9 @@ It will still be treated as a part: ...@@ -897,8 +928,9 @@ It will still be treated as a part:
>>> print system(buildout), >>> print system(buildout),
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug.
Updating data-dir. Updating data-dir.
Updating debug. Installing debug.
File 1 /sample-buildout/mydata/file File 1 /sample-buildout/mydata/file
File 2 /sample-buildout/mydata/file/log File 2 /sample-buildout/mydata/file/log
recipe recipes:debug 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