OLD | NEW |
---|---|
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 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
994 | 994 |
995 # See if the file on the host changed since the last push (if any) and | 995 # See if the file on the host changed since the last push (if any) and |
996 # return early if it didn't. Note that this shortcut assumes that the tests | 996 # return early if it didn't. Note that this shortcut assumes that the tests |
997 # on the device don't modify the files. | 997 # on the device don't modify the files. |
998 if not os.path.isdir(host_path): | 998 if not os.path.isdir(host_path): |
999 if host_path in self._push_if_needed_cache: | 999 if host_path in self._push_if_needed_cache: |
1000 host_path_mtime = self._push_if_needed_cache[host_path] | 1000 host_path_mtime = self._push_if_needed_cache[host_path] |
1001 if host_path_mtime == os.stat(host_path).st_mtime: | 1001 if host_path_mtime == os.stat(host_path).st_mtime: |
1002 return | 1002 return |
1003 | 1003 |
1004 def GetHostSize(path): | 1004 size = os.stat(host_path).st_size |
1005 return int(cmd_helper.GetCmdOutput(['du', '-sb', path]).split()[0]) | |
1006 | |
1007 size = GetHostSize(host_path) | |
1008 self._pushed_files.append(device_path) | 1005 self._pushed_files.append(device_path) |
1009 self._potential_push_size += size | 1006 self._potential_push_size += size |
1010 | 1007 |
1011 changed_files = self.GetFilesChanged(host_path, device_path) | 1008 changed_files = self.GetFilesChanged(host_path, device_path) |
1012 logging.info('Found %d files that need to be pushed to %s', | 1009 logging.info('Found %d files that need to be pushed to %s', |
1013 len(changed_files), device_path) | 1010 len(changed_files), device_path) |
1014 if not changed_files: | 1011 if not changed_files: |
1015 return | 1012 return |
1016 | 1013 |
1017 def Push(host, device): | 1014 def Push(host, device): |
(...skipping 14 matching lines...) Expand all Loading... | |
1032 retry += 1 | 1029 retry += 1 |
1033 wait_time = 5 * retry | 1030 wait_time = 5 * retry |
1034 logging.error('Push failed, retrying in %d seconds: %s' % | 1031 logging.error('Push failed, retrying in %d seconds: %s' % |
1035 (wait_time, output)) | 1032 (wait_time, output)) |
1036 time.sleep(wait_time) | 1033 time.sleep(wait_time) |
1037 else: | 1034 else: |
1038 raise Exception('Push failed: %s' % output) | 1035 raise Exception('Push failed: %s' % output) |
1039 | 1036 |
1040 diff_size = 0 | 1037 diff_size = 0 |
1041 if len(changed_files) <= MAX_INDIVIDUAL_PUSHES: | 1038 if len(changed_files) <= MAX_INDIVIDUAL_PUSHES: |
1042 diff_size = sum(GetHostSize(f[0]) for f in changed_files) | 1039 diff_size = sum(os.stat(f[0]).st_size for f in changed_files) |
craigdh
2014/03/24 19:19:54
This doesn't work for directories.
| |
1043 | 1040 |
1044 # TODO(craigdh): Replace this educated guess with a heuristic that | 1041 # TODO(craigdh): Replace this educated guess with a heuristic that |
1045 # approximates the push time for each method. | 1042 # approximates the push time for each method. |
1046 if len(changed_files) > MAX_INDIVIDUAL_PUSHES or diff_size > 0.5 * size: | 1043 if len(changed_files) > MAX_INDIVIDUAL_PUSHES or diff_size > 0.5 * size: |
1047 self._actual_push_size += size | 1044 self._actual_push_size += size |
1048 if os.path.isdir(host_path): | 1045 if os.path.isdir(host_path): |
1049 self.RunShellCommand('mkdir -p %s' % device_path) | 1046 self.RunShellCommand('mkdir -p %s' % device_path) |
1050 Push(host_path, device_path) | 1047 Push(host_path, device_path) |
1051 else: | 1048 else: |
1052 for f in changed_files: | 1049 for f in changed_files: |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1843 """ | 1840 """ |
1844 def __init__(self, output): | 1841 def __init__(self, output): |
1845 self._output = output | 1842 self._output = output |
1846 | 1843 |
1847 def write(self, data): | 1844 def write(self, data): |
1848 data = data.replace('\r\r\n', '\n') | 1845 data = data.replace('\r\r\n', '\n') |
1849 self._output.write(data) | 1846 self._output.write(data) |
1850 | 1847 |
1851 def flush(self): | 1848 def flush(self): |
1852 self._output.flush() | 1849 self._output.flush() |
OLD | NEW |