Mercurial > mozilla > hg > talosnames
annotate talosnames/web.py @ 24:56d267d847e1
more progress
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 10 Jul 2012 21:36:24 -0700 |
parents | 82d15f93cc4a |
children | 6ec941f8704a |
rev | line source |
---|---|
0 | 1 #!/usr/bin/env python |
2 | |
3 """ | |
4 web handler for talosnames | |
5 """ | |
6 | |
19
aae0a420c4f7
should now actually do something
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
7 import os |
22 | 8 import pprint |
19
aae0a420c4f7
should now actually do something
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
9 import tempita |
18 | 10 from api import TalosNames |
0 | 11 from webob import Request, Response, exc |
12 | |
19
aae0a420c4f7
should now actually do something
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
13 here = os.path.dirname(os.path.abspath(__file__)) |
aae0a420c4f7
should now actually do something
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
14 template = os.path.join(here, 'templates', 'index.html') |
aae0a420c4f7
should now actually do something
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
15 |
0 | 16 class Handler(object): |
17 | |
18 def __init__(self, **kw): | |
18 | 19 self.api = TalosNames() |
19
aae0a420c4f7
should now actually do something
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
20 self.template = file(template).read() |
0 | 21 |
22 def __call__(self, environ, start_response): | |
23 request = Request(environ) | |
20 | 24 response = Response(content_type='text/html', |
19
aae0a420c4f7
should now actually do something
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
25 body=self.render()) |
0 | 26 return response(environ, start_response) |
27 | |
19
aae0a420c4f7
should now actually do something
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
28 def render(self): |
aae0a420c4f7
should now actually do something
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
29 template = tempita.HTMLTemplate(self.template) |
21 | 30 suites = sorted(self.api.suites.keys()) |
31 tests = {} | |
32 for suite in suites: | |
33 try: | |
34 test = self.api.test_config(suite) | |
35 tests[suite] = test | |
36 except: | |
37 tests[suite] = None | |
38 | |
39 data = {'suites': suites, | |
40 'commands': self.api.buildbot_commands, | |
41 'tbpl': dict([(suite, self.api.tbpl_name(suite)) | |
42 for suite in suites]), | |
22 | 43 'tests': tests, |
24 | 44 'pprint': pprint.pformat, |
45 'api': self.api | |
21 | 46 } |
20 | 47 return template.substitute(data) |
19
aae0a420c4f7
should now actually do something
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
48 |
0 | 49 if __name__ == '__main__': |
50 from wsgiref import simple_server | |
51 app = Handler() | |
52 server = simple_server.make_server(host='0.0.0.0', port=8080, app=app) | |
53 server.serve_forever() | |
54 | |
18 | 55 |