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 |
11 import os.path | 11 import os.path |
12 import sys | 12 import sys |
13 import urlparse | 13 import urlparse |
14 | 14 |
15 from devtoolslib.android_shell import AndroidShell | 15 from devtoolslib.android_shell import AndroidShell |
16 from devtoolslib.linux_shell import LinuxShell | 16 from devtoolslib.linux_shell import LinuxShell |
17 from devtoolslib.shell_config import ShellConfigurationException | |
17 | 18 |
18 # When spinning up servers for local origins, we want to use predictable ports | 19 # When spinning up servers for local origins, we want to use predictable ports |
19 # so that caching works between subsequent runs with the same command line. | 20 # so that caching works between subsequent runs with the same command line. |
20 _LOCAL_ORIGIN_PORT = 31840 | 21 _LOCAL_ORIGIN_PORT = 31840 |
21 _MAPPINGS_BASE_PORT = 31841 | 22 _MAPPINGS_BASE_PORT = 31841 |
22 | 23 |
23 | 24 |
24 class ShellConfigurationException(Exception): | |
25 """Represents an error preventing creating a functional shell abstraction.""" | |
26 pass | |
27 | |
28 | |
29 def _is_web_url(dest): | 25 def _is_web_url(dest): |
30 return True if urlparse.urlparse(dest).scheme else False | 26 return True if urlparse.urlparse(dest).scheme else False |
31 | 27 |
32 | 28 |
33 def _host_local_url_destination(shell, dest_file, port): | 29 def _host_local_url_destination(shell, dest_file, port): |
34 """Starts a local server to host |dest_file|. | 30 """Starts a local server to host |dest_file|. |
35 | 31 |
36 Returns: | 32 Returns: |
37 Url of the hosted file. | 33 Url of the hosted file. |
38 """ | 34 """ |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 if not argument.startswith(key): | 159 if not argument.startswith(key): |
164 continue | 160 continue |
165 arguments[i] = argument + delimiter + value | 161 arguments[i] = argument + delimiter + value |
166 break | 162 break |
167 else: | 163 else: |
168 arguments.append(key + value) | 164 arguments.append(key + value) |
169 | 165 |
170 return arguments | 166 return arguments |
171 | 167 |
172 | 168 |
169 def _configure_dev_server(shell, shell_args, dev_server_config): | |
170 """Sets up a dev server on the host according to |dev_server_config|. | |
171 | |
172 Args: | |
173 shell: The shell that is being configured. | |
174 shell_arguments: Current list of shell arguments. | |
175 dev_server_config: Instance of shell_config.DevServerConfig describing the | |
176 dev server to be set up. | |
177 | |
178 Returns: | |
179 The updated argument list. | |
180 """ | |
181 server_url = shell.serve_local_directories(dev_server_config.mappings) | |
182 shell_args.append('--map-origin=%s=%s' % (dev_server_config.host, server_url)) | |
183 print "Configured %s locally as %s" % (dev_server_config.host, server_url) | |
184 for mapping_prefix, mapping_path in dev_server_config.mappings: | |
185 print " /%s -> %s" % (mapping_prefix, mapping_path) | |
186 return shell_args | |
qsr
2015/08/05 08:11:13
Why do you both update the reference you are given
ppi
2015/08/05 10:54:01
This matches what all other functions do. I'm happ
| |
187 | |
188 | |
173 def get_shell(shell_config, shell_args): | 189 def get_shell(shell_config, shell_args): |
174 """ | 190 """ |
175 Produces a shell abstraction configured according to |shell_config|. | 191 Produces a shell abstraction configured according to |shell_config|. |
176 | 192 |
177 Args: | 193 Args: |
178 shell_config: Instance of shell_config.ShellConfig. | 194 shell_config: Instance of shell_config.ShellConfig. |
179 shell_args: Additional raw shell arguments to be passed to the shell. We | 195 shell_args: Additional raw shell arguments to be passed to the shell. We |
180 need to take these into account as some parameters need to appear only | 196 need to take these into account as some parameters need to appear only |
181 once on the argument list (e.g. url-mappings) so we need to coalesce any | 197 once on the argument list (e.g. url-mappings) so we need to coalesce any |
182 overrides and the existing value into just one argument. | 198 overrides and the existing value into just one argument. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 if shell_config.origin: | 230 if shell_config.origin: |
215 if _is_web_url(shell_config.origin): | 231 if _is_web_url(shell_config.origin): |
216 shell_args.append('--origin=' + shell_config.origin) | 232 shell_args.append('--origin=' + shell_config.origin) |
217 else: | 233 else: |
218 shell_args.extend(configure_local_origin(shell, shell_config.origin, | 234 shell_args.extend(configure_local_origin(shell, shell_config.origin, |
219 fixed_port=True)) | 235 fixed_port=True)) |
220 | 236 |
221 if shell_config.sky: | 237 if shell_config.sky: |
222 shell_args = _configure_sky(shell_args) | 238 shell_args = _configure_sky(shell_args) |
223 | 239 |
240 for dev_server_config in shell_config.dev_servers: | |
241 shell_args = _configure_dev_server(shell, shell_args, dev_server_config) | |
242 | |
224 return shell, shell_args | 243 return shell, shell_args |
OLD | NEW |