| OLD | NEW |
| 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 subprocess | 5 import subprocess |
| 6 import threading | 6 import threading |
| 7 | 7 |
| 8 from devtoolslib.shell import Shell | 8 from devtoolslib.shell import Shell |
| 9 from devtoolslib import http_server | 9 from devtoolslib import http_server |
| 10 | 10 |
| 11 | 11 |
| 12 class LinuxShell(Shell): | 12 class LinuxShell(Shell): |
| 13 """Wrapper around Mojo shell running on Linux. | 13 """Wrapper around Mojo shell running on Linux. |
| 14 | 14 |
| 15 Args: | 15 Args: |
| 16 executable_path: path to the shell binary | 16 executable_path: path to the shell binary |
| 17 command_prefix: optional list of arguments to prepend to the shell command, | 17 command_prefix: optional list of arguments to prepend to the shell command, |
| 18 allowing e.g. to run the shell under debugger. | 18 allowing e.g. to run the shell under debugger. |
| 19 """ | 19 """ |
| 20 | 20 |
| 21 def __init__(self, executable_path, command_prefix=None): | 21 def __init__(self, executable_path, command_prefix=None): |
| 22 self.executable_path = executable_path | 22 self.executable_path = executable_path |
| 23 self.command_prefix = command_prefix if command_prefix else [] | 23 self.command_prefix = command_prefix if command_prefix else [] |
| 24 | 24 |
| 25 def ServeLocalDirectory(self, local_dir_path, port=0, | 25 def ServeLocalDirectory(self, local_dir_path, port=0): |
| 26 additional_mappings=None): | |
| 27 """Serves the content of the local (host) directory, making it available to | 26 """Serves the content of the local (host) directory, making it available to |
| 28 the shell under the url returned by the function. | 27 the shell under the url returned by the function. |
| 29 | 28 |
| 30 The server will run on a separate thread until the program terminates. The | 29 The server will run on a separate thread until the program terminates. The |
| 31 call returns immediately. | 30 call returns immediately. |
| 32 | 31 |
| 33 Args: | 32 Args: |
| 34 local_dir_path: path to the directory to be served | 33 local_dir_path: path to the directory to be served |
| 35 port: port at which the server will be available to the shell | 34 port: port at which the server will be available to the shell |
| 36 additional_mappings: List of tuples (prefix, local_base_path) mapping | |
| 37 URLs that start with |prefix| to local directory at |local_base_path|. | |
| 38 The prefixes should skip the leading slash. | |
| 39 | 35 |
| 40 Returns: | 36 Returns: |
| 41 The url that the shell can use to access the content of |local_dir_path|. | 37 The url that the shell can use to access the content of |local_dir_path|. |
| 42 """ | 38 """ |
| 43 return 'http://%s:%d/' % http_server.start_http_server(local_dir_path, port, | 39 mappings = [('', local_dir_path)] |
| 44 additional_mappings) | 40 return 'http://%s:%d/' % http_server.start_http_server(mappings, port) |
| 41 |
| 42 def ServeLocalDirectories(self, mappings, port=0): |
| 43 """Serves the content of the local (host) directories, making it available |
| 44 to the shell under the url returned by the function. |
| 45 |
| 46 The server will run on a separate thread until the program terminates. The |
| 47 call returns immediately. |
| 48 |
| 49 Args: |
| 50 mappings: List of tuples (prefix, local_base_path) mapping URLs that start |
| 51 with |prefix| to local directory at |local_base_path|. The prefixes |
| 52 should skip the leading slash. The first matching prefix will be used |
| 53 each time. |
| 54 port: port at which the server will be available to the shell |
| 55 |
| 56 Returns: |
| 57 The url that the shell can use to access the content of |local_dir_path|. |
| 58 """ |
| 59 return 'http://%s:%d/' % http_server.start_http_server(mappings, port) |
| 45 | 60 |
| 46 def ForwardHostPortToShell(self, host_port): | 61 def ForwardHostPortToShell(self, host_port): |
| 47 """Forwards a port on the host machine to the same port wherever the shell | 62 """Forwards a port on the host machine to the same port wherever the shell |
| 48 is running. | 63 is running. |
| 49 | 64 |
| 50 This is a no-op if the shell is running locally. | 65 This is a no-op if the shell is running locally. |
| 51 """ | 66 """ |
| 52 pass | 67 pass |
| 53 | 68 |
| 54 def Run(self, arguments): | 69 def Run(self, arguments): |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 (Results.output, _) = p.communicate() | 107 (Results.output, _) = p.communicate() |
| 93 | 108 |
| 94 run_thread = threading.Thread(target=do_run) | 109 run_thread = threading.Thread(target=do_run) |
| 95 run_thread.start() | 110 run_thread.start() |
| 96 run_thread.join(timeout) | 111 run_thread.join(timeout) |
| 97 | 112 |
| 98 if run_thread.is_alive(): | 113 if run_thread.is_alive(): |
| 99 p.terminate() | 114 p.terminate() |
| 100 return p.returncode, Results.output, True | 115 return p.returncode, Results.output, True |
| 101 return p.returncode, Results.output, False | 116 return p.returncode, Results.output, False |
| OLD | NEW |