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

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

Issue 57633003: Make PushIfNeeded do what is says. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 7 years, 1 month 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 (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 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 host_path: Path (file or directory) on the host. 834 host_path: Path (file or directory) on the host.
835 device_path: Path on the device. 835 device_path: Path on the device.
836 ignore_filenames: If True only the file contents are considered when 836 ignore_filenames: If True only the file contents are considered when
837 checking whether a file has changed, otherwise the relative path 837 checking whether a file has changed, otherwise the relative path
838 must also match. 838 must also match.
839 839
840 Returns: 840 Returns:
841 A list of tuples of the form (host_path, device_path) for files whose 841 A list of tuples of the form (host_path, device_path) for files whose
842 md5sums do not match. 842 md5sums do not match.
843 """ 843 """
844
845 # Md5Sum resolves symbolic links in path names so the calculation of
846 # relative path names from its output will need the real path names of the
847 # base directories. Having calculated these they are used throughout the
848 # function since this makes us less subject to any future changes to Md5Sum.
849 real_host_path = os.path.realpath(host_path)
850 real_device_path = self.RunShellCommand('realpath "%s"' % device_path)[0]
851
844 host_hash_tuples, device_hash_tuples = self._RunMd5Sum( 852 host_hash_tuples, device_hash_tuples = self._RunMd5Sum(
845 host_path, device_path) 853 real_host_path, real_device_path)
846 854
847 # Ignore extra files on the device. 855 # Ignore extra files on the device.
848 if not ignore_filenames: 856 if not ignore_filenames:
849 host_files = [os.path.relpath(os.path.normpath(p.path), 857 host_files = [os.path.relpath(os.path.normpath(p.path),
850 os.path.normpath(host_path)) for p in host_hash_tuples] 858 real_host_path) for p in host_hash_tuples]
851 859
852 def HostHas(fname): 860 def HostHas(fname):
853 return any(path in fname for path in host_files) 861 return any(path in fname for path in host_files)
854 862
855 device_hash_tuples = [h for h in device_hash_tuples if HostHas(h.path)] 863 device_hash_tuples = [h for h in device_hash_tuples if HostHas(h.path)]
856 864
857 if len(host_hash_tuples) > len(device_hash_tuples): 865 if len(host_hash_tuples) > len(device_hash_tuples):
858 logging.info('%s files do not exist on the device' % 866 logging.info('%s files do not exist on the device' %
859 (len(host_hash_tuples) - len(device_hash_tuples))) 867 (len(host_hash_tuples) - len(device_hash_tuples)))
860 868
861 # Constructs the target device path from a given host path. Don't use when 869 # Constructs the target device path from a given host path. Don't use when
862 # only a single file is given as the base name given in device_path may 870 # only a single file is given as the base name given in device_path may
863 # differ from that in host_path. 871 # differ from that in host_path.
864 def HostToDevicePath(host_file_path): 872 def HostToDevicePath(host_file_path):
865 return os.path.join(device_path, os.path.relpath( 873 return os.path.join(device_path, os.path.relpath(host_file_path,
866 host_file_path, os.path.normpath(host_path))) 874 real_host_path))
867 875
868 device_hashes = [h.hash for h in device_hash_tuples] 876 device_hashes = [h.hash for h in device_hash_tuples]
869 return [(t.path, HostToDevicePath(t.path) if os.path.isdir(host_path) else 877 return [(t.path, HostToDevicePath(t.path) if
870 device_path) 878 os.path.isdir(real_host_path) else real_device_path)
871 for t in host_hash_tuples if t.hash not in device_hashes] 879 for t in host_hash_tuples if t.hash not in device_hashes]
872 880
873 def PushIfNeeded(self, host_path, device_path): 881 def PushIfNeeded(self, host_path, device_path):
874 """Pushes |host_path| to |device_path|. 882 """Pushes |host_path| to |device_path|.
875 883
876 Works for files and directories. This method skips copying any paths in 884 Works for files and directories. This method skips copying any paths in
877 |test_data_paths| that already exist on the device with the same hash. 885 |test_data_paths| that already exist on the device with the same hash.
878 886
879 All pushed files can be removed by calling RemovePushedFiles(). 887 All pushed files can be removed by calling RemovePushedFiles().
880 """ 888 """
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
1654 """ 1662 """
1655 def __init__(self, output): 1663 def __init__(self, output):
1656 self._output = output 1664 self._output = output
1657 1665
1658 def write(self, data): 1666 def write(self, data):
1659 data = data.replace('\r\r\n', '\n') 1667 data = data.replace('\r\r\n', '\n')
1660 self._output.write(data) 1668 self._output.write(data)
1661 1669
1662 def flush(self): 1670 def flush(self):
1663 self._output.flush() 1671 self._output.flush()
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