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 | 9 |
10 import collections | 10 import collections |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 apk_path: Path to .apk file to install. | 418 apk_path: Path to .apk file to install. |
419 keep_data: Reinstalls instead of uninstalling first, preserving the | 419 keep_data: Reinstalls instead of uninstalling first, preserving the |
420 application data. | 420 application data. |
421 package_name: Package name (only needed if keep_data=False). | 421 package_name: Package name (only needed if keep_data=False). |
422 reboots_on_failure: number of time to reboot if package manager is frozen. | 422 reboots_on_failure: number of time to reboot if package manager is frozen. |
423 """ | 423 """ |
424 # Check if package is already installed and up to date. | 424 # Check if package is already installed and up to date. |
425 if package_name: | 425 if package_name: |
426 installed_apk_path = self.GetApplicationPath(package_name) | 426 installed_apk_path = self.GetApplicationPath(package_name) |
427 if (installed_apk_path and | 427 if (installed_apk_path and |
428 not self.GetFilesChanged(apk_path, installed_apk_path)): | 428 not self.GetFilesChanged(apk_path, installed_apk_path, |
429 ignore_filenames=True)): | |
429 logging.info('Skipped install: identical %s APK already installed' % | 430 logging.info('Skipped install: identical %s APK already installed' % |
430 package_name) | 431 package_name) |
431 return | 432 return |
432 # Install. | 433 # Install. |
433 reboots_left = reboots_on_failure | 434 reboots_left = reboots_on_failure |
434 while True: | 435 while True: |
435 try: | 436 try: |
436 if not keep_data: | 437 if not keep_data: |
437 assert package_name | 438 assert package_name |
438 self.Uninstall(package_name) | 439 self.Uninstall(package_name) |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
798 cmd = (MD5SUM_LD_LIBRARY_PATH + ' ' + self._util_wrapper + ' ' + | 799 cmd = (MD5SUM_LD_LIBRARY_PATH + ' ' + self._util_wrapper + ' ' + |
799 MD5SUM_DEVICE_PATH + ' ' + device_path) | 800 MD5SUM_DEVICE_PATH + ' ' + device_path) |
800 device_hash_tuples = _ParseMd5SumOutput( | 801 device_hash_tuples = _ParseMd5SumOutput( |
801 self.RunShellCommand(cmd, timeout_time=2 * 60)) | 802 self.RunShellCommand(cmd, timeout_time=2 * 60)) |
802 assert os.path.exists(host_path), 'Local path not found %s' % host_path | 803 assert os.path.exists(host_path), 'Local path not found %s' % host_path |
803 md5sum_output = cmd_helper.GetCmdOutput( | 804 md5sum_output = cmd_helper.GetCmdOutput( |
804 ['%s/md5sum_bin_host' % self._md5sum_build_dir, host_path]) | 805 ['%s/md5sum_bin_host' % self._md5sum_build_dir, host_path]) |
805 host_hash_tuples = _ParseMd5SumOutput(md5sum_output.splitlines()) | 806 host_hash_tuples = _ParseMd5SumOutput(md5sum_output.splitlines()) |
806 return (host_hash_tuples, device_hash_tuples) | 807 return (host_hash_tuples, device_hash_tuples) |
807 | 808 |
808 def GetFilesChanged(self, host_path, device_path): | 809 def GetFilesChanged(self, host_path, device_path, ignore_filenames=False): |
frankf
2013/09/04 21:52:21
This needs to be cleaned up and move to its own ut
| |
809 """Compares the md5sum of a host path against a device path. | 810 """Compares the md5sum of a host path against a device path. |
810 | 811 |
811 Note: Ignores extra files on the device. | 812 Note: Ignores extra files on the device. |
812 | 813 |
813 Args: | 814 Args: |
814 host_path: Path (file or directory) on the host. | 815 host_path: Path (file or directory) on the host. |
815 device_path: Path on the device. | 816 device_path: Path on the device. |
817 ignore_filenames: If True only the file contents are considered when | |
818 checking whether a file has changed, otherwise the relative path | |
819 must also match. | |
816 | 820 |
817 Returns: | 821 Returns: |
818 A list of tuples of the form (host_path, device_path) for files whose | 822 A list of tuples of the form (host_path, device_path) for files whose |
819 md5sums do not match. | 823 md5sums do not match. |
820 """ | 824 """ |
821 host_hash_tuples, device_hash_tuples = self._RunMd5Sum( | 825 host_hash_tuples, device_hash_tuples = self._RunMd5Sum( |
822 host_path, device_path) | 826 host_path, device_path) |
823 | 827 |
824 # Ignore extra files on the device. | 828 # Ignore extra files on the device. |
825 if len(device_hash_tuples) > len(host_hash_tuples): | 829 if not ignore_filenames: |
826 host_files = [os.path.relpath(os.path.normpath(p.path), | 830 host_files = [os.path.relpath(os.path.normpath(p.path), |
827 os.path.normpath(host_path)) for p in host_hash_tuples] | 831 os.path.normpath(host_path)) for p in host_hash_tuples] |
828 | 832 |
829 def HostHas(fname): | 833 def HostHas(fname): |
830 return any(path in fname for path in host_files) | 834 return any(path in fname for path in host_files) |
831 | 835 |
832 device_hash_tuples = [h for h in device_hash_tuples if HostHas(h.path)] | 836 device_hash_tuples = [h for h in device_hash_tuples if HostHas(h.path)] |
833 | 837 |
834 # Constructs the target device path from a given host path. Don't use when | 838 # Constructs the target device path from a given host path. Don't use when |
835 # only a single file is given as the base name given in device_path may | 839 # only a single file is given as the base name given in device_path may |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1548 """ | 1552 """ |
1549 def __init__(self, output): | 1553 def __init__(self, output): |
1550 self._output = output | 1554 self._output = output |
1551 | 1555 |
1552 def write(self, data): | 1556 def write(self, data): |
1553 data = data.replace('\r\r\n', '\n') | 1557 data = data.replace('\r\r\n', '\n') |
1554 self._output.write(data) | 1558 self._output.write(data) |
1555 | 1559 |
1556 def flush(self): | 1560 def flush(self): |
1557 self._output.flush() | 1561 self._output.flush() |
OLD | NEW |