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

Side by Side Diff: tools/android/loading/device_setup.py

Issue 1619713002: Upgrade analyze.py and related scripts to new world order. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 11 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
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 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 contextlib 5 import contextlib
6 import logging
6 import os 7 import os
7 import sys 8 import sys
8 import time 9 import time
9 10
10 _SRC_DIR = os.path.abspath(os.path.join( 11 _SRC_DIR = os.path.abspath(os.path.join(
11 os.path.dirname(__file__), '..', '..', '..')) 12 os.path.dirname(__file__), '..', '..', '..'))
12 13
13 sys.path.append(os.path.join(_SRC_DIR, 'third_party', 'catapult', 'devil')) 14 sys.path.append(os.path.join(_SRC_DIR, 'third_party', 'catapult', 'devil'))
15 from devil.android import device_utils
14 from devil.android.sdk import intent 16 from devil.android.sdk import intent
15 17
16 sys.path.append(os.path.join(_SRC_DIR, 'build', 'android')) 18 sys.path.append(os.path.join(_SRC_DIR, 'build', 'android'))
17 from pylib import constants 19 from pylib import constants
18 from pylib import flag_changer 20 from pylib import flag_changer
19 21
20 import devtools_monitor 22 import devtools_monitor
21 23
22 DEVTOOLS_PORT = 9222 24 DEVTOOLS_PORT = 9222
23 DEVTOOLS_HOSTNAME = 'localhost' 25 DEVTOOLS_HOSTNAME = 'localhost'
24 DEFAULT_CHROME_PACKAGE = 'chrome' 26 DEFAULT_CHROME_PACKAGE = 'chrome'
25 27
28
29 class DeviceSetupException(Exception):
30 def __init__(self, msg):
31 super(DeviceSetupException, self).__init__(msg)
32 logging.error(msg)
33
34
35 def GetFirstDevice():
36 """Returns the first connected device.
37
38 Raises:
39 DeviceSetupException if there is no such device.
40 """
41 devices = device_utils.DeviceUtils.HealthyDevices()
42 if not devices:
43 raise DeviceSetupException('No devices found')
44 return devices[0]
45
46
26 @contextlib.contextmanager 47 @contextlib.contextmanager
27 def FlagReplacer(device, command_line_path, new_flags): 48 def FlagReplacer(device, command_line_path, new_flags):
28 """Replaces chrome flags in a context, restores them afterwards. 49 """Replaces chrome flags in a context, restores them afterwards.
29 50
30 Args: 51 Args:
31 device: Device to target, from DeviceUtils. Can be None, in which case this 52 device: Device to target, from DeviceUtils. Can be None, in which case this
32 context manager is a no-op. 53 context manager is a no-op.
33 command_line_path: Full path to the command-line file. 54 command_line_path: Full path to the command-line file.
34 new_flags: Flags to replace. 55 new_flags: Flags to replace.
35 """ 56 """
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 package: the key for chrome package info. 134 package: the key for chrome package info.
114 fn: the function to execute that launches chrome and performs the 135 fn: the function to execute that launches chrome and performs the
115 appropriate instrumentation. The function will receive a 136 appropriate instrumentation. The function will receive a
116 DevToolsConnection as its sole parameter. 137 DevToolsConnection as its sole parameter.
117 138
118 Returns: 139 Returns:
119 As fn() returns. 140 As fn() returns.
120 """ 141 """
121 with DeviceConnection(device, package) as connection: 142 with DeviceConnection(device, package) as connection:
122 return fn(connection) 143 return fn(connection)
OLDNEW
« no previous file with comments | « tools/android/loading/deprecated/process_request_log.py ('k') | tools/android/loading/devtools_monitor.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698