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=unused-argument | 9 # pylint: disable=unused-argument |
10 | 10 |
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 host_path: an absolute path of a file or directory on the host | 1027 host_path: an absolute path of a file or directory on the host |
1028 device_path: an absolute path of a file or directory on the device | 1028 device_path: an absolute path of a file or directory on the device |
1029 track_stale: whether to bother looking for stale files (slower) | 1029 track_stale: whether to bother looking for stale files (slower) |
1030 | 1030 |
1031 Returns: | 1031 Returns: |
1032 a two-element tuple | 1032 a two-element tuple |
1033 1st element: a list of (host_files_path, device_files_path) tuples to push | 1033 1st element: a list of (host_files_path, device_files_path) tuples to push |
1034 2nd element: a list of stale files under device_path, or [] when | 1034 2nd element: a list of stale files under device_path, or [] when |
1035 track_stale == False | 1035 track_stale == False |
1036 """ | 1036 """ |
1037 real_host_path = os.path.realpath(host_path) | |
1038 try: | 1037 try: |
1039 real_device_path = self.RunShellCommand( | 1038 host_checksums = md5sum.CalculateHostMd5Sums([host_path]) |
1040 ['realpath', device_path], single_line=True, check_return=True) | 1039 interesting_device_paths = [device_path] |
1041 except device_errors.CommandFailedError: | 1040 if not track_stale and os.path.isdir(host_path): |
1042 real_device_path = None | |
1043 if not real_device_path: | |
1044 return ([(host_path, device_path)], []) | |
1045 | |
1046 try: | |
1047 host_checksums = md5sum.CalculateHostMd5Sums([real_host_path]) | |
1048 interesting_device_paths = [real_device_path] | |
1049 if not track_stale and os.path.isdir(real_host_path): | |
1050 interesting_device_paths = [ | 1041 interesting_device_paths = [ |
1051 posixpath.join(real_device_path, os.path.relpath(p, real_host_path)) | 1042 posixpath.join(device_path, os.path.relpath(p, host_path)) |
1052 for p in host_checksums.keys()] | 1043 for p in host_checksums.keys()] |
1053 device_checksums = md5sum.CalculateDeviceMd5Sums( | 1044 device_checksums = md5sum.CalculateDeviceMd5Sums( |
1054 interesting_device_paths, self) | 1045 interesting_device_paths, self) |
1055 except EnvironmentError as e: | 1046 except EnvironmentError as e: |
1056 logging.warning('Error calculating md5: %s', e) | 1047 logging.warning('Error calculating md5: %s', e) |
1057 return ([(host_path, device_path)], []) | 1048 return ([(host_path, device_path)], []) |
1058 | 1049 |
1059 if os.path.isfile(host_path): | 1050 if os.path.isfile(host_path): |
1060 host_checksum = host_checksums.get(real_host_path) | 1051 host_checksum = host_checksums.get(host_path) |
1061 device_checksum = device_checksums.get(real_device_path) | 1052 device_checksum = device_checksums.get(device_path) |
1062 if host_checksum != device_checksum: | 1053 if host_checksum != device_checksum: |
1063 return ([(host_path, device_path)], []) | 1054 return ([(host_path, device_path)], []) |
1064 else: | 1055 else: |
1065 return ([], []) | 1056 return ([], []) |
1066 else: | 1057 else: |
1067 to_push = [] | 1058 to_push = [] |
1068 for host_abs_path, host_checksum in host_checksums.iteritems(): | 1059 for host_abs_path, host_checksum in host_checksums.iteritems(): |
1069 device_abs_path = '%s/%s' % ( | 1060 device_abs_path = posixpath.join( |
1070 real_device_path, os.path.relpath(host_abs_path, real_host_path)) | 1061 device_path, os.path.relpath(host_abs_path, host_path)) |
1071 device_checksum = device_checksums.pop(device_abs_path, None) | 1062 device_checksum = device_checksums.pop(device_abs_path, None) |
1072 if device_checksum != host_checksum: | 1063 if device_checksum != host_checksum: |
1073 to_push.append((host_abs_path, device_abs_path)) | 1064 to_push.append((host_abs_path, device_abs_path)) |
1074 to_delete = device_checksums.keys() | 1065 to_delete = device_checksums.keys() |
1075 return (to_push, to_delete) | 1066 return (to_push, to_delete) |
1076 | 1067 |
1077 def _ComputeDeviceChecksumsForApks(self, package_name): | 1068 def _ComputeDeviceChecksumsForApks(self, package_name): |
1078 ret = self._cache['package_apk_checksums'].get(package_name) | 1069 ret = self._cache['package_apk_checksums'].get(package_name) |
1079 if ret is None: | 1070 if ret is None: |
1080 device_paths = self._GetApplicationPathsInternal(package_name) | 1071 device_paths = self._GetApplicationPathsInternal(package_name) |
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1880 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() | 1871 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() |
1881 if not blacklisted(adb)] | 1872 if not blacklisted(adb)] |
1882 | 1873 |
1883 @decorators.WithTimeoutAndRetriesFromInstance() | 1874 @decorators.WithTimeoutAndRetriesFromInstance() |
1884 def RestartAdbd(self, timeout=None, retries=None): | 1875 def RestartAdbd(self, timeout=None, retries=None): |
1885 logging.info('Restarting adbd on device.') | 1876 logging.info('Restarting adbd on device.') |
1886 with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script: | 1877 with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script: |
1887 self.WriteFile(script.name, _RESTART_ADBD_SCRIPT) | 1878 self.WriteFile(script.name, _RESTART_ADBD_SCRIPT) |
1888 self.RunShellCommand(['source', script.name], as_root=True) | 1879 self.RunShellCommand(['source', script.name], as_root=True) |
1889 self.adb.WaitForDevice() | 1880 self.adb.WaitForDevice() |
OLD | NEW |