Skip to content

Commit

Permalink
Allow Properties(default=..) to contain further properties
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Nov 24, 2011
1 parent a35433e commit 5472889
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions master/buildbot/process/properties.py
Expand Up @@ -312,10 +312,14 @@ def __init__(self, key, default=None, defaultWhenFalse=True):

def getRenderingFor(self, props):
if self.defaultWhenFalse:
return props.getProperty(self.key) or self.default
rv = props.getProperty(self.key)
if rv:
return rv
else:
return props.getProperty(self.key, default=self.default)
if props.hasProperty(self.key):
return props.getProperty(self.key)

return props.render(self.default)

class _DefaultRenderer:
"""
Expand Down
8 changes: 8 additions & 0 deletions master/buildbot/test/unit/test_process_properties.py
Expand Up @@ -561,6 +561,14 @@ def testDefaultValue(self):
self.failUnlessEqual(self.build.render(value),
"Hello!")

def testDefaultValueNested(self):
self.props.setProperty("xxx", 'yyy', "scheduler")
value = Property("do-tests",
default=WithProperties("a-%(xxx)s-b"))

self.failUnlessEqual(self.build.render(value),
"a-yyy-b")

def testIgnoreDefaultValue(self):
self.props.setProperty("do-tests", "string", "scheduler")
value = Property("do-tests", default="Hello!")
Expand Down
4 changes: 4 additions & 0 deletions master/docs/manual/cfg-properties.rst
Expand Up @@ -180,6 +180,10 @@ parameter is not set::
f.addStep(ShellCommand(command=[ 'echo', 'warnings:',
Property('warnings', default='none', defaultWhenFalse=False) ])

The default value can reference other properties, e.g., ::

command=Property('command', default=Property('default-command'))

.. Index:: single; Properties; WithProperties

.. _WithProperties:
Expand Down
5 changes: 5 additions & 0 deletions master/docs/release-notes.rst
Expand Up @@ -39,6 +39,11 @@ Features
* The master-side SVN step now has an `export` method which is similar to
`copy`, but the build directory does not contain Subversion metdata. (:bb:bug:`2078`)

* :py:class:`Property` instances will now render any properties in the
default value if necessary. This makes possible constructs like ::

command=Property('command', default=Property('default-command'))

Slave
-----

Expand Down

0 comments on commit 5472889

Please sign in to comment.