Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 # This helps you preview the apps and extensions docs. | 6 # This helps you preview the apps and extensions docs. |
| 7 # | 7 # |
| 8 # ./preview.py --help | 8 # ./preview.py --help |
| 9 # | 9 # |
| 10 # There are two modes: server- and render- mode. The default is server, in which | 10 # There are two modes: server- and render- mode. The default is server, in which |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 # Note: absolute paths into static content (e.g. /static/css/site.css) will be | 27 # Note: absolute paths into static content (e.g. /static/css/site.css) will be |
| 28 # relative paths (e.g. static/css/site.css) for convenient sandboxing. | 28 # relative paths (e.g. static/css/site.css) for convenient sandboxing. |
| 29 | 29 |
| 30 # NOTE: RUN THIS FIRST. Or all third_party imports will fail. | 30 # NOTE: RUN THIS FIRST. Or all third_party imports will fail. |
| 31 import build_server | 31 import build_server |
| 32 # Copy all the files necessary to run the server. These are cleaned up when the | 32 # Copy all the files necessary to run the server. These are cleaned up when the |
| 33 # server quits. | 33 # server quits. |
| 34 build_server.main() | 34 build_server.main() |
| 35 | 35 |
| 36 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer | 36 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer |
| 37 from fake_fetchers import ConfigureFakeFetchers | |
| 37 import logging | 38 import logging |
| 38 import optparse | 39 import optparse |
| 39 import os | 40 import os |
| 40 import sys | 41 import sys |
| 41 import time | 42 import time |
| 42 | 43 |
| 43 from local_renderer import LocalRenderer | 44 from local_renderer import LocalRenderer |
| 44 | 45 |
| 45 class _RequestHandler(BaseHTTPRequestHandler): | 46 class _RequestHandler(BaseHTTPRequestHandler): |
| 46 '''A HTTPRequestHandler that outputs the docs page generated by Handler. | 47 '''A HTTPRequestHandler that outputs the docs page generated by Handler. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 62 parser.add_option('-r', '--render', default='', | 63 parser.add_option('-r', '--render', default='', |
| 63 help='statically render a page and print to stdout rather than starting ' | 64 help='statically render a page and print to stdout rather than starting ' |
| 64 'the server, e.g. apps/storage.html. The path may optionally end ' | 65 'the server, e.g. apps/storage.html. The path may optionally end ' |
| 65 'with #n where n is the number of times to render the page before ' | 66 'with #n where n is the number of times to render the page before ' |
| 66 'printing it, e.g. apps/storage.html#50, to use for profiling.') | 67 'printing it, e.g. apps/storage.html#50, to use for profiling.') |
| 67 parser.add_option('-t', '--time', action='store_true', | 68 parser.add_option('-t', '--time', action='store_true', |
| 68 help='Print the time taken rendering rather than the result.') | 69 help='Print the time taken rendering rather than the result.') |
| 69 | 70 |
| 70 (opts, argv) = parser.parse_args() | 71 (opts, argv) = parser.parse_args() |
| 71 | 72 |
| 73 ConfigureFakeFetchers() | |
|
not at google - send to devlin
2013/05/16 18:56:15
shouldn't be needed. make LocalRenderer use a fake
epeterson
2013/06/02 00:25:50
Done.
| |
| 74 | |
| 72 if opts.render: | 75 if opts.render: |
| 73 if opts.render.find('#') >= 0: | 76 if opts.render.find('#') >= 0: |
| 74 (path, iterations) = opts.render.rsplit('#', 1) | 77 (path, iterations) = opts.render.rsplit('#', 1) |
| 75 extra_iterations = int(iterations) - 1 | 78 extra_iterations = int(iterations) - 1 |
| 76 else: | 79 else: |
| 77 path = opts.render | 80 path = opts.render |
| 78 extra_iterations = 0 | 81 extra_iterations = 0 |
| 79 | 82 |
| 80 if opts.time: | 83 if opts.time: |
| 81 start_time = time.time() | 84 start_time = time.time() |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 106 print('') | 109 print('') |
| 107 print(' http://localhost:%s/apps/' % opts.port) | 110 print(' http://localhost:%s/apps/' % opts.port) |
| 108 print('') | 111 print('') |
| 109 | 112 |
| 110 logging.getLogger().setLevel(logging.INFO) | 113 logging.getLogger().setLevel(logging.INFO) |
| 111 server = HTTPServer(('', int(opts.port)), _RequestHandler) | 114 server = HTTPServer(('', int(opts.port)), _RequestHandler) |
| 112 try: | 115 try: |
| 113 server.serve_forever() | 116 server.serve_forever() |
| 114 finally: | 117 finally: |
| 115 server.socket.close() | 118 server.socket.close() |
| OLD | NEW |