Skip to content

Commit

Permalink
Merge branch 'DynamicParameter' of git://github.com/jaredgrubb/buildbot
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Feb 26, 2013
2 parents ede2a91 + 247ff44 commit c599ace
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 18 deletions.
6 changes: 5 additions & 1 deletion master/buildbot/schedulers/forcesched.py
Expand Up @@ -209,14 +209,18 @@ def parse_from_arg(self, s):
raise ValidationError("'%s' does not belongs to list of available choices '%s'"%(s, self.choices))
return s


def getChoices(self, master, scheduler, buildername):
return self.choices

class InheritBuildParameter(ChoiceStringParameter):
"""A parameter that takes its values from another build"""
type = ChoiceStringParameter.type + ["inherit"]
name = "inherit"
compatible_builds = None

def getChoices(self, master, scheduler, buildername):
return self.compatible_builds(master.status, buildername)

def getFromKwargs(self, kwargs):
raise ValidationError("InheritBuildParameter can only be used by properties")

Expand Down
25 changes: 12 additions & 13 deletions master/buildbot/status/web/builder.py
Expand Up @@ -25,7 +25,6 @@
map_branches, path_to_authzfail, ActionResource, \
getRequestCharset
from buildbot.schedulers.forcesched import ForceScheduler
from buildbot.schedulers.forcesched import InheritBuildParameter, NestedParameter
from buildbot.schedulers.forcesched import ValidationError
from buildbot.status.web.build import BuildsResource, StatusResourceBuild
from buildbot import util
Expand Down Expand Up @@ -177,23 +176,23 @@ def buildForceContextForField(req, default_props, sch, field, master, buildernam
pname = "%s.%s"%(sch.name, field.fullName)

default = field.default
if isinstance(field, InheritBuildParameter):
# yes, I know, its bad to overwrite the parameter attribute,
# but I dont have any other simple way of doing this atm.
field.choices = field.compatible_builds(master.status, buildername)
if field.choices:
default = field.choices[0]

if "list" in field.type:
choices = field.getChoices(master, sch, buildername)
if choices:
default = choices[0]
default_props[pname+".choices"] = choices

default = req.args.get(pname, [default])[0]
if "bool" in field.type:
default_props[pname] = "checked" if default else ""
else:
default = "checked" if default else ""
elif isinstance(default, unicode):
# filter out unicode chars, and html stuff
if isinstance(default, unicode):
default = html.escape(default.encode('utf-8','ignore'))
default_props[pname] = default
default = html.escape(default.encode('utf-8','ignore'))

default_props[pname] = default

if isinstance(field, NestedParameter):
if "nested" in field.type:
for subfield in field.fields:
buildForceContextForField(req, default_props, sch, subfield, master, buildername)

Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/status/web/templates/forms.html
Expand Up @@ -94,8 +94,8 @@
<span class="label">{{f.label}}</span>
<span class="select">
<select name='{{f.fullName}}' {{ f.multiple and "multiple" or ""}}>
{% for c in f.choices %}
<option {{(c in default_props[sch.name+"."+f.fullName]) and "selected" or ""}}>{{c}}</option>
{% for c in default_props[sch.name+"."+f.fullName+".choices"] %}
<option {{(c in default_props[sch.name+"."+f.fullName]) and "selected" or ""}}>{{c}}</option>
{% endfor %}
</select>
</span>
Expand Down
5 changes: 5 additions & 0 deletions master/buildbot/test/unit/test_schedulers_forcesched.py
Expand Up @@ -379,6 +379,11 @@ def test_ChoiceParameterError(self):
klass=ChoiceStringParameter, choices=['t1','t2'],
debug=False)

def test_ChoiceParameterError_notStrict(self):
self.do_ParameterTest(value='t1', expect='t1',
strict=False,
klass=ChoiceStringParameter, choices=['t1','t2'])


def test_ChoiceParameterMultiple(self):
self.do_ParameterTest(value=['t1','t2'], expect=['t1','t2'],
Expand Down
16 changes: 14 additions & 2 deletions master/docs/manual/cfg-schedulers.rst
Expand Up @@ -1071,6 +1071,8 @@ use the authenticated user instead of displaying a text-entry box.
``need_email`` (optional; default True)
If true, require a full email address rather than arbitrary text.

.. bb:sched:: ChoiceStringParameter
ChoiceStringParameter
#####################

Expand All @@ -1082,8 +1084,13 @@ ChoiceStringParameter
This parameter type lets the user choose between several choices (e.g the list
of branches you are supporting, or the test campaign to run). If ``multiple``
is false, then its result is a string - one of the choices. If ``multiple`` is
true, then the result is a list of strings from the choices. Its arguments, in
addition to the common options, are:
true, then the result is a list of strings from the choices.

Note that for some use cases, the choices need to be generated dynamically. This can
be done via subclassing and overiding the 'getChoices' member function. An example
of this is provided by the source for the :py:class:`InheritBuildParameter` class.

Its arguments, in addition to the common options, are:

``choices``

Expand Down Expand Up @@ -1121,6 +1128,10 @@ Example::
CodebaseParameter
#####################

::

CodebaseParameter(codebase="myrepo")

This is a parameter group to specify a sourcestamp for a given codebase.

``codebase``
Expand All @@ -1147,6 +1158,7 @@ This is a parameter group to specify a sourcestamp for a given codebase.
A :ref:`parameter <ForceScheduler-Parameters>` specifying the project for
the build. The default value is a string parameter.


InheritBuildParameter
#####################

Expand Down
3 changes: 3 additions & 0 deletions master/docs/relnotes/index.rst
Expand Up @@ -63,6 +63,9 @@ Changes for Developers
to send a message back to the committer.
See the linked documentation for details.

* bb:sched:`ChoiceStringParameter` has a new method ``getChoices`` that can be used to generate
content dynamically for Force scheduler forms.

Slave
-----

Expand Down

0 comments on commit c599ace

Please sign in to comment.