| 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 |
| 11 # a webserver is started on a port (default 8000). Navigating to paths on | 11 # a webserver is started on a port (default 8000). Navigating to paths on |
| 12 # http://localhost:8000, for example | 12 # http://localhost:8000, for example |
| 13 # | 13 # |
| 14 # http://localhost:8000/extensions/tabs.html | 14 # http://localhost:8000/extensions/tabs.html |
| 15 # | 15 # |
| 16 # will render the documentation for the extension tabs API. | 16 # will render the documentation for the extension tabs API. |
| 17 # | 17 # |
| 18 # On the other hand, render mode statically renders docs to stdout. Use this | 18 # On the other hand, render mode statically renders docs to stdout. Use this |
| 19 # to save the output (more convenient than needing to save the page in a | 19 # to save the output (more convenient than needing to save the page in a |
| 20 # browser), handy when uploading the docs somewhere (e.g. for a review), | 20 # browser), handy when uploading the docs somewhere (e.g. for a review), |
| 21 # and for profiling the server. For example, | 21 # and for profiling the server. For example, |
| 22 # | 22 # |
| 23 # ./preview.py -r extensions/tabs.html | 23 # ./preview.py -r extensions/tabs.html |
| 24 # | 24 # |
| 25 # will output the documentation for the tabs API on stdout and exit immediately. | 25 # will output the documentation for the tabs API on stdout and exit immediately. |
| 26 # | |
| 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. | |
| 29 | 26 |
| 30 # NOTE: RUN THIS FIRST. Or all third_party imports will fail. | 27 # NOTE: RUN THIS FIRST. Or all third_party imports will fail. |
| 31 import build_server | 28 import build_server |
| 32 # Copy all the files necessary to run the server. These are cleaned up when the | 29 # Copy all the files necessary to run the server. These are cleaned up when the |
| 33 # server quits. | 30 # server quits. |
| 34 build_server.main() | 31 build_server.main() |
| 35 | 32 |
| 36 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer | 33 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer |
| 37 import logging | 34 import logging |
| 38 import optparse | 35 import optparse |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 if response.status != 200: | 81 if response.status != 200: |
| 85 print('Error status: %s' % response.status) | 82 print('Error status: %s' % response.status) |
| 86 exit(1) | 83 exit(1) |
| 87 | 84 |
| 88 for _ in range(extra_iterations): | 85 for _ in range(extra_iterations): |
| 89 LocalRenderer.Render(path) | 86 LocalRenderer.Render(path) |
| 90 | 87 |
| 91 if opts.time: | 88 if opts.time: |
| 92 print('Took %s seconds' % (time.time() - start_time)) | 89 print('Took %s seconds' % (time.time() - start_time)) |
| 93 else: | 90 else: |
| 94 # Static paths will show up as /trunk/static/foo but this only makes | 91 print(response.content.ToString()) |
| 95 # sense from a webserver. | |
| 96 print(response.content.ToString().replace('/trunk/', '')) | |
| 97 exit() | 92 exit() |
| 98 | 93 |
| 99 print('Starting previewserver on port %s' % opts.port) | 94 print('Starting previewserver on port %s' % opts.port) |
| 100 print('') | 95 print('') |
| 101 print('The extension documentation can be found at:') | 96 print('The extension documentation can be found at:') |
| 102 print('') | 97 print('') |
| 103 print(' http://localhost:%s/extensions/' % opts.port) | 98 print(' http://localhost:%s/extensions/' % opts.port) |
| 104 print('') | 99 print('') |
| 105 print('The apps documentation can be found at:') | 100 print('The apps documentation can be found at:') |
| 106 print('') | 101 print('') |
| 107 print(' http://localhost:%s/apps/' % opts.port) | 102 print(' http://localhost:%s/apps/' % opts.port) |
| 108 print('') | 103 print('') |
| 109 | 104 |
| 110 logging.getLogger().setLevel(logging.INFO) | 105 logging.getLogger().setLevel(logging.INFO) |
| 111 server = HTTPServer(('', int(opts.port)), _RequestHandler) | 106 server = HTTPServer(('', int(opts.port)), _RequestHandler) |
| 112 try: | 107 try: |
| 113 server.serve_forever() | 108 server.serve_forever() |
| 114 finally: | 109 finally: |
| 115 server.socket.close() | 110 server.socket.close() |
| OLD | NEW |