# HG changeset patch # User Jeff Hammel # Date 1344897692 25200 # Node ID 11249e75ced64cff97972ff2d0a784e22962dcc2 # Parent fcd98303a90d9bc6a59c5c5e847d80bd6c56f639 allow more than one template path diff -r fcd98303a90d -r 11249e75ced6 setup.py --- a/setup.py Mon Aug 13 15:14:53 2012 -0700 +++ b/setup.py Mon Aug 13 15:41:32 2012 -0700 @@ -7,6 +7,11 @@ version = "0.0" dependencies = ['webob', 'CommandParser', 'talos', 'buildbot', 'PyYAML'] +try: + import json +except ImportError: + dependencies.append('simplejson') + # allow use of setuptools/distribute or distutils kw = {} try: diff -r fcd98303a90d -r 11249e75ced6 talosnames/web.py --- a/talosnames/web.py Mon Aug 13 15:14:53 2012 -0700 +++ b/talosnames/web.py Mon Aug 13 15:41:32 2012 -0700 @@ -14,12 +14,19 @@ from subprocess import list2cmdline from webob import Request, Response, exc +try: + import json +except ImportError: + import simplejson as json + here = os.path.dirname(os.path.abspath(__file__)) -template = os.path.join(here, 'templates', 'index.html') class Handler(object): + paths = {'tbpl': 'tbpl.html'} + def __init__(self, **kw): + self.api = TalosNames() # get data @@ -39,7 +46,6 @@ 'tbpl': dict([(suite, self.api.tbpl_name(suite)) for suite in suites]), 'tests': tests, - 'list2cmdline': list2cmdline } paint = {} @@ -85,13 +91,17 @@ self.data['chrome'] = chrome self.data['test_type'] = test_type + self.data['json'] = json.dumps(self.data) + + self.data['list2cmdline'] = list2cmdline + def __call__(self, environ, start_response): request = Request(environ) response = Response(content_type='text/html', - body=self.render(request)) + body=self.render(request.path_info, request)) return response(environ, start_response) - def render(self, request=None): + def render(self, template='index.html', request=None): # make a local copy of the data data = self.data.copy() @@ -120,10 +130,16 @@ data['suites'] = [i for i in data['suites'] if not data['enabled'][i]] + path = self.template_path(template) + contents = file(path).read() + template = tempita.HTMLTemplate(contents) + return template.substitute(data) - contents = file(template).read() - _template = tempita.HTMLTemplate(contents) - return _template.substitute(data) + def template_path(self, path): + """returns template path""" + path = path.strip('/') + template = self.paths.get(path, 'index.html') + return os.path.join(here, 'templates', template) def main(args=sys.argv[1:]): parser = optparse.OptionParser()