| 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 |
| 11 import collections | 11 import collections |
| 12 import datetime | 12 import datetime |
| 13 import inspect | 13 import inspect |
| 14 import json | 14 import json |
| 15 import logging | 15 import logging |
| 16 import os | 16 import os |
| 17 import re | 17 import re |
| 18 import shlex | 18 import shlex |
| 19 import signal | 19 import signal |
| 20 import subprocess | 20 import subprocess |
| 21 import sys | 21 import sys |
| 22 import tempfile | 22 import tempfile |
| 23 import time | 23 import time |
| 24 | 24 |
| 25 import cmd_helper | 25 import cmd_helper |
| 26 import constants | 26 import constants |
| 27 import screenshot | 27 import screenshot |
| 28 import system_properties | 28 import system_properties |
| 29 from utils import host_utils |
| 29 | 30 |
| 30 try: | 31 try: |
| 31 from pylib import pexpect | 32 from pylib import pexpect |
| 32 except ImportError: | 33 except ImportError: |
| 33 pexpect = None | 34 pexpect = None |
| 34 | 35 |
| 35 sys.path.append(os.path.join( | 36 sys.path.append(os.path.join( |
| 36 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) | 37 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) |
| 37 import adb_interface | 38 import adb_interface |
| 38 import am_instrument_parser | 39 import am_instrument_parser |
| (...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 | 995 |
| 995 # See if the file on the host changed since the last push (if any) and | 996 # 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 | 997 # return early if it didn't. Note that this shortcut assumes that the tests |
| 997 # on the device don't modify the files. | 998 # on the device don't modify the files. |
| 998 if not os.path.isdir(host_path): | 999 if not os.path.isdir(host_path): |
| 999 if host_path in self._push_if_needed_cache: | 1000 if host_path in self._push_if_needed_cache: |
| 1000 host_path_mtime = self._push_if_needed_cache[host_path] | 1001 host_path_mtime = self._push_if_needed_cache[host_path] |
| 1001 if host_path_mtime == os.stat(host_path).st_mtime: | 1002 if host_path_mtime == os.stat(host_path).st_mtime: |
| 1002 return | 1003 return |
| 1003 | 1004 |
| 1004 def GetHostSize(path): | 1005 size = host_utils.GetRecursiveDiskUsage(host_path) |
| 1005 return int(cmd_helper.GetCmdOutput(['du', '-sb', path]).split()[0]) | |
| 1006 | |
| 1007 size = GetHostSize(host_path) | |
| 1008 self._pushed_files.append(device_path) | 1006 self._pushed_files.append(device_path) |
| 1009 self._potential_push_size += size | 1007 self._potential_push_size += size |
| 1010 | 1008 |
| 1011 changed_files = self.GetFilesChanged(host_path, device_path) | 1009 changed_files = self.GetFilesChanged(host_path, device_path) |
| 1012 logging.info('Found %d files that need to be pushed to %s', | 1010 logging.info('Found %d files that need to be pushed to %s', |
| 1013 len(changed_files), device_path) | 1011 len(changed_files), device_path) |
| 1014 if not changed_files: | 1012 if not changed_files: |
| 1015 return | 1013 return |
| 1016 | 1014 |
| 1017 def Push(host, device): | 1015 def Push(host, device): |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1032 retry += 1 | 1030 retry += 1 |
| 1033 wait_time = 5 * retry | 1031 wait_time = 5 * retry |
| 1034 logging.error('Push failed, retrying in %d seconds: %s' % | 1032 logging.error('Push failed, retrying in %d seconds: %s' % |
| 1035 (wait_time, output)) | 1033 (wait_time, output)) |
| 1036 time.sleep(wait_time) | 1034 time.sleep(wait_time) |
| 1037 else: | 1035 else: |
| 1038 raise Exception('Push failed: %s' % output) | 1036 raise Exception('Push failed: %s' % output) |
| 1039 | 1037 |
| 1040 diff_size = 0 | 1038 diff_size = 0 |
| 1041 if len(changed_files) <= MAX_INDIVIDUAL_PUSHES: | 1039 if len(changed_files) <= MAX_INDIVIDUAL_PUSHES: |
| 1042 diff_size = sum(GetHostSize(f[0]) for f in changed_files) | 1040 diff_size = sum(host_utils.GetRecursiveDiskUsage(f[0]) |
| 1041 for f in changed_files) |
| 1043 | 1042 |
| 1044 # TODO(craigdh): Replace this educated guess with a heuristic that | 1043 # TODO(craigdh): Replace this educated guess with a heuristic that |
| 1045 # approximates the push time for each method. | 1044 # approximates the push time for each method. |
| 1046 if len(changed_files) > MAX_INDIVIDUAL_PUSHES or diff_size > 0.5 * size: | 1045 if len(changed_files) > MAX_INDIVIDUAL_PUSHES or diff_size > 0.5 * size: |
| 1047 self._actual_push_size += size | 1046 self._actual_push_size += size |
| 1048 if os.path.isdir(host_path): | 1047 if os.path.isdir(host_path): |
| 1049 self.RunShellCommand('mkdir -p %s' % device_path) | 1048 self.RunShellCommand('mkdir -p %s' % device_path) |
| 1050 Push(host_path, device_path) | 1049 Push(host_path, device_path) |
| 1051 else: | 1050 else: |
| 1052 for f in changed_files: | 1051 for f in changed_files: |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1843 """ | 1842 """ |
| 1844 def __init__(self, output): | 1843 def __init__(self, output): |
| 1845 self._output = output | 1844 self._output = output |
| 1846 | 1845 |
| 1847 def write(self, data): | 1846 def write(self, data): |
| 1848 data = data.replace('\r\r\n', '\n') | 1847 data = data.replace('\r\r\n', '\n') |
| 1849 self._output.write(data) | 1848 self._output.write(data) |
| 1850 | 1849 |
| 1851 def flush(self): | 1850 def flush(self): |
| 1852 self._output.flush() | 1851 self._output.flush() |
| OLD | NEW |