Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 itertools | 6 import itertools |
| 7 import json | 7 import json |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import os.path | 10 import os.path |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 "tcp:%d" % host_port])) | 135 "tcp:%d" % host_port])) |
| 136 | 136 |
| 137 unmap_command = self._CreateADBCommand(["reverse", "--remove", | 137 unmap_command = self._CreateADBCommand(["reverse", "--remove", |
| 138 "tcp:%d" % device_port]) | 138 "tcp:%d" % device_port]) |
| 139 | 139 |
| 140 def _UnmapPort(): | 140 def _UnmapPort(): |
| 141 subprocess.Popen(unmap_command) | 141 subprocess.Popen(unmap_command) |
| 142 atexit.register(_UnmapPort) | 142 atexit.register(_UnmapPort) |
| 143 return device_port | 143 return device_port |
| 144 | 144 |
| 145 def _StartHttpServerForDirectory(self, path, port=0): | 145 def _StartHttpServerForDirectory(self, path, device_port=0): |
| 146 """Starts an http server serving files from |path|. Returns the local | 146 """Starts an http server serving files from |path|. Returns the local |
| 147 url. | 147 url. |
| 148 """ | 148 """ |
| 149 assert path | 149 assert path |
| 150 print 'starting http for', path | 150 print 'starting http for', path |
| 151 server_address = StartHttpServer(path) | 151 server_address = StartHttpServer(path) |
| 152 | 152 |
| 153 print 'local port=%d' % server_address[1] | 153 print 'local port=%d' % server_address[1] |
| 154 return 'http://127.0.0.1:%d/' % self._MapPort(port, server_address[1]) | 154 return 'http://127.0.0.1:%d/' % self._MapPort(device_port, |
| 155 server_address[1]) | |
| 155 | 156 |
| 156 def _StartHttpServerForOriginMapping(self, mapping, port): | 157 def _StartHttpServerForOriginMapping(self, mapping, port): |
| 157 """If |mapping| points at a local file starts an http server to serve files | 158 """If |mapping| points at a local file starts an http server to serve files |
| 158 from the directory and returns the new mapping. | 159 from the directory and returns the new mapping. |
| 159 | 160 |
| 160 This is intended to be called for every --map-origin value. | 161 This is intended to be called for every --map-origin value. |
| 161 """ | 162 """ |
| 162 parts = mapping.split('=') | 163 parts = mapping.split('=') |
| 163 if len(parts) != 2: | 164 if len(parts) != 2: |
| 164 return mapping | 165 return mapping |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 def SetUpLocalOrigin(self, local_dir, fixed_port=True): | 217 def SetUpLocalOrigin(self, local_dir, fixed_port=True): |
| 217 """Sets up a local http server to serve files in |local_dir| along with | 218 """Sets up a local http server to serve files in |local_dir| along with |
| 218 device port forwarding. Returns the origin flag to be set when running the | 219 device port forwarding. Returns the origin flag to be set when running the |
| 219 shell. | 220 shell. |
| 220 """ | 221 """ |
| 221 | 222 |
| 222 origin_url = self._StartHttpServerForDirectory( | 223 origin_url = self._StartHttpServerForDirectory( |
| 223 local_dir, DEFAULT_BASE_PORT if fixed_port else 0) | 224 local_dir, DEFAULT_BASE_PORT if fixed_port else 0) |
| 224 return "--origin=" + origin_url | 225 return "--origin=" + origin_url |
| 225 | 226 |
| 227 def ServeLocalDirectory(self, local_dir_path, port=0): | |
| 228 """Serves the content of the local (host) directory, making it available to | |
| 229 the shell under the url returned by the function. | |
| 230 | |
| 231 The server will run on a separate thread until the program terminates. The | |
| 232 call returns immediately. | |
| 233 | |
| 234 Args: | |
| 235 local_dir_path: path to the directory to be served | |
| 236 port: port at which the server will be available to the shell | |
| 237 """ | |
| 238 return self._StartHttpServerForDirectory(local_dir_path, port) | |
|
qsr
2015/05/19 13:55:42
You are just delegatng to a private method -> you
ppi
2015/05/19 14:22:48
Done.
| |
| 239 | |
| 226 def StartShell(self, | 240 def StartShell(self, |
| 227 arguments, | 241 arguments, |
| 228 stdout=None, | 242 stdout=None, |
| 229 on_application_stop=None, | 243 on_application_stop=None, |
| 230 fixed_port=True): | 244 fixed_port=True): |
| 231 """Starts the mojo shell, passing it the given arguments. | 245 """Starts the mojo shell, passing it the given arguments. |
| 232 | 246 |
| 233 The |arguments| list must contain the "--origin=" arg. SetUpLocalOrigin() | 247 The |arguments| list must contain the "--origin=" arg. SetUpLocalOrigin() |
| 234 can be used to set up a local directory on the host machine as origin. | 248 can be used to set up a local directory on the host machine as origin. |
| 235 If |stdout| is not None, it should be a valid argument for subprocess.Popen. | 249 If |stdout| is not None, it should be a valid argument for subprocess.Popen. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 Returns: | 338 Returns: |
| 325 The process responsible for reading the logs. | 339 The process responsible for reading the logs. |
| 326 """ | 340 """ |
| 327 logcat = subprocess.Popen(self._CreateADBCommand([ | 341 logcat = subprocess.Popen(self._CreateADBCommand([ |
| 328 'logcat', | 342 'logcat', |
| 329 '-s', | 343 '-s', |
| 330 ' '.join(LOGCAT_TAGS)]), | 344 ' '.join(LOGCAT_TAGS)]), |
| 331 stdout=sys.stdout) | 345 stdout=sys.stdout) |
| 332 atexit.register(_ExitIfNeeded, logcat) | 346 atexit.register(_ExitIfNeeded, logcat) |
| 333 return logcat | 347 return logcat |
| OLD | NEW |