Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3744 from tardyp/badges
add badges plugin
- Loading branch information
Showing
13 changed files
with
304 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
new :ref`badges` plugin which reimplement the buildbot eight png badge system. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
# This file is part of Buildbot. Buildbot is free software: you can | ||
# redistribute it and/or modify it under the terms of the GNU General Public | ||
# License as published by the Free Software Foundation, version 2. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, write to the Free Software Foundation, Inc., 51 | ||
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
# Copyright Buildbot Team Members | ||
|
||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
|
||
import cairocffi as cairo | ||
import cairosvg | ||
|
||
import jinja2 | ||
from klein import Klein | ||
from twisted.internet import defer | ||
|
||
from buildbot.data import resultspec | ||
from buildbot.process.results import Results | ||
from buildbot.www.plugin import Application | ||
from xml.sax.saxutils import escape | ||
|
||
|
||
class Api(object): | ||
app = Klein() | ||
|
||
default = { # note that these defaults are documented in cfg-www.rst | ||
"left_text": "Build Status", | ||
"left_color": "#555", | ||
"style": "plastic", | ||
"template_name": "{style}.svg.j2", | ||
"font_face": "DejaVu Sans", | ||
"font_size": 11, | ||
"color_scheme": { | ||
"exception": "#007ec6", # blue | ||
"failure": "#e05d44", # red | ||
"retry": "#007ec6", # blue | ||
"skipped": "a4a61d", # yellowgreen | ||
"success": "#4c1", # brightgreen | ||
"unknown": "#9f9f9f", # lightgrey | ||
"warnings": "#dfb317" # yellow | ||
} | ||
} | ||
|
||
def __init__(self, ep): | ||
self.ep = ep | ||
self.env = jinja2.Environment(loader=jinja2.ChoiceLoader([ | ||
jinja2.PackageLoader('buildbot_badges'), | ||
jinja2.FileSystemLoader('templates') | ||
])) | ||
|
||
def makeConfiguration(self, request): | ||
|
||
config = {} | ||
config.update(self.default) | ||
for k, v in self.ep.config.items(): | ||
if k == 'color_scheme': | ||
config[k].update(v) | ||
else: | ||
config[k] = v | ||
|
||
for k, v in request.args.items(): | ||
config[k] = escape(v[0]) | ||
return config | ||
|
||
@app.route("/<string:builder>.png", methods=['GET']) | ||
@defer.inlineCallbacks | ||
def getPng(self, request, builder): | ||
svg = yield self.getSvg(request, builder) | ||
request.setHeader('content-type', 'image/png') | ||
defer.returnValue(cairosvg.svg2png(svg)) | ||
|
||
@app.route("/<string:builder>.svg", methods=['GET']) | ||
@defer.inlineCallbacks | ||
def getSvg(self, request, builder): | ||
config = self.makeConfiguration(request) | ||
request.setHeader('content-type', 'image/svg+xml') | ||
request.setHeader('cache-control', 'no-cache') | ||
|
||
# get the last completed build for that builder using the data api | ||
last_build = yield self.ep.master.data.get( | ||
("builders", builder, "builds"), | ||
limit=1, order=['-number'], | ||
filters=[resultspec.Filter('complete', 'eq', [True])]) | ||
|
||
# get the status text corresponding to results code | ||
results_txt = "unknown" | ||
if last_build: | ||
results = last_build[0]['results'] | ||
if results >= 0 and results < len(Results): | ||
results_txt = Results[results] | ||
|
||
svgdata = self.makesvg(results_txt, results_txt, left_text=config['left_text'], config=config) | ||
defer.returnValue(svgdata) | ||
|
||
def textwidth(self, text, config): | ||
"""Calculates the width of the specified text. | ||
""" | ||
surface = cairo.SVGSurface(None, 1280, 200) | ||
ctx = cairo.Context(surface) | ||
ctx.select_font_face(config['font_face'], | ||
cairo.FONT_SLANT_NORMAL, | ||
cairo.FONT_WEIGHT_BOLD) | ||
ctx.set_font_size(int(config['font_size'])) | ||
return ctx.text_extents(text)[2] + 2 | ||
|
||
def makesvg(self, right_text, status=None, left_text=None, | ||
left_color=None, config=None): | ||
"""Renders an SVG from the template, using the specified data | ||
""" | ||
right_color = config['color_scheme'].get(status, "#9f9f9f") # Grey | ||
|
||
left_text = left_text or config['left_text'] | ||
left_color = left_color or config['left_color'] | ||
|
||
left = { | ||
"color": left_color, | ||
"text": left_text, | ||
"width": self.textwidth(left_text, config) | ||
} | ||
right = { | ||
"color": right_color, | ||
"text": right_text, | ||
"width": self.textwidth(right_text, config) | ||
} | ||
|
||
template = self.env.get_template(config['template_name'].format(**config)) | ||
return template.render(left=left, right=right, config=config) | ||
|
||
|
||
# create the interface for the setuptools entry point | ||
ep = Application(__name__, "Buildbot badges", ui=False) | ||
ep.resource = Api(ep).app.resource() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<svg xmlns="http://www.w3.org/2000/svg" width="{{ left.width + right.width }}" height="20"> | ||
<rect width="{{ left.width + right.width }}" height="20" fill="{{ left.color }}"/> | ||
<rect x="{{ left.width }}" width="{{ right.width }}" height="20" fill="{{ right.color }}"/> | ||
<rect x="{{ left.width }}" width="4" height="20" fill="{{ right.color }}"/> | ||
<rect width="{{ left.width + right.width }}" height="20" fill-opacity=".1"/> | ||
<g fill="#fff" text-anchor="middle" font-family="{{config.font_face}},Verdana,Geneva,sans-serif" font-size="{{config.font_size}}"> | ||
<text x="{{ left.width/2+1 }}" y="14">{{ left.text }}</text> | ||
<text x="{{ left.width+right.width/2-1 }}" y="14">{{ right.text }}</text> | ||
</g> | ||
</svg> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<svg xmlns="http://www.w3.org/2000/svg" width="{{ left.width + right.width }}" height="20"> | ||
<linearGradient id="smooth" x2="0" y2="100%"> | ||
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/> | ||
<stop offset="1" stop-opacity=".1"/> | ||
</linearGradient> | ||
<rect rx="3" width="{{ left.width + right.width }}" height="20" fill="{{ left.color }}"/> | ||
<rect rx="3" x="{{ left.width }}" width="{{ right.width }}" height="20" fill="{{ right.color }}"/> | ||
<rect x="{{ left.width }}" width="4" height="20" fill="{{ right.color }}"/> | ||
<rect rx="3" width="{{ left.width + right.width }}" height="20" fill="url(#smooth)"/> | ||
<g fill="#fff" text-anchor="middle" font-family="{{config.font_face}},Verdana,Geneva,sans-serif" font-size="{{config.font_size}}"> | ||
<text x="{{ left.width/2+1 }}" y="15" fill="#010101" fill-opacity=".3">{{ left.text }}</text> | ||
<text x="{{ left.width/2+1 }}" y="14">{{ left.text }}</text> | ||
<text x="{{ left.width+right.width/2-1 }}" y="15" fill="#010101" fill-opacity=".3">{{ right.text }}</text> | ||
<text x="{{ left.width+right.width/2-1 }}" y="14">{{ right.text }}</text> | ||
</g> | ||
</svg> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<svg xmlns="http://www.w3.org/2000/svg" width="{{ left.width + right.width }}" height="18"> | ||
<linearGradient id="smooth" x2="0" y2="100%"> | ||
<stop offset="0" stop-color="#fff" stop-opacity=".7"/> | ||
<stop offset=".1" stop-color="#aaa" stop-opacity=".1"/> | ||
<stop offset=".9" stop-color="#000" stop-opacity=".3"/> | ||
<stop offset="1" stop-color="#000" stop-opacity=".5"/> | ||
</linearGradient> | ||
<rect rx="4" width="{{ left.width + right.width }}" height="18" fill="{{ left.color }}"/> | ||
<rect rx="4" x="{{ left.width }}" width="{{ right.width }}" height="18" fill="{{ right.color }}"/> | ||
<rect x="{{ left.width }}" width="4" height="18" fill="{{ right.color }}"/> | ||
<rect rx="4" width="{{ left.width+right.width }}" height="18" fill="url(#smooth)"/> | ||
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> | ||
<text x="{{ left.width/2+1 }}" y="14" fill="#010101" fill-opacity=".3">{{ left.text }}</text> | ||
<text x="{{ left.width/2+1 }}" y="13">{{ left.text }}</text> | ||
<text x="{{ left.width+right.width/2-1 }}" y="14" fill="#010101" fill-opacity=".3">{{ right.text }}</text> | ||
<text x="{{ left.width+right.width/2-1 }}" y="13">{{ right.text }}</text> | ||
</g> | ||
</svg> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python | ||
# | ||
# This file is part of Buildbot. Buildbot is free software: you can | ||
# redistribute it and/or modify it under the terms of the GNU General Public | ||
# License as published by the Free Software Foundation, version 2. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, write to the Free Software Foundation, Inc., 51 | ||
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
# Copyright Buildbot Team Members | ||
|
||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
try: | ||
from buildbot_pkg import setup_www_plugin | ||
except ImportError: | ||
import sys | ||
print("Please install buildbot_pkg module in order to install that package, or use the pre-build .whl modules available on pypi", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
setup_www_plugin( | ||
name='buildbot-badges', | ||
description='Buildbot badges', | ||
author=u'Buildbot Team Members', | ||
author_email=u'users@buildbot.net', | ||
url='http://buildbot.net/', | ||
license='GNU GPL', | ||
packages=['buildbot_badges'], | ||
install_requires=[ | ||
'klein', | ||
'CairoSVG==1.0.22', # cairoSVG 2+ is not py2 compatible | ||
'cairocffi', 'Jinja2' | ||
], | ||
package_data={ | ||
'': [ | ||
'VERSION', 'templates/*.svg.j2' | ||
], | ||
}, | ||
entry_points=""" | ||
[buildbot.www] | ||
badges = buildbot_badges:ep | ||
""", | ||
) |