OLD | NEW |
1 # Copyright (c) 2014 ThE Chromium Authors. All Rights Reserved. | 1 # Copyright (c) 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 from recipe_engine import recipe_api | 5 from recipe_engine import recipe_api |
6 | 6 |
7 class AdbApi(recipe_api.RecipeApi): | 7 class AdbApi(recipe_api.RecipeApi): |
8 def __init__(self, **kwargs): | 8 def __init__(self, **kwargs): |
9 super(AdbApi, self).__init__(**kwargs) | 9 super(AdbApi, self).__init__(**kwargs) |
10 self._custom_adb_path = None | 10 self._custom_adb_path = None |
11 self._devices = None | 11 self._devices = None |
12 | 12 |
13 def __call__(self, cmd, serial=None, **kwargs): | 13 def __call__(self, cmd, serial=None, **kwargs): |
14 """Run an ADB command.""" | 14 """Run an ADB command.""" |
15 cmd_prefix = [self.adb_path()] | 15 cmd_prefix = [self.adb_path()] |
16 if serial: | 16 if serial: |
17 cmd_prefix.extend(['-s', serial]) | 17 cmd_prefix.extend(['-s', serial]) |
18 return self.m.step(cmd=cmd_prefix + cmd, **kwargs) | 18 return self.m.step(cmd=cmd_prefix + cmd, **kwargs) |
19 | 19 |
20 def set_adb_path(self, adb_path): | 20 def set_adb_path(self, adb_path): |
21 self._custom_adb_path = adb_path | 21 self._custom_adb_path = adb_path |
22 | 22 |
23 def adb_path(self): | 23 def adb_path(self): |
24 if self._custom_adb_path: | 24 if self._custom_adb_path: |
25 return self._custom_adb_path | 25 return self._custom_adb_path |
26 return self.m.infra_paths['slave_build'].join( | 26 return self.m.path['slave_build'].join( |
27 'src', 'third_party', 'android_tools', 'sdk', 'platform-tools', 'adb') | 27 'src', 'third_party', 'android_tools', 'sdk', 'platform-tools', 'adb') |
28 | 28 |
29 def adb_dir(self): | 29 def adb_dir(self): |
30 return self.m.path.dirname(self.adb_path()) | 30 return self.m.path.dirname(self.adb_path()) |
31 | 31 |
32 def list_devices(self, step_test_data=None, **kwargs): | 32 def list_devices(self, step_test_data=None, **kwargs): |
33 cmd = [ | 33 cmd = [ |
34 str(self.adb_path()), | 34 str(self.adb_path()), |
35 'devices', | 35 'devices', |
36 ] | 36 ] |
(...skipping 22 matching lines...) Expand all Loading... |
59 import sys | 59 import sys |
60 adb_path = sys.argv[1] | 60 adb_path = sys.argv[1] |
61 for device in sys.argv[2:]: | 61 for device in sys.argv[2:]: |
62 print 'Attempting to root device %s ...' % (device) | 62 print 'Attempting to root device %s ...' % (device) |
63 subprocess.check_call([adb_path, '-s', device, 'root']) | 63 subprocess.check_call([adb_path, '-s', device, 'root']) |
64 subprocess.check_call([adb_path, '-s', device, 'wait-for-device']) | 64 subprocess.check_call([adb_path, '-s', device, 'wait-for-device']) |
65 print 'Finished rooting device %s' % (device) | 65 print 'Finished rooting device %s' % (device) |
66 """, | 66 """, |
67 args=[self.adb_path()] + self.devices, | 67 args=[self.adb_path()] + self.devices, |
68 **kwargs) | 68 **kwargs) |
OLD | NEW |