OLD | NEW |
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 """Provides a variety of device interactions based on adb. | 5 """Provides a variety of device interactions based on adb. |
6 | 6 |
7 Eventually, this will be based on adb_wrapper. | 7 Eventually, this will be based on adb_wrapper. |
8 """ | 8 """ |
9 # pylint: disable=W0613 | 9 # pylint: disable=W0613 |
10 | 10 |
11 import logging | 11 import logging |
12 import multiprocessing | 12 import multiprocessing |
13 import os | 13 import os |
14 import re | 14 import re |
15 import sys | 15 import sys |
16 import tempfile | 16 import tempfile |
17 import time | 17 import time |
18 import zipfile | 18 import zipfile |
19 | 19 |
20 import pylib.android_commands | 20 import pylib.android_commands |
21 from pylib import cmd_helper | 21 from pylib import cmd_helper |
22 from pylib.device import adb_wrapper | 22 from pylib.device import adb_wrapper |
23 from pylib.device import decorators | 23 from pylib.device import decorators |
24 from pylib.device import device_errors | 24 from pylib.device import device_errors |
25 from pylib.device.commands import install_commands | 25 from pylib.device.commands import install_commands |
26 from pylib.utils import apk_helper | 26 from pylib.utils import apk_helper |
27 from pylib.utils import device_temp_file | 27 from pylib.utils import device_temp_file |
28 from pylib.utils import host_utils | 28 from pylib.utils import host_utils |
| 29 from pylib.utils import md5sum |
29 from pylib.utils import parallelizer | 30 from pylib.utils import parallelizer |
30 from pylib.utils import timeout_retry | 31 from pylib.utils import timeout_retry |
31 | 32 |
32 _DEFAULT_TIMEOUT = 30 | 33 _DEFAULT_TIMEOUT = 30 |
33 _DEFAULT_RETRIES = 3 | 34 _DEFAULT_RETRIES = 3 |
34 | 35 |
35 | 36 |
36 @decorators.WithExplicitTimeoutAndRetries( | 37 @decorators.WithExplicitTimeoutAndRetries( |
37 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) | 38 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) |
38 def GetAVDs(): | 39 def GetAVDs(): |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 def _GetChangedFilesImpl(self, host_path, device_path): | 695 def _GetChangedFilesImpl(self, host_path, device_path): |
695 real_host_path = os.path.realpath(host_path) | 696 real_host_path = os.path.realpath(host_path) |
696 try: | 697 try: |
697 real_device_path = self.RunShellCommand( | 698 real_device_path = self.RunShellCommand( |
698 ['realpath', device_path], single_line=True, check_return=True) | 699 ['realpath', device_path], single_line=True, check_return=True) |
699 except device_errors.CommandFailedError: | 700 except device_errors.CommandFailedError: |
700 real_device_path = None | 701 real_device_path = None |
701 if not real_device_path: | 702 if not real_device_path: |
702 return [(host_path, device_path)] | 703 return [(host_path, device_path)] |
703 | 704 |
704 # TODO(jbudorick): Move the md5 logic up into DeviceUtils or base | 705 host_hash_tuples = md5sum.CalculateHostMd5Sums([real_host_path]) |
705 # this function on mtime. | 706 device_paths_to_md5 = ( |
706 # pylint: disable=protected-access | 707 real_device_path if os.path.isfile(real_host_path) |
707 host_hash_tuples, device_hash_tuples = self.old_interface._RunMd5Sum( | 708 else ('%s/%s' % (real_device_path, os.path.relpath(p, real_host_path)) |
708 real_host_path, real_device_path) | 709 for _, p in host_hash_tuples)) |
709 # pylint: enable=protected-access | 710 device_hash_tuples = md5sum.CalculateDeviceMd5Sums( |
| 711 device_paths_to_md5, self) |
710 | 712 |
711 if os.path.isfile(host_path): | 713 if os.path.isfile(host_path): |
712 if (not device_hash_tuples | 714 if (not device_hash_tuples |
713 or device_hash_tuples[0].hash != host_hash_tuples[0].hash): | 715 or device_hash_tuples[0].hash != host_hash_tuples[0].hash): |
714 return [(host_path, device_path)] | 716 return [(host_path, device_path)] |
715 else: | 717 else: |
716 return [] | 718 return [] |
717 else: | 719 else: |
718 device_tuple_dict = dict((d.path, d.hash) for d in device_hash_tuples) | 720 device_tuple_dict = dict((d.path, d.hash) for d in device_hash_tuples) |
719 to_push = [] | 721 to_push = [] |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 Returns: | 1158 Returns: |
1157 A Parallelizer operating over |devices|. | 1159 A Parallelizer operating over |devices|. |
1158 """ | 1160 """ |
1159 if not devices or len(devices) == 0: | 1161 if not devices or len(devices) == 0: |
1160 devices = pylib.android_commands.GetAttachedDevices() | 1162 devices = pylib.android_commands.GetAttachedDevices() |
1161 parallelizer_type = (parallelizer.Parallelizer if async | 1163 parallelizer_type = (parallelizer.Parallelizer if async |
1162 else parallelizer.SyncParallelizer) | 1164 else parallelizer.SyncParallelizer) |
1163 return parallelizer_type([ | 1165 return parallelizer_type([ |
1164 d if isinstance(d, DeviceUtils) else DeviceUtils(d) | 1166 d if isinstance(d, DeviceUtils) else DeviceUtils(d) |
1165 for d in devices]) | 1167 for d in devices]) |
OLD | NEW |