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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 self.send_response(response.status) | 58 self.send_response(response.status) |
59 for k, v in response.headers.iteritems(): | 59 for k, v in response.headers.iteritems(): |
60 self.send_header(k, v) | 60 self.send_header(k, v) |
61 self.end_headers() | 61 self.end_headers() |
62 self.wfile.write(response.content.ToString()) | 62 self.wfile.write(response.content.ToString()) |
63 | 63 |
64 if __name__ == '__main__': | 64 if __name__ == '__main__': |
65 parser = optparse.OptionParser( | 65 parser = optparse.OptionParser( |
66 description='Runs a server to preview the extension documentation.', | 66 description='Runs a server to preview the extension documentation.', |
67 usage='usage: %prog [option]...') | 67 usage='usage: %prog [option]...') |
| 68 parser.add_option('-a', '--address', default='127.0.0.1', |
| 69 help='the local interface address to bind the server to') |
68 parser.add_option('-p', '--port', default='8000', | 70 parser.add_option('-p', '--port', default='8000', |
69 help='port to run the server on') | 71 help='port to run the server on') |
70 parser.add_option('-r', '--render', default='', | 72 parser.add_option('-r', '--render', default='', |
71 help='statically render a page and print to stdout rather than starting ' | 73 help='statically render a page and print to stdout rather than starting ' |
72 'the server, e.g. apps/storage.html. The path may optionally end ' | 74 'the server, e.g. apps/storage.html. The path may optionally end ' |
73 'with #n where n is the number of times to render the page before ' | 75 'with #n where n is the number of times to render the page before ' |
74 'printing it, e.g. apps/storage.html#50, to use for profiling.') | 76 'printing it, e.g. apps/storage.html#50, to use for profiling.') |
75 parser.add_option('-s', '--stat', | 77 parser.add_option('-s', '--stat', |
76 help='Print profile stats at the end of the run using the given ' | 78 help='Print profile stats at the end of the run using the given ' |
77 'profiling option (like "tottime"). -t is ignored if this is set.') | 79 'profiling option (like "tottime"). -t is ignored if this is set.') |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 print('The extension documentation can be found at:') | 121 print('The extension documentation can be found at:') |
120 print('') | 122 print('') |
121 print(' http://localhost:%s/extensions/' % opts.port) | 123 print(' http://localhost:%s/extensions/' % opts.port) |
122 print('') | 124 print('') |
123 print('The apps documentation can be found at:') | 125 print('The apps documentation can be found at:') |
124 print('') | 126 print('') |
125 print(' http://localhost:%s/apps/' % opts.port) | 127 print(' http://localhost:%s/apps/' % opts.port) |
126 print('') | 128 print('') |
127 | 129 |
128 logging.getLogger().setLevel(logging.INFO) | 130 logging.getLogger().setLevel(logging.INFO) |
129 server = HTTPServer(('', int(opts.port)), _RequestHandler) | 131 server = HTTPServer((opts.address, int(opts.port)), _RequestHandler) |
130 try: | 132 try: |
131 server.serve_forever() | 133 server.serve_forever() |
132 finally: | 134 finally: |
133 server.socket.close() | 135 server.socket.close() |
OLD | NEW |