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 import BaseHTTPServer | 6 import BaseHTTPServer |
| 7 import logging | 7 import logging |
| 8 import multiprocessing | 8 import multiprocessing |
| 9 import optparse | 9 import argparse |
|
binji
2014/11/13 23:57:04
sort
Sam Clegg
2014/11/30 17:55:13
Done.
| |
| 10 import os | 10 import os |
| 11 import SimpleHTTPServer # pylint: disable=W0611 | 11 import SimpleHTTPServer # pylint: disable=W0611 |
| 12 import socket | 12 import socket |
| 13 import sys | 13 import sys |
| 14 import time | 14 import time |
| 15 import urlparse | 15 import urlparse |
| 16 | 16 |
| 17 if sys.version_info < (2, 6, 0): | 17 if sys.version_info < (2, 6, 0): |
|
binji
2014/11/13 23:57:04
2.7
Sam Clegg
2014/11/30 17:55:13
Seperate CL
| |
| 18 sys.stderr.write("python 2.6 or later is required run this script\n") | 18 sys.stderr.write("python 2.6 or later is required run this script\n") |
| 19 sys.exit(1) | 19 sys.exit(1) |
| 20 | 20 |
| 21 | 21 |
| 22 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 22 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 23 NACL_SDK_ROOT = os.path.dirname(SCRIPT_DIR) | 23 NACL_SDK_ROOT = os.path.dirname(SCRIPT_DIR) |
| 24 | 24 |
| 25 | 25 |
| 26 # We only run from the examples directory so that not too much is exposed | 26 # We only run from the examples directory so that not too much is exposed |
| 27 # via this HTTP server. Everything in the directory is served, so there should | 27 # via this HTTP server. Everything in the directory is served, so there should |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 if conn.poll(): | 178 if conn.poll(): |
| 179 httpd.running = conn.recv() | 179 httpd.running = conn.recv() |
| 180 except KeyboardInterrupt: | 180 except KeyboardInterrupt: |
| 181 pass | 181 pass |
| 182 finally: | 182 finally: |
| 183 conn.send(httpd.result) | 183 conn.send(httpd.result) |
| 184 conn.close() | 184 conn.close() |
| 185 | 185 |
| 186 | 186 |
| 187 def main(args): | 187 def main(args): |
| 188 parser = optparse.OptionParser() | 188 parser = argparse.ArgumentParser() |
| 189 parser.add_option('-C', '--serve-dir', | 189 parser.add_argument('-C', '--serve-dir', |
| 190 help='Serve files out of this directory.', | 190 help='Serve files out of this directory.', |
| 191 default=os.path.abspath('.')) | 191 default=os.path.abspath('.')) |
| 192 parser.add_option('-p', '--port', | 192 parser.add_argument('-p', '--port', |
| 193 help='Run server on this port.', default=5103) | 193 help='Run server on this port.', default=5103) |
| 194 parser.add_option('--no-dir-check', '--no_dir_check', | 194 parser.add_argument('--no-dir-check', '--no_dir_check', |
| 195 help='No check to ensure serving from safe directory.', | 195 help='No check to ensure serving from safe directory.', |
| 196 dest='do_safe_check', action='store_false', default=True) | 196 dest='do_safe_check', action='store_false', default=True) |
| 197 | 197 |
| 198 # To enable bash completion for this command first install optcomplete | 198 # To enable bash completion for this command first install optcomplete |
| 199 # and then add this line to your .bashrc: | 199 # and then add this line to your .bashrc: |
| 200 # complete -F _optcomplete httpd.py | 200 # complete -F _optcomplete httpd.py |
| 201 try: | 201 try: |
| 202 import optcomplete | 202 import optcomplete |
| 203 optcomplete.autocomplete(parser) | 203 optcomplete.autocomplete(parser) |
| 204 except ImportError: | 204 except ImportError: |
| 205 pass | 205 pass |
| 206 | 206 |
| 207 options, args = parser.parse_args(args) | 207 options, args = parser.parse_args(args) |
|
binji
2014/11/13 23:57:04
fix
Sam Clegg
2014/11/30 17:55:13
Done.
| |
| 208 if options.do_safe_check: | 208 if options.do_safe_check: |
| 209 SanityCheckDirectory(options.serve_dir) | 209 SanityCheckDirectory(options.serve_dir) |
| 210 | 210 |
| 211 server = LocalHTTPServer(options.serve_dir, int(options.port)) | 211 server = LocalHTTPServer(options.serve_dir, int(options.port)) |
| 212 | 212 |
| 213 # Serve until the client tells us to stop. When it does, it will give us an | 213 # Serve until the client tells us to stop. When it does, it will give us an |
| 214 # errorcode. | 214 # errorcode. |
| 215 print 'Serving %s on %s...' % (options.serve_dir, server.GetURL('')) | 215 print 'Serving %s on %s...' % (options.serve_dir, server.GetURL('')) |
| 216 return server.ServeForever() | 216 return server.ServeForever() |
| 217 | 217 |
| 218 if __name__ == '__main__': | 218 if __name__ == '__main__': |
| 219 sys.exit(main(sys.argv[1:])) | 219 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |