view talosnames/web.py @ 23:5f39ce13fbbc

what i meant
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 10 Jul 2012 19:08:06 -0700
parents 82d15f93cc4a
children 56d267d847e1
line wrap: on
line source

#!/usr/bin/env python

"""
web handler for talosnames
"""

import os
import pprint
import tempita
from api import TalosNames
from webob import Request, Response, exc

here = os.path.dirname(os.path.abspath(__file__))
template = os.path.join(here, 'templates', 'index.html')

class Handler(object):

    def __init__(self, **kw):
        self.api = TalosNames()
        self.template = file(template).read()

    def __call__(self, environ, start_response):
        request = Request(environ)
        response = Response(content_type='text/html',
                            body=self.render())
        return response(environ, start_response)

    def render(self):
        template = tempita.HTMLTemplate(self.template)
        suites = sorted(self.api.suites.keys())
        tests = {}
        for suite in suites:
            try:
                test = self.api.test_config(suite)
                tests[suite] = test
            except:
                tests[suite] = None

        data = {'suites': suites,
                'commands': self.api.buildbot_commands,
                'tbpl': dict([(suite, self.api.tbpl_name(suite))
                              for suite in suites]),
                'tests': tests,
                'pprint': pprint.pformat
                }
        return template.substitute(data)

if __name__ == '__main__':
    from wsgiref import simple_server
    app = Handler()
    server = simple_server.make_server(host='0.0.0.0', port=8080, app=app)
    server.serve_forever()