view talosnames/web.py @ 35:88d280049e2f

stub parsing options
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 23 Jul 2012 13:57:14 -0700
parents 1a9ec766f2b0
children c945731f06d0
line wrap: on
line source

#!/usr/bin/env python

"""
web handler for talosnames
"""

import optparse
import os
import pprint
import tempita
from api import TalosNames
from subprocess import list2cmdline
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()

        # get data
        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

        self.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,
                     'list2cmdline': list2cmdline
                     }

        paint = {}
        chrome = {}
        graphserver = {}
        for suite in suites:
            for test in tests.get(suite) or []:
                config = self.api.talos_config(suite)
                _paint = '--mozAfterPaint' in self.data['commands'][suite]
                _chrome = '--noChrome' not in self.data['commands'][suite]
                extension = config.get('test_name_extension', '')
                _extension = ''
                if not _chrome:
                    _extension += '_nochrome'
                if _paint:
                    _extension += '_paint'
                if extension != _extension:
                    raise AssertionError
                paint[suite] = _paint
                chrome[suite] = _chrome
                graphserver.setdefault(suite, {})[test] = [self.api.graphserver_name(test + extension) or ('','')]
        self.data['graphserver'] = graphserver
        self.data['paint'] = paint
        self.data['chrome'] = chrome

    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):
        contents = file(template).read()
        _template = tempita.HTMLTemplate(contents)
        return _template.substitute(self.data)

if __name__ == '__main__':

    parser = optparse.OptionParser()
    options, args = parser.parse_args()

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