| OLD | NEW |
| 1 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import argparse | 5 import argparse |
| 6 import json | 6 import json |
| 7 import os | 7 import os |
| 8 import sys | 8 import sys |
| 9 | 9 |
| 10 from hooks import install | 10 from hooks import install |
| 11 | 11 |
| 12 from paste import fileapp | 12 from paste import fileapp |
| 13 from paste import httpserver | 13 from paste import httpserver |
| 14 | 14 |
| 15 import webapp2 | 15 import webapp2 |
| 16 from webapp2 import Route, RedirectHandler | 16 from webapp2 import Route, RedirectHandler |
| 17 | 17 |
| 18 from perf_insights_build import perf_insights_dev_server_config | 18 from perf_insights_build import perf_insights_dev_server_config |
| 19 from tracing_build import tracing_dev_server_config | 19 from tracing_build import tracing_dev_server_config |
| 20 | 20 |
| 21 _UNIT_TEST_HTML = """<html><body> | 21 _MAIN_HTML = """<html><body> |
| 22 <h1>Run Unit Tests</h1> | 22 <h1>Run Unit Tests</h1> |
| 23 <ul> | 23 <ul> |
| 24 %s | 24 %s |
| 25 </ul> | 25 </ul> |
| 26 <h1>Quick links</h1> |
| 27 <ul> |
| 28 %s |
| 29 </ul> |
| 26 </body></html> | 30 </body></html> |
| 27 """ | 31 """ |
| 28 | 32 |
| 29 _UNIT_TEST_LINK = '<li><a href="%s">%s</a></li>' | 33 _QUICK_LINKS = [ |
| 34 ('Trace File Viewer', '/tracing_examples/trace_viewer.html') |
| 35 ] |
| 30 | 36 |
| 37 _LINK_ITEM = '<li><a href="%s">%s</a></li>' |
| 31 | 38 |
| 32 def _GetFilesIn(basedir): | 39 def _GetFilesIn(basedir): |
| 33 data_files = [] | 40 data_files = [] |
| 34 for dirpath, dirnames, filenames in os.walk(basedir, followlinks=True): | 41 for dirpath, dirnames, filenames in os.walk(basedir, followlinks=True): |
| 35 new_dirnames = [d for d in dirnames if not d.startswith('.')] | 42 new_dirnames = [d for d in dirnames if not d.startswith('.')] |
| 36 del dirnames[:] | 43 del dirnames[:] |
| 37 dirnames += new_dirnames | 44 dirnames += new_dirnames |
| 38 | 45 |
| 39 for f in filenames: | 46 for f in filenames: |
| 40 if f.startswith('.'): | 47 if f.startswith('.'): |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 if not joined_path.startswith(top_path): | 128 if not joined_path.startswith(top_path): |
| 122 self.response.set_status(403) | 129 self.response.set_status(403) |
| 123 return | 130 return |
| 124 app = FileAppWithGZipHandling(joined_path) | 131 app = FileAppWithGZipHandling(joined_path) |
| 125 app.cache_control(no_cache=True) | 132 app.cache_control(no_cache=True) |
| 126 return app | 133 return app |
| 127 | 134 |
| 128 | 135 |
| 129 class TestOverviewHandler(webapp2.RequestHandler): | 136 class TestOverviewHandler(webapp2.RequestHandler): |
| 130 def get(self, *args, **kwargs): # pylint: disable=unused-argument | 137 def get(self, *args, **kwargs): # pylint: disable=unused-argument |
| 131 links = [] | 138 test_links = [] |
| 132 for name, path in kwargs.pop('pds').iteritems(): | 139 for name, path in kwargs.pop('pds').iteritems(): |
| 133 links.append(_UNIT_TEST_LINK % (path, name)) | 140 test_links.append(_LINK_ITEM % (path, name)) |
| 134 self.response.out.write(_UNIT_TEST_HTML % '\n'.join(links)) | 141 quick_links = [] |
| 142 for name, path in _QUICK_LINKS: |
| 143 quick_links.append(_LINK_ITEM % (path, name)) |
| 144 self.response.out.write(_MAIN_HTML % ('\n'.join(test_links), |
| 145 '\n'.join(quick_links))) |
| 135 | 146 |
| 136 | 147 |
| 137 def CreateApp(pds, args): | 148 def CreateApp(pds, args): |
| 138 default_tests = dict((pd.GetName(), pd.GetRunUnitTestsUrl()) for pd in pds) | 149 default_tests = dict((pd.GetName(), pd.GetRunUnitTestsUrl()) for pd in pds) |
| 139 routes = [ | 150 routes = [ |
| 140 Route('/tests.html', TestOverviewHandler, defaults={'pds': default_tests}), | 151 Route('/tests.html', TestOverviewHandler, defaults={'pds': default_tests}), |
| 141 Route('', RedirectHandler, defaults={'_uri': '/tests.html'}), | 152 Route('', RedirectHandler, defaults={'_uri': '/tests.html'}), |
| 142 Route('/', RedirectHandler, defaults={'_uri': '/tests.html'}), | 153 Route('/', RedirectHandler, defaults={'_uri': '/tests.html'}), |
| 143 ] | 154 ] |
| 144 for pd in pds: | 155 for pd in pds: |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 app = CreateApp(pds, args) | 243 app = CreateApp(pds, args) |
| 233 | 244 |
| 234 server = httpserver.serve(app, host='127.0.0.1', port=args.port, | 245 server = httpserver.serve(app, host='127.0.0.1', port=args.port, |
| 235 start_loop=False) | 246 start_loop=False) |
| 236 _AddPleaseExitMixinToServer(server) | 247 _AddPleaseExitMixinToServer(server) |
| 237 app.server = server | 248 app.server = server |
| 238 | 249 |
| 239 sys.stderr.write('Now running on http://127.0.0.1:%i\n' % server.server_port) | 250 sys.stderr.write('Now running on http://127.0.0.1:%i\n' % server.server_port) |
| 240 | 251 |
| 241 return server.serve_forever() | 252 return server.serve_forever() |
| OLD | NEW |