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

Side by Side Diff: build/android/pylib/android_commands.py

Issue 358993003: [Android] Switch to DeviceUtils versions of file functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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 | « build/android/provision_devices.py ('k') | build/android/pylib/base/base_test_runner.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 an interface to communicate with the device via the adb command. 5 """Provides an interface to communicate with the device via the adb command.
6 6
7 Assumes adb binary is currently on system path. 7 Assumes adb binary is currently on system path.
8 """ 8 """
9 # pylint: disable-all 9 # pylint: disable-all
10 10
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 1047
1048 def PushIfNeeded(self, host_path, device_path): 1048 def PushIfNeeded(self, host_path, device_path):
1049 """Pushes |host_path| to |device_path|. 1049 """Pushes |host_path| to |device_path|.
1050 1050
1051 Works for files and directories. This method skips copying any paths in 1051 Works for files and directories. This method skips copying any paths in
1052 |test_data_paths| that already exist on the device with the same hash. 1052 |test_data_paths| that already exist on the device with the same hash.
1053 1053
1054 All pushed files can be removed by calling RemovePushedFiles(). 1054 All pushed files can be removed by calling RemovePushedFiles().
1055 """ 1055 """
1056 MAX_INDIVIDUAL_PUSHES = 50 1056 MAX_INDIVIDUAL_PUSHES = 50
1057 assert os.path.exists(host_path), 'Local path not found %s' % host_path 1057 if not os.path.exists(host_path):
1058 raise device_errors.CommandFailedError(
1059 'Local path not found %s' % host_path, device=str(self))
1058 1060
1059 # See if the file on the host changed since the last push (if any) and 1061 # See if the file on the host changed since the last push (if any) and
1060 # return early if it didn't. Note that this shortcut assumes that the tests 1062 # return early if it didn't. Note that this shortcut assumes that the tests
1061 # on the device don't modify the files. 1063 # on the device don't modify the files.
1062 if not os.path.isdir(host_path): 1064 if not os.path.isdir(host_path):
1063 if host_path in self._push_if_needed_cache: 1065 if host_path in self._push_if_needed_cache:
1064 host_path_mtime = self._push_if_needed_cache[host_path] 1066 host_path_mtime = self._push_if_needed_cache[host_path]
1065 if host_path_mtime == os.stat(host_path).st_mtime: 1067 if host_path_mtime == os.stat(host_path).st_mtime:
1066 return 1068 return
1067 1069
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 1105
1104 diff_size = 0 1106 diff_size = 0
1105 if len(changed_files) <= MAX_INDIVIDUAL_PUSHES: 1107 if len(changed_files) <= MAX_INDIVIDUAL_PUSHES:
1106 diff_size = sum(host_utils.GetRecursiveDiskUsage(f[0]) 1108 diff_size = sum(host_utils.GetRecursiveDiskUsage(f[0])
1107 for f in changed_files) 1109 for f in changed_files)
1108 1110
1109 # TODO(craigdh): Replace this educated guess with a heuristic that 1111 # TODO(craigdh): Replace this educated guess with a heuristic that
1110 # approximates the push time for each method. 1112 # approximates the push time for each method.
1111 if len(changed_files) > MAX_INDIVIDUAL_PUSHES or diff_size > 0.5 * size: 1113 if len(changed_files) > MAX_INDIVIDUAL_PUSHES or diff_size > 0.5 * size:
1112 self._actual_push_size += size 1114 self._actual_push_size += size
1113 if os.path.isdir(host_path):
1114 self.RunShellCommand('mkdir -p %s' % device_path)
1115 Push(host_path, device_path) 1115 Push(host_path, device_path)
1116 else: 1116 else:
1117 for f in changed_files: 1117 for f in changed_files:
1118 Push(f[0], f[1]) 1118 Push(f[0], f[1])
1119 self._actual_push_size += diff_size 1119 self._actual_push_size += diff_size
1120 1120
1121 def GetPushSizeInfo(self): 1121 def GetPushSizeInfo(self):
1122 """Get total size of pushes to the device done via PushIfNeeded() 1122 """Get total size of pushes to the device done via PushIfNeeded()
1123 1123
1124 Returns: 1124 Returns:
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 self.RunShellCommand('rm -f "%s"' % device_file) 1776 self.RunShellCommand('rm -f "%s"' % device_file)
1777 return host_file 1777 return host_file
1778 1778
1779 def PullFileFromDevice(self, device_file, host_file): 1779 def PullFileFromDevice(self, device_file, host_file):
1780 """Download |device_file| on the device from to |host_file| on the host. 1780 """Download |device_file| on the device from to |host_file| on the host.
1781 1781
1782 Args: 1782 Args:
1783 device_file: Absolute path to the file to retrieve from the device. 1783 device_file: Absolute path to the file to retrieve from the device.
1784 host_file: Absolute path to the file to store on the host. 1784 host_file: Absolute path to the file to store on the host.
1785 """ 1785 """
1786 assert self._adb.Pull(device_file, host_file) 1786 if not self._adb.Pull(device_file, host_file):
1787 raise device_errors.AdbCommandFailedError(
1788 ['pull', device_file, host_file], 'Failed to pull file from device.')
1787 assert os.path.exists(host_file) 1789 assert os.path.exists(host_file)
1788 1790
1789 def SetUtilWrapper(self, util_wrapper): 1791 def SetUtilWrapper(self, util_wrapper):
1790 """Sets a wrapper prefix to be used when running a locally-built 1792 """Sets a wrapper prefix to be used when running a locally-built
1791 binary on the device (ex.: md5sum_bin). 1793 binary on the device (ex.: md5sum_bin).
1792 """ 1794 """
1793 self._util_wrapper = util_wrapper 1795 self._util_wrapper = util_wrapper
1794 1796
1795 def RunInstrumentationTest(self, test, test_package, instr_args, timeout): 1797 def RunInstrumentationTest(self, test, test_package, instr_args, timeout):
1796 """Runs a single instrumentation test. 1798 """Runs a single instrumentation test.
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1966 """ 1968 """
1967 def __init__(self, output): 1969 def __init__(self, output):
1968 self._output = output 1970 self._output = output
1969 1971
1970 def write(self, data): 1972 def write(self, data):
1971 data = data.replace('\r\r\n', '\n') 1973 data = data.replace('\r\r\n', '\n')
1972 self._output.write(data) 1974 self._output.write(data)
1973 1975
1974 def flush(self): 1976 def flush(self):
1975 self._output.flush() 1977 self._output.flush()
OLDNEW
« no previous file with comments | « build/android/provision_devices.py ('k') | build/android/pylib/base/base_test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698