| 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 """Produces configured shell abstractions. | 5 """Produces configured shell abstractions. |
| 6 | 6 |
| 7 This module knows how to produce a configured shell abstraction based on | 7 This module knows how to produce a configured shell abstraction based on |
| 8 shell_config.ShellConfig. | 8 shell_config.ShellConfig. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 def _host_local_url_destination(shell, dest_file, port, free_host_port): | 29 def _host_local_url_destination(shell, dest_file, port, free_host_port): |
| 30 """Starts a local server to host |dest_file|. | 30 """Starts a local server to host |dest_file|. |
| 31 | 31 |
| 32 Returns: | 32 Returns: |
| 33 Url of the hosted file. | 33 Url of the hosted file. |
| 34 """ | 34 """ |
| 35 directory = os.path.dirname(dest_file) | 35 directory = os.path.dirname(dest_file) |
| 36 if not os.path.exists(directory): | 36 if not os.path.exists(directory): |
| 37 raise ValueError('local path passed as --map-url destination ' | 37 raise ValueError('local path passed as --map-url destination ' |
| 38 'does not exist') | 38 'does not exist') |
| 39 server_url = shell.serve_local_directory(directory, port, free_host_port) | 39 mappings = [('', [directory])] |
| 40 server_url = shell.serve_local_directories(mappings, port, free_host_port) |
| 40 return server_url + os.path.relpath(dest_file, directory) | 41 return server_url + os.path.relpath(dest_file, directory) |
| 41 | 42 |
| 42 | 43 |
| 43 def _host_local_origin_destination(shell, dest_dir, port, free_host_port): | 44 def _host_local_origin_destination(shell, dest_dir, port, free_host_port): |
| 44 """Starts a local server to host |dest_dir|. | 45 """Starts a local server to host |dest_dir|. |
| 45 | 46 |
| 46 Returns: | 47 Returns: |
| 47 Url of the hosted directory. | 48 Url of the hosted directory. |
| 48 """ | 49 """ |
| 49 return shell.serve_local_directory(dest_dir, port, free_host_port) | 50 mappings = [('', [dest_dir])] |
| 51 return shell.serve_local_directories(mappings, port, free_host_port) |
| 50 | 52 |
| 51 | 53 |
| 52 def _rewrite(mapping, host_destination_functon, shell, port, free_host_port): | 54 def _rewrite(mapping, host_destination_functon, shell, port, free_host_port): |
| 53 """Takes a mapping given as <src>=<dest> and rewrites the <dest> part to be | 55 """Takes a mapping given as <src>=<dest> and rewrites the <dest> part to be |
| 54 hosted locally using the given function if <dest> is not a web url. | 56 hosted locally using the given function if <dest> is not a web url. |
| 55 """ | 57 """ |
| 56 parts = mapping.split('=') | 58 parts = mapping.split('=') |
| 57 if len(parts) != 2: | 59 if len(parts) != 2: |
| 58 raise ValueError('each mapping value should be in format ' | 60 raise ValueError('each mapping value should be in format ' |
| 59 '"<url>=<url-or-local-path>"') | 61 '"<url>=<url-or-local-path>"') |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 return args | 113 return args |
| 112 | 114 |
| 113 | 115 |
| 114 def configure_local_origin(shell, local_dir, port, free_host_port): | 116 def configure_local_origin(shell, local_dir, port, free_host_port): |
| 115 """Sets up a local http server to serve files in |local_dir| along with | 117 """Sets up a local http server to serve files in |local_dir| along with |
| 116 device port forwarding if needed. | 118 device port forwarding if needed. |
| 117 | 119 |
| 118 Returns: | 120 Returns: |
| 119 The list of arguments to be appended to the shell argument list. | 121 The list of arguments to be appended to the shell argument list. |
| 120 """ | 122 """ |
| 121 | 123 mappings = [('', [local_dir])] |
| 122 origin_url = shell.serve_local_directory(local_dir, port, free_host_port) | 124 origin_url = shell.serve_local_directories(mappings, port, free_host_port) |
| 123 return ["--origin=" + origin_url] | 125 return ["--origin=" + origin_url] |
| 124 | 126 |
| 125 | 127 |
| 126 def append_to_argument(arguments, key, value, delimiter=","): | 128 def append_to_argument(arguments, key, value, delimiter=","): |
| 127 """Looks for an argument of the form "key=val1,val2" within |arguments| and | 129 """Looks for an argument of the form "key=val1,val2" within |arguments| and |
| 128 appends |value| to it. | 130 appends |value| to it. |
| 129 | 131 |
| 130 If the argument is not present in |arguments| it is added. | 132 If the argument is not present in |arguments| it is added. |
| 131 | 133 |
| 132 Args: | 134 Args: |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 shell_args = append_to_argument(shell_args, '--content-handlers=', | 241 shell_args = append_to_argument(shell_args, '--content-handlers=', |
| 240 '%s,%s' % (mime_type, | 242 '%s,%s' % (mime_type, |
| 241 content_handler_url)) | 243 content_handler_url)) |
| 242 | 244 |
| 243 for dev_server_config in shell_config.dev_servers: | 245 for dev_server_config in shell_config.dev_servers: |
| 244 shell_args = _configure_dev_server(shell, shell_args, dev_server_config, | 246 shell_args = _configure_dev_server(shell, shell_args, dev_server_config, |
| 245 shell_config.free_host_ports, | 247 shell_config.free_host_ports, |
| 246 shell_config.verbose) | 248 shell_config.verbose) |
| 247 | 249 |
| 248 return shell, shell_args | 250 return shell, shell_args |
| OLD | NEW |