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