|
| 1 | +import urllib, urllib2 |
| 2 | +import json |
| 3 | + |
| 4 | +from PIL import Image, ImageDraw |
| 5 | +import StringIO |
| 6 | + |
| 7 | +import webapp2 |
| 8 | + |
| 9 | +PLATFORMS_ALL = ['Mac', 'Linux', 'Win'] |
| 10 | + |
| 11 | + |
| 12 | +class BuildStatusHandler(webapp2.RequestHandler): |
| 13 | + |
| 14 | + def get_last_build(self, project, platform): |
| 15 | + url = 'http://build.chromium.org/p/client.polymer/json/builders/' + urllib.quote('%s %s' % (project, platform)) + '/builds/-1' |
| 16 | + return json.load(urllib2.urlopen(url)) |
| 17 | + |
| 18 | + def last_build_is_successful(self, project, platform, browser): |
| 19 | + success = True |
| 20 | + build = self.get_last_build(project, platform) |
| 21 | + foundTest = False |
| 22 | + for step in build['steps']: |
| 23 | + if foundTest: |
| 24 | + if step['results'][0] != 0: |
| 25 | + if browser == 'all' or step['text'][0].find(browser) != -1: |
| 26 | + success = False |
| 27 | + break |
| 28 | + elif step['name'] == 'test': |
| 29 | + if step['results'][0] != 0: |
| 30 | + success = False |
| 31 | + break |
| 32 | + else: |
| 33 | + foundTest = True |
| 34 | + return success |
| 35 | + |
| 36 | + def get(self, project, platform='all', browser='all'): |
| 37 | + success = True |
| 38 | + if platform == 'all': |
| 39 | + for plat in PLATFORMS_ALL: |
| 40 | + if not self.last_build_is_successful(project, plat, browser): |
| 41 | + success = False |
| 42 | + break |
| 43 | + else: |
| 44 | + success = self.last_build_is_successful(project, platform, browser) |
| 45 | + |
| 46 | + if success: |
| 47 | + color = 'rgb(0, 169, 92)' |
| 48 | + status = 'passing' |
| 49 | + else: |
| 50 | + color = 'rgb(216, 68, 55)' |
| 51 | + status = 'failing' |
| 52 | + image = Image.new("RGBA", (120, 20)) |
| 53 | + draw = ImageDraw.Draw(image) |
| 54 | + draw.polygon([(1, 1), (89, 1), (89, 19), (1, 19)], 'white', 'rgb(127, 127, 127)') |
| 55 | + draw.polygon([(37, 3), (87, 3), (87, 18), (37, 18)], color) |
| 56 | + draw.text((5, 5), 'build', 'rgb(127, 127, 127)') |
| 57 | + draw.text((41, 5), status, 'white') |
| 58 | + |
| 59 | + output = StringIO.StringIO() |
| 60 | + image.save(output, format="png") |
| 61 | + layer = output.getvalue() |
| 62 | + output.close() |
| 63 | + |
| 64 | + self.response.headers['Content-Type'] = 'image/png' |
| 65 | + self.response.write(layer) |
| 66 | + |
| 67 | + |
| 68 | +application = webapp2.WSGIApplication([ |
| 69 | + webapp2.Route('/build/<project>/status.png', BuildStatusHandler), |
| 70 | + webapp2.Route('/build/<project>/<platform>/status.png', BuildStatusHandler), |
| 71 | + webapp2.Route('/build/<project>/<platform>/<browser>/status.png', BuildStatusHandler), |
| 72 | +], debug=False) |
0 commit comments