Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(739)

Side by Side Diff: mojo/devtools/common/devtoolslib/http_server.py

Issue 1139053005: Add ServeLocalDirectory to the shell abstraction. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Address Ben's comments. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 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 atexit 5 import atexit
6 import datetime 6 import datetime
7 import email.utils 7 import email.utils
8 import hashlib 8 import hashlib
9 import logging 9 import logging
10 import math 10 import math
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return os.path.join(base_path, os.path.relpath(path_from_current)) 119 return os.path.join(base_path, os.path.relpath(path_from_current))
120 120
121 def log_message(self, *_): 121 def log_message(self, *_):
122 """Override the base class method to disable logging.""" 122 """Override the base class method to disable logging."""
123 pass 123 pass
124 124
125 RequestHandler.protocol_version = 'HTTP/1.1' 125 RequestHandler.protocol_version = 'HTTP/1.1'
126 return RequestHandler 126 return RequestHandler
127 127
128 128
129 def StartHttpServer(path): 129 def StartHttpServer(local_dir_path, host_port=0):
130 """Starts an http server serving files from |path| on random 130 """Starts an http server serving files from |path| on |host_port|. Pass 0
131 (system-allocated) port. Returns the server address. 131 as |host_port| to use a system-allocated port.
132
133 Returns:
134 Tuple of the server address and the port on which it runs.
132 """ 135 """
133 assert path 136 assert local_dir_path
134 httpd = _SilentTCPServer(('127.0.0.1', 0), _GetHandlerClassForPath(path)) 137 httpd = _SilentTCPServer(('127.0.0.1', host_port),
138 _GetHandlerClassForPath(local_dir_path))
135 atexit.register(httpd.shutdown) 139 atexit.register(httpd.shutdown)
136 140
137 http_thread = threading.Thread(target=httpd.serve_forever) 141 http_thread = threading.Thread(target=httpd.serve_forever)
138 http_thread.daemon = True 142 http_thread.daemon = True
139 http_thread.start() 143 http_thread.start()
140 return httpd.server_address 144 return httpd.server_address
OLDNEW
« no previous file with comments | « mojo/devtools/common/devtoolslib/android_shell.py ('k') | mojo/devtools/common/devtoolslib/linux_shell.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698