Search code examples
buildbot

How to use a default value when using util.Interpolate


I'm using something like util.Interpolate('%(src::branch)s') to get the name of the branch from my Subversion repository. This works as expected when polling the repository but not when forcing a build. Is it possible to somehow use util.Interpolate('%(src::branch)s') so that when the branch is None or an empty string it uses "trunk" instead?

util.Interpolate('%(src::branch)s') should return the src::branch property when one has been set or else trunk.


Solution

  • According to buildbot docs it should be:

    util.Interpolate('%(src::branch:-trunk)s')

    The following ways of interpreting the value are available:

    -replacement

    If the key exists, substitute its value; otherwise, substitute replacement. replacement may be empty (default), %(prop:propname:-)s.

    ~replacement

    Like -replacement, but only substitutes the value of the key if it is something Python regards as True. Python considers None, 0, empty lists, and the empty string to be false, so such values will be replaced by replacement.

    +replacement

    If the key exists, substitute replacement; otherwise, substitute an empty string.