Skip to content

Commit

Permalink
Refactor console revision filtering to be more generic.
Browse files Browse the repository at this point in the history
Add the option to filter /console by repository.
  • Loading branch information
Amber Yust committed Sep 30, 2010
1 parent 7a06e20 commit 2577ff9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 36 deletions.
79 changes: 46 additions & 33 deletions master/buildbot/status/web/console.py
Expand Up @@ -9,6 +9,8 @@
from buildbot.status import builder
from buildbot.status.web.base import HtmlResource

class DoesNotPassFilter(Exception): pass # Used for filtering revs

def getResultsClass(results, prevResults, inProgress):
"""Given the current and past results, return the class that will be used
by the css to display the right color for a box."""
Expand Down Expand Up @@ -174,35 +176,6 @@ def getAllChanges(self, source, status, debugInfo):

return allChanges

def stripRevisions(self, allChanges, numRevs, branch, devName):
"""Returns a subset of changes from allChanges that matches the query.
allChanges is the list of all changes we know about.
numRevs is the number of changes we will inspect from allChanges. We
do not want to inspect all of them or it would be too slow.
branch is the branch we are interested in. Changes not in this branch
will be ignored.
devName is the developper name. Changes have not been submitted by this
person will be ignored.
"""

revisions = []

if not allChanges:
return revisions

totalRevs = len(allChanges)
for i in range(totalRevs - 1, totalRevs - numRevs, -1):
if i < 0:
break
change = allChanges[i]
if branch == ANYBRANCH or branch == change.branch:
if not devName or change.who in devName:
rev = DevRevision(change)
revisions.append(rev)

return revisions

def getBuildDetails(self, request, builderName, build):
"""Returns an HTML list of failures for a given build."""
details = {}
Expand Down Expand Up @@ -519,12 +492,44 @@ def displayStatusLine(self, builderList, allBuilds, revision, debugInfo):

return (builds, details)

def filterRevisions(self, revisions, filter=None, max_revs=None):
"""Filter a set of revisions based on any number of filter criteria.
If specified, filter should be a dict with keys corresponding to
revision attributes, and values of 1+ strings"""
if not filter:
if max_revs is None:
for rev in reversed(revisions):
yield DevRevision(rev)
else:
for index,rev in enumerate(reversed(revisions)):
if index >= max_revs:
break
yield DevRevision(rev)
else:
for index, rev in enumerate(reversed(revisions)):
if max_revs and index >= max_revs:
break
try:
for field,acceptable in filter.iteritems():
if not hasattr(rev, field):
raise DoesNotPassFilter
if type(acceptable) in (str, unicode):
if getattr(rev, field) != acceptable:
raise DoesNotPassFilter
elif type(acceptable) in (list, tuple, set):
if getattr(rev, field) not in acceptable:
raise DoesNotPassFilter
yield DevRevision(rev)
except DoesNotPassFilter:
pass

def displayPage(self, request, status, builderList, allBuilds, revisions,
categories, branch, debugInfo):
categories, repository, branch, debugInfo):
"""Display the console page."""
# Build the main template directory with all the informations we have.
subs = dict()
subs["branch"] = branch or 'trunk'
subs["repository"] = repository
if categories:
subs["categories"] = ' '.join(categories)
subs["time"] = time.strftime("%a %d %b %Y %H:%M:%S",
Expand Down Expand Up @@ -604,6 +609,8 @@ def content(self, request, cxt):
categories = request.args.get("category", [])
# List of all builders to show on the page.
builders = request.args.get("builder", [])
# Repo used to filter the changes shown.
repository = request.args.get("repository", [None])[0]
# Branch used to filter the changes shown.
branch = request.args.get("branch", [ANYBRANCH])[0]
# List of all the committers name to display on the page.
Expand All @@ -627,8 +634,14 @@ def content(self, request, cxt):
numRevs *= 2
numBuilds = numRevs


revisions = self.stripRevisions(allChanges, numRevs, branch, devName)
revFilter = {}
if branch != ANYBRANCH:
revFilter['branch'] = branch
if devName:
revFilter['who'] = devName
if repository:
revFilter['repository'] = repository
revisions = list(self.filterRevisions(allChanges, max_revs=numRevs, filter=revFilter))
debugInfo["revision_final"] = len(revisions)

# Fetch all the builds for all builders until we get the next build
Expand All @@ -650,7 +663,7 @@ def content(self, request, cxt):
debugInfo["added_blocks"] = 0

cxt.update(self.displayPage(request, status, builderList, allBuilds,
revisions, categories, branch, debugInfo))
revisions, categories, repository, branch, debugInfo))

template = request.site.buildbot_service.templates.get_template("console.html")
data = template.render(cxt)
Expand Down
3 changes: 3 additions & 0 deletions master/buildbot/status/web/templates/console.html
Expand Up @@ -86,6 +86,9 @@ <h1>Console View</h1>
{% if categories|length > 1 %}
<br><b>Categories:</b> {% for c in categories %}{{ c.name }} {% endfor %}
{% endif %}
{% if repository %}
<br><b>Repository:</b> {{ repository }}
{% endif %}
{% if branch != ANYBRANCH %}
<br><b>Branch:</b> {{ branch }}
{% endif %}
Expand Down
7 changes: 4 additions & 3 deletions master/docs/cfg-statustargets.texinfo
Expand Up @@ -254,9 +254,10 @@ regressions from this change. Finally a yellow box means that the test
is in progress.

By adding one or more ``builder='' query arguments, the Console view is
restricted to only showing information about the given Builders. By
adding one or more ``branch='' query arguments, the display is
restricted to showing information about the given branches. In
restricted to only showing information about the given Builders. Adding a
``repository='' argument will limit display to a given repository. By
adding a ``branch='' query argument, the display is
restricted to showing information about the given branch. In
addition, adding one or more ``category='' query arguments to the URL
will limit the display to Builders that were defined with one of the
given categories.
Expand Down

0 comments on commit 2577ff9

Please sign in to comment.