forked from Polymer/old-docs-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
80 lines (66 loc) · 2.7 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# @license
# Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
# This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
# The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
# The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
# Code distributed by Google as part of the polymer project is also
# subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
import urllib, urllib2
import json
from PIL import Image, ImageDraw
import StringIO
import webapp2
PLATFORMS_ALL = ['Mac', 'Linux', 'Win']
class BuildStatusHandler(webapp2.RequestHandler):
def get_last_build(self, project, platform):
url = 'http://build.chromium.org/p/client.polymer/json/builders/' + urllib.quote('%s %s' % (project, platform)) + '/builds/-1'
return json.load(urllib2.urlopen(url))
def last_build_is_successful(self, project, platform, browser):
success = True
build = self.get_last_build(project, platform)
foundTest = False
for step in build['steps']:
if foundTest:
if step['results'][0] != 0:
if browser == 'all' or step['text'][0].find(browser) != -1:
success = False
break
elif step['name'] == 'test':
if step['results'][0] != 0:
success = False
break
else:
foundTest = True
return success
def get(self, project, platform='all', browser='all'):
success = True
if platform == 'all':
for plat in PLATFORMS_ALL:
if not self.last_build_is_successful(project, plat, browser):
success = False
break
else:
success = self.last_build_is_successful(project, platform, browser)
if success:
color = 'rgb(0, 169, 92)'
status = 'passing'
else:
color = 'rgb(216, 68, 55)'
status = 'failing'
image = Image.new("RGBA", (120, 20))
draw = ImageDraw.Draw(image)
draw.polygon([(1, 1), (89, 1), (89, 19), (1, 19)], 'white', 'rgb(127, 127, 127)')
draw.polygon([(37, 3), (87, 3), (87, 18), (37, 18)], color)
draw.text((5, 5), 'build', 'rgb(127, 127, 127)')
draw.text((41, 5), status, 'white')
output = StringIO.StringIO()
image.save(output, format="png")
layer = output.getvalue()
output.close()
self.response.headers['Content-Type'] = 'image/png'
self.response.write(layer)
application = webapp2.WSGIApplication([
webapp2.Route('/build/<project>/status.png', BuildStatusHandler),
webapp2.Route('/build/<project>/<platform>/status.png', BuildStatusHandler),
webapp2.Route('/build/<project>/<platform>/<browser>/status.png', BuildStatusHandler),
], debug=False)