| 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 hashlib | 6 import hashlib |
| 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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 line) | 363 line) |
| 364 if match: | 364 if match: |
| 365 device_port = int(match.group(1)) | 365 device_port = int(match.group(1)) |
| 366 host_port = self._ForwardHostPortToDevice(0, device_port) | 366 host_port = self._ForwardHostPortToDevice(0, device_port) |
| 367 print ("Dart observatory available at the host at http://127.0.0.1:%d" | 367 print ("Dart observatory available at the host at http://127.0.0.1:%d" |
| 368 % host_port) | 368 % host_port) |
| 369 | 369 |
| 370 logcat_watch_thread = threading.Thread(target=_ForwardObservatoriesAsNeeded) | 370 logcat_watch_thread = threading.Thread(target=_ForwardObservatoriesAsNeeded) |
| 371 logcat_watch_thread.start() | 371 logcat_watch_thread.start() |
| 372 | 372 |
| 373 def ServeLocalDirectory(self, local_dir_path, port=0, | 373 def ServeLocalDirectory(self, local_dir_path, port=0): |
| 374 additional_mappings=None): | |
| 375 """Serves the content of the local (host) directory, making it available to | 374 """Serves the content of the local (host) directory, making it available to |
| 376 the shell under the url returned by the function. | 375 the shell under the url returned by the function. |
| 377 | 376 |
| 378 The server will run on a separate thread until the program terminates. The | 377 The server will run on a separate thread until the program terminates. The |
| 379 call returns immediately. | 378 call returns immediately. |
| 380 | 379 |
| 381 Args: | 380 Args: |
| 382 local_dir_path: path to the directory to be served | 381 local_dir_path: path to the directory to be served |
| 383 port: port at which the server will be available to the shell | 382 port: port at which the server will be available to the shell |
| 384 additional_mappings: List of tuples (prefix, local_base_path) mapping | |
| 385 URLs that start with |prefix| to local directory at |local_base_path|. | |
| 386 The prefixes should skip the leading slash. | |
| 387 | 383 |
| 388 Returns: | 384 Returns: |
| 389 The url that the shell can use to access the content of |local_dir_path|. | 385 The url that the shell can use to access the content of |local_dir_path|. |
| 390 """ | 386 """ |
| 391 assert local_dir_path | 387 assert local_dir_path |
| 392 server_address = start_http_server(local_dir_path, host_port=port, | 388 mappings = [('', local_dir_path)] |
| 393 additional_mappings=additional_mappings) | 389 server_address = start_http_server(mappings, host_port=port) |
| 394 | 390 |
| 395 return 'http://127.0.0.1:%d/' % self._ForwardDevicePortToHost( | 391 return 'http://127.0.0.1:%d/' % self._ForwardDevicePortToHost( |
| 396 port, server_address[1]) | 392 port, server_address[1]) |
| 393 |
| 394 def ServeLocalDirectories(self, mappings, port=0): |
| 395 """Serves the content of the local (host) directories, making it available |
| 396 to the shell under the url returned by the function. |
| 397 |
| 398 The server will run on a separate thread until the program terminates. The |
| 399 call returns immediately. |
| 400 |
| 401 Args: |
| 402 mappings: List of tuples (prefix, local_base_path) mapping URLs that start |
| 403 with |prefix| to local directory at |local_base_path|. The prefixes |
| 404 should skip the leading slash. The first matching prefix will be used |
| 405 each time. |
| 406 port: port at which the server will be available to the shell |
| 407 |
| 408 Returns: |
| 409 The url that the shell can use to access the content of |local_dir_path|. |
| 410 """ |
| 411 assert mappings |
| 412 server_address = start_http_server(mappings, host_port=port) |
| 413 |
| 414 return 'http://127.0.0.1:%d/' % self._ForwardDevicePortToHost( |
| 415 port, server_address[1]) |
| 397 | 416 |
| 398 def ForwardHostPortToShell(self, host_port): | 417 def ForwardHostPortToShell(self, host_port): |
| 399 """Forwards a port on the host machine to the same port wherever the shell | 418 """Forwards a port on the host machine to the same port wherever the shell |
| 400 is running. | 419 is running. |
| 401 | 420 |
| 402 This is a no-op if the shell is running locally. | 421 This is a no-op if the shell is running locally. |
| 403 """ | 422 """ |
| 404 self._ForwardHostPortToDevice(host_port, host_port) | 423 self._ForwardHostPortToDevice(host_port, host_port) |
| 405 | 424 |
| 406 def Run(self, arguments): | 425 def Run(self, arguments): |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 Results.output = rf.read() | 470 Results.output = rf.read() |
| 452 | 471 |
| 453 run_thread = threading.Thread(target=do_run) | 472 run_thread = threading.Thread(target=do_run) |
| 454 run_thread.start() | 473 run_thread.start() |
| 455 run_thread.join(timeout) | 474 run_thread.join(timeout) |
| 456 | 475 |
| 457 if run_thread.is_alive(): | 476 if run_thread.is_alive(): |
| 458 self.StopShell() | 477 self.StopShell() |
| 459 return None, Results.output, True | 478 return None, Results.output, True |
| 460 return None, Results.output, False | 479 return None, Results.output, False |
| OLD | NEW |