Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: mojo/devtools/common/devtoolslib/android_shell.py

Issue 1162923004: Move the logic to set up a local origin for shell run to shell_arguments.py. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | mojo/devtools/common/devtoolslib/shell_arguments.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 17 matching lines...) Expand all
28 'MojoShellApplication', 28 'MojoShellApplication',
29 ] 29 ]
30 30
31 # Tags used by native logging reflected in the logcat. 31 # Tags used by native logging reflected in the logcat.
32 _LOGCAT_NATIVE_TAGS = [ 32 _LOGCAT_NATIVE_TAGS = [
33 'chromium', 33 'chromium',
34 ] 34 ]
35 35
36 _MOJO_SHELL_PACKAGE_NAME = 'org.chromium.mojo.shell' 36 _MOJO_SHELL_PACKAGE_NAME = 'org.chromium.mojo.shell'
37 37
38 _DEFAULT_BASE_PORT = 31337
39 38
40 _logger = logging.getLogger() 39 _logger = logging.getLogger()
41 40
42 41
43 def _ExitIfNeeded(process): 42 def _ExitIfNeeded(process):
44 """Exits |process| if it is still alive.""" 43 """Exits |process| if it is still alive."""
45 if process.poll() is None: 44 if process.poll() is None:
46 process.kill() 45 process.kill()
47 46
48 47
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 fp.write(apk_sha1) 180 fp.write(apk_sha1)
182 fp.flush() 181 fp.flush()
183 subprocess.check_call(self._CreateADBCommand(['push', fp.name, 182 subprocess.check_call(self._CreateADBCommand(['push', fp.name,
184 device_sha1_path]), 183 device_sha1_path]),
185 stdout=self.verbose_pipe) 184 stdout=self.verbose_pipe)
186 else: 185 else:
187 # To ensure predictable state after running InstallApk(), we need to stop 186 # To ensure predictable state after running InstallApk(), we need to stop
188 # the shell here, as this is what "adb install" implicitly does. 187 # the shell here, as this is what "adb install" implicitly does.
189 self.StopShell() 188 self.StopShell()
190 189
191 def SetUpLocalOrigin(self, local_dir, fixed_port=True):
192 """Sets up a local http server to serve files in |local_dir| along with
193 device port forwarding. Returns the origin flag to be set when running the
194 shell.
195 """
196
197 origin_url = self.ServeLocalDirectory(
198 local_dir, _DEFAULT_BASE_PORT if fixed_port else 0)
199 return "--origin=" + origin_url
200
201 def ServeLocalDirectory(self, local_dir_path, port=0): 190 def ServeLocalDirectory(self, local_dir_path, port=0):
202 """Serves the content of the local (host) directory, making it available to 191 """Serves the content of the local (host) directory, making it available to
203 the shell under the url returned by the function. 192 the shell under the url returned by the function.
204 193
205 The server will run on a separate thread until the program terminates. The 194 The server will run on a separate thread until the program terminates. The
206 call returns immediately. 195 call returns immediately.
207 196
208 Args: 197 Args:
209 local_dir_path: path to the directory to be served 198 local_dir_path: path to the directory to be served
210 port: port at which the server will be available to the shell 199 port: port at which the server will be available to the shell
(...skipping 26 matching lines...) Expand all
237 def _UnmapPort(): 226 def _UnmapPort():
238 subprocess.Popen(unmap_command) 227 subprocess.Popen(unmap_command)
239 atexit.register(_UnmapPort) 228 atexit.register(_UnmapPort)
240 229
241 def StartShell(self, 230 def StartShell(self,
242 arguments, 231 arguments,
243 stdout=None, 232 stdout=None,
244 on_application_stop=None): 233 on_application_stop=None):
245 """Starts the mojo shell, passing it the given arguments. 234 """Starts the mojo shell, passing it the given arguments.
246 235
247 The |arguments| list must contain the "--origin=" arg. SetUpLocalOrigin() 236 Args:
248 can be used to set up a local directory on the host machine as origin. 237 arguments: List of arguments for the shell. It must contain the
249 If |stdout| is not None, it should be a valid argument for subprocess.Popen. 238 "--origin=" arg. shell_arguments.ConfigureLocalOrigin() can be used
239 to set up a local directory on the host machine as origin.
240 stdout: Valid argument for subprocess.Popen() or None.
250 """ 241 """
251 if not self.stop_shell_registered: 242 if not self.stop_shell_registered:
252 atexit.register(self.StopShell) 243 atexit.register(self.StopShell)
253 self.stop_shell_registered = True 244 self.stop_shell_registered = True
254 245
255 STDOUT_PIPE = "/data/data/%s/stdout.fifo" % _MOJO_SHELL_PACKAGE_NAME 246 STDOUT_PIPE = "/data/data/%s/stdout.fifo" % _MOJO_SHELL_PACKAGE_NAME
256 247
257 cmd = self._CreateADBCommand([ 248 cmd = self._CreateADBCommand([
258 'shell', 249 'shell',
259 'am', 250 'am',
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 tags.extend(_LOGCAT_NATIVE_TAGS) 331 tags.extend(_LOGCAT_NATIVE_TAGS)
341 if self.additional_logcat_tags is not None: 332 if self.additional_logcat_tags is not None:
342 tags.extend(self.additional_logcat_tags.split(",")) 333 tags.extend(self.additional_logcat_tags.split(","))
343 logcat = subprocess.Popen( 334 logcat = subprocess.Popen(
344 self._CreateADBCommand(['logcat', 335 self._CreateADBCommand(['logcat',
345 '-s', 336 '-s',
346 ' '.join(tags)]), 337 ' '.join(tags)]),
347 stdout=sys.stdout) 338 stdout=sys.stdout)
348 atexit.register(_ExitIfNeeded, logcat) 339 atexit.register(_ExitIfNeeded, logcat)
349 return logcat 340 return logcat
OLDNEW
« no previous file with comments | « no previous file | mojo/devtools/common/devtoolslib/shell_arguments.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698