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

Side by Side Diff: build/android/pylib/device/device_utils.py

Issue 1304713003: DeviceUtils.PushChangedFiles(): Don't run mkdir when it's not necessary (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@device6
Patch Set: rebase Created 5 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 987 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 delete_device_stale: option to delete stale files on device 998 delete_device_stale: option to delete stale files on device
999 999
1000 Raises: 1000 Raises:
1001 CommandFailedError on failure. 1001 CommandFailedError on failure.
1002 CommandTimeoutError on timeout. 1002 CommandTimeoutError on timeout.
1003 DeviceUnreachableError on missing device. 1003 DeviceUnreachableError on missing device.
1004 """ 1004 """
1005 1005
1006 all_changed_files = [] 1006 all_changed_files = []
1007 all_stale_files = [] 1007 all_stale_files = []
1008 missing_dirs = []
1008 for h, d in host_device_tuples: 1009 for h, d in host_device_tuples:
1009 if os.path.isdir(h): 1010 changed_files, up_to_date_files, stale_files = (
1010 self.RunShellCommand(['mkdir', '-p', d], check_return=True)
1011 changed_files, stale_files = (
1012 self._GetChangedAndStaleFiles(h, d, delete_device_stale)) 1011 self._GetChangedAndStaleFiles(h, d, delete_device_stale))
1013 all_changed_files += changed_files 1012 all_changed_files += changed_files
1014 all_stale_files += stale_files 1013 all_stale_files += stale_files
1014 if (os.path.isdir(h) and changed_files and not up_to_date_files
1015 and not stale_files):
1016 missing_dirs.append(d)
1015 1017
1016 if delete_device_stale and all_stale_files: 1018 if delete_device_stale and all_stale_files:
1017 self.RunShellCommand(['rm', '-f'] + all_stale_files, 1019 self.RunShellCommand(['rm', '-f'] + all_stale_files,
1018 check_return=True) 1020 check_return=True)
1019 1021
1020 if all_changed_files: 1022 if all_changed_files:
1023 if missing_dirs:
1024 self.RunShellCommand(['mkdir', '-p'] + missing_dirs, check_return=True)
1021 self._PushFilesImpl(host_device_tuples, all_changed_files) 1025 self._PushFilesImpl(host_device_tuples, all_changed_files)
1022 1026
1023 def _GetChangedAndStaleFiles(self, host_path, device_path, track_stale=False): 1027 def _GetChangedAndStaleFiles(self, host_path, device_path, track_stale=False):
1024 """Get files to push and delete 1028 """Get files to push and delete
1025 1029
1026 Args: 1030 Args:
1027 host_path: an absolute path of a file or directory on the host 1031 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 1032 device_path: an absolute path of a file or directory on the device
1029 track_stale: whether to bother looking for stale files (slower) 1033 track_stale: whether to bother looking for stale files (slower)
1030 1034
1031 Returns: 1035 Returns:
1032 a two-element tuple 1036 a three-element tuple
1033 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
1034 2nd element: a list of stale files under device_path, or [] when 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
1035 track_stale == False 1040 track_stale == False
1036 """ 1041 """
1037 try: 1042 try:
1038 host_checksums = md5sum.CalculateHostMd5Sums([host_path]) 1043 host_checksums = md5sum.CalculateHostMd5Sums([host_path])
1039 interesting_device_paths = [device_path] 1044 interesting_device_paths = [device_path]
1040 if not track_stale and os.path.isdir(host_path): 1045 if not track_stale and os.path.isdir(host_path):
1041 interesting_device_paths = [ 1046 interesting_device_paths = [
1042 posixpath.join(device_path, os.path.relpath(p, host_path)) 1047 posixpath.join(device_path, os.path.relpath(p, host_path))
1043 for p in host_checksums.keys()] 1048 for p in host_checksums.keys()]
1044 device_checksums = md5sum.CalculateDeviceMd5Sums( 1049 device_checksums = md5sum.CalculateDeviceMd5Sums(
1045 interesting_device_paths, self) 1050 interesting_device_paths, self)
1046 except EnvironmentError as e: 1051 except EnvironmentError as e:
1047 logging.warning('Error calculating md5: %s', e) 1052 logging.warning('Error calculating md5: %s', e)
1048 return ([(host_path, device_path)], []) 1053 return ([(host_path, device_path)], [], [])
1049 1054
1055 to_push = []
1056 up_to_date = []
1057 to_delete = []
1050 if os.path.isfile(host_path): 1058 if os.path.isfile(host_path):
1051 host_checksum = host_checksums.get(host_path) 1059 host_checksum = host_checksums.get(host_path)
1052 device_checksum = device_checksums.get(device_path) 1060 device_checksum = device_checksums.get(device_path)
1053 if host_checksum != device_checksum: 1061 if host_checksum == device_checksum:
1054 return ([(host_path, device_path)], []) 1062 up_to_date.append(host_path)
1055 else: 1063 else:
1056 return ([], []) 1064 to_push.append((host_path, device_path))
1057 else: 1065 else:
1058 to_push = []
1059 for host_abs_path, host_checksum in host_checksums.iteritems(): 1066 for host_abs_path, host_checksum in host_checksums.iteritems():
1060 device_abs_path = posixpath.join( 1067 device_abs_path = posixpath.join(
1061 device_path, os.path.relpath(host_abs_path, host_path)) 1068 device_path, os.path.relpath(host_abs_path, host_path))
1062 device_checksum = device_checksums.pop(device_abs_path, None) 1069 device_checksum = device_checksums.pop(device_abs_path, None)
1063 if device_checksum != host_checksum: 1070 if device_checksum == host_checksum:
1071 up_to_date.append(host_abs_path)
1072 else:
1064 to_push.append((host_abs_path, device_abs_path)) 1073 to_push.append((host_abs_path, device_abs_path))
1065 to_delete = device_checksums.keys() 1074 to_delete = device_checksums.keys()
1066 return (to_push, to_delete) 1075 return (to_push, up_to_date, to_delete)
1067 1076
1068 def _ComputeDeviceChecksumsForApks(self, package_name): 1077 def _ComputeDeviceChecksumsForApks(self, package_name):
1069 ret = self._cache['package_apk_checksums'].get(package_name) 1078 ret = self._cache['package_apk_checksums'].get(package_name)
1070 if ret is None: 1079 if ret is None:
1071 device_paths = self._GetApplicationPathsInternal(package_name) 1080 device_paths = self._GetApplicationPathsInternal(package_name)
1072 file_to_checksums = md5sum.CalculateDeviceMd5Sums(device_paths, self) 1081 file_to_checksums = md5sum.CalculateDeviceMd5Sums(device_paths, self)
1073 ret = set(file_to_checksums.values()) 1082 ret = set(file_to_checksums.values())
1074 self._cache['package_apk_checksums'][package_name] = ret 1083 self._cache['package_apk_checksums'][package_name] = ret
1075 return ret 1084 return ret
1076 1085
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() 1880 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices()
1872 if not blacklisted(adb)] 1881 if not blacklisted(adb)]
1873 1882
1874 @decorators.WithTimeoutAndRetriesFromInstance() 1883 @decorators.WithTimeoutAndRetriesFromInstance()
1875 def RestartAdbd(self, timeout=None, retries=None): 1884 def RestartAdbd(self, timeout=None, retries=None):
1876 logging.info('Restarting adbd on device.') 1885 logging.info('Restarting adbd on device.')
1877 with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script: 1886 with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script:
1878 self.WriteFile(script.name, _RESTART_ADBD_SCRIPT) 1887 self.WriteFile(script.name, _RESTART_ADBD_SCRIPT)
1879 self.RunShellCommand(['source', script.name], as_root=True) 1888 self.RunShellCommand(['source', script.name], as_root=True)
1880 self.adb.WaitForDevice() 1889 self.adb.WaitForDevice()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698