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 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 device_path: an absolute path of a file or directory on the device | 1032 device_path: an absolute path of a file or directory on the device |
1033 track_stale: whether to bother looking for stale files (slower) | 1033 track_stale: whether to bother looking for stale files (slower) |
1034 | 1034 |
1035 Returns: | 1035 Returns: |
1036 a three-element tuple | 1036 a three-element tuple |
1037 1st element: a list of (host_files_path, device_files_path) tuples to push | 1037 1st element: a list of (host_files_path, device_files_path) tuples to push |
1038 2nd element: a list of host_files_path that are up-to-date | 1038 2nd element: a list of host_files_path that are up-to-date |
1039 3rd element: a list of stale files under device_path, or [] when | 1039 3rd element: a list of stale files under device_path, or [] when |
1040 track_stale == False | 1040 track_stale == False |
1041 """ | 1041 """ |
| 1042 real_host_path = os.path.realpath(host_path) |
1042 try: | 1043 try: |
1043 host_checksums = md5sum.CalculateHostMd5Sums([host_path]) | 1044 real_device_path = self.RunShellCommand( |
1044 interesting_device_paths = [device_path] | 1045 ['realpath', device_path], single_line=True, check_return=True) |
1045 if not track_stale and os.path.isdir(host_path): | 1046 except device_errors.CommandFailedError: |
| 1047 real_device_path = None |
| 1048 if not real_device_path: |
| 1049 return ([(host_path, device_path)], [], []) |
| 1050 |
| 1051 try: |
| 1052 host_checksums = md5sum.CalculateHostMd5Sums([real_host_path]) |
| 1053 interesting_device_paths = [real_device_path] |
| 1054 if not track_stale and os.path.isdir(real_host_path): |
1046 interesting_device_paths = [ | 1055 interesting_device_paths = [ |
1047 posixpath.join(device_path, os.path.relpath(p, host_path)) | 1056 posixpath.join(real_device_path, os.path.relpath(p, real_host_path)) |
1048 for p in host_checksums.keys()] | 1057 for p in host_checksums.keys()] |
1049 device_checksums = md5sum.CalculateDeviceMd5Sums( | 1058 device_checksums = md5sum.CalculateDeviceMd5Sums( |
1050 interesting_device_paths, self) | 1059 interesting_device_paths, self) |
1051 except EnvironmentError as e: | 1060 except EnvironmentError as e: |
1052 logging.warning('Error calculating md5: %s', e) | 1061 logging.warning('Error calculating md5: %s', e) |
1053 return ([(host_path, device_path)], [], []) | 1062 return ([(host_path, device_path)], [], []) |
1054 | 1063 |
1055 to_push = [] | 1064 to_push = [] |
1056 up_to_date = [] | 1065 up_to_date = [] |
1057 to_delete = [] | 1066 to_delete = [] |
1058 if os.path.isfile(host_path): | 1067 if os.path.isfile(host_path): |
1059 host_checksum = host_checksums.get(host_path) | 1068 host_checksum = host_checksums.get(real_host_path) |
1060 device_checksum = device_checksums.get(device_path) | 1069 device_checksum = device_checksums.get(real_device_path) |
1061 if host_checksum == device_checksum: | 1070 if host_checksum == device_checksum: |
1062 up_to_date.append(host_path) | 1071 up_to_date.append(host_path) |
1063 else: | 1072 else: |
1064 to_push.append((host_path, device_path)) | 1073 to_push.append((host_path, device_path)) |
1065 else: | 1074 else: |
1066 for host_abs_path, host_checksum in host_checksums.iteritems(): | 1075 for host_abs_path, host_checksum in host_checksums.iteritems(): |
1067 device_abs_path = posixpath.join( | 1076 device_abs_path = posixpath.join( |
1068 device_path, os.path.relpath(host_abs_path, host_path)) | 1077 real_device_path, os.path.relpath(host_abs_path, real_host_path)) |
1069 device_checksum = device_checksums.pop(device_abs_path, None) | 1078 device_checksum = device_checksums.pop(device_abs_path, None) |
1070 if device_checksum == host_checksum: | 1079 if device_checksum == host_checksum: |
1071 up_to_date.append(host_abs_path) | 1080 up_to_date.append(host_abs_path) |
1072 else: | 1081 else: |
1073 to_push.append((host_abs_path, device_abs_path)) | 1082 to_push.append((host_abs_path, device_abs_path)) |
1074 to_delete = device_checksums.keys() | 1083 to_delete = device_checksums.keys() |
1075 return (to_push, up_to_date, to_delete) | 1084 return (to_push, up_to_date, to_delete) |
1076 | 1085 |
1077 def _ComputeDeviceChecksumsForApks(self, package_name): | 1086 def _ComputeDeviceChecksumsForApks(self, package_name): |
1078 ret = self._cache['package_apk_checksums'].get(package_name) | 1087 ret = self._cache['package_apk_checksums'].get(package_name) |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1880 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() | 1889 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() |
1881 if not blacklisted(adb)] | 1890 if not blacklisted(adb)] |
1882 | 1891 |
1883 @decorators.WithTimeoutAndRetriesFromInstance() | 1892 @decorators.WithTimeoutAndRetriesFromInstance() |
1884 def RestartAdbd(self, timeout=None, retries=None): | 1893 def RestartAdbd(self, timeout=None, retries=None): |
1885 logging.info('Restarting adbd on device.') | 1894 logging.info('Restarting adbd on device.') |
1886 with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script: | 1895 with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script: |
1887 self.WriteFile(script.name, _RESTART_ADBD_SCRIPT) | 1896 self.WriteFile(script.name, _RESTART_ADBD_SCRIPT) |
1888 self.RunShellCommand(['source', script.name], as_root=True) | 1897 self.RunShellCommand(['source', script.name], as_root=True) |
1889 self.adb.WaitForDevice() | 1898 self.adb.WaitForDevice() |
OLD | NEW |