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

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

Issue 197883005: [Telementry][Android] Only copy changed or missing files of profile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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
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 1782 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 package = match.group(2) 1793 package = match.group(2)
1794 logging.warning('Trying to dismiss %s dialog for %s' % match.groups()) 1794 logging.warning('Trying to dismiss %s dialog for %s' % match.groups())
1795 self.SendKeyEvent(KEYCODE_DPAD_RIGHT) 1795 self.SendKeyEvent(KEYCODE_DPAD_RIGHT)
1796 self.SendKeyEvent(KEYCODE_DPAD_RIGHT) 1796 self.SendKeyEvent(KEYCODE_DPAD_RIGHT)
1797 self.SendKeyEvent(KEYCODE_ENTER) 1797 self.SendKeyEvent(KEYCODE_ENTER)
1798 match = _FindFocusedWindow() 1798 match = _FindFocusedWindow()
1799 if match: 1799 if match:
1800 logging.error('Still showing a %s dialog for %s' % match.groups()) 1800 logging.error('Still showing a %s dialog for %s' % match.groups())
1801 return package 1801 return package
1802 1802
1803 def EfficientDeviceDirectoryCopy(self, source, dest):
1804 """ Copy a directory efficiently on the device
1805
1806 Copy new and changed files the source directory to the destination directory
1807 and remove added files. This is in some cases much faster than cp -r.
1808
1809 Args:
1810 source: absolute path of source directory
1811 dest: absolute path of destination directory
1812 """
1813 logging.info("In EfficientDeviceDirectoryCopy %s %s" % (source, dest))
bulach 2014/03/13 17:22:57 nit: s/"/'/ also, s/%/,/ that is, logging.info t
1814 script = """
bulach 2014/03/13 17:22:57 would it make sense to have this in a separate fil
aberent 2014/03/13 18:32:45 Done.
1815 source=$1
1816 dest=$2
1817 echo copying $source to $dest
1818
1819 delete_extra() {
1820 # Don't delete symbolic links, since doing so deletes the vital lib link.
1821 if [ ! -L "$1" ]
1822 then
1823 if [ ! -e "$source/$1" ]
1824 then
1825 echo rm -rf "$dest/$1"
1826 rm -rf "$dest/$1"
1827 elif [ -d "$1" ]
1828 then
1829 for f in "$1"/*
1830 do
1831 delete_extra "$f"
1832 done
1833 fi
1834 fi
1835 }
1836
1837 copy_if_older() {
1838 if [ -d "$1" ] && [ -e "$dest/$1" ]
1839 then
1840 if [ ! -e "$dest/$1" ]
1841 then
1842 echo cp -a "$1" "$dest/$1"
1843 cp -a "$1" "$dest/$1"
1844 else
1845 for f in "$1"/*
1846 do
1847 copy_if_older "$f"
bulach 2014/03/13 17:22:57 indent
aberent 2014/03/13 18:32:45 Done.
1848 done
1849 fi
1850 elif [ ! -e "$dest/$1" ] || [ "$1" -ot "$dest/$1" ]
1851 then
1852 echo cp -a "$1" "$dest/$1"
1853 cp -a "$1" "$dest/$1"
1854 fi
1855 }
1856
1857 if [ -e "$dest" ]
1858 then
1859 echo cd "$dest"
1860 cd "$dest"
1861 for f in ./*
1862 do
1863 if [ -e "$f" ]
1864 then
1865 delete_extra "$f"
1866 fi
1867 done
1868 else
1869 echo mkdir "$dest"
1870 mkdir "$dest"
1871 fi
1872 echo cd "$source"
1873 cd "$source"
1874 for f in ./*
1875 do
1876 if [ -e "$f" ]
1877 then
1878 copy_if_older "$f"
1879 fi
1880 done
1881 """
1882 temp_script_file = self._GetDeviceTempFileName(
1883 AndroidCommands._TEMP_SCRIPT_FILE_BASE_FMT)
1884 self.SetFileContents(temp_script_file, script)
1885 self.EnableAdbRoot
1886 out = self.RunShellCommand("sh %s %s %s" % (temp_script_file, source, dest),
bulach 2014/03/13 17:22:57 nit: s/"/'/
aberent 2014/03/13 18:32:45 Done.
1887 timeout_time=120)
1888 if self._device:
1889 device_repr = self._device[-4:]
1890 else:
1891 device_repr = '????'
1892 for line in out:
1893 logging.info('[%s]> %s', device_repr, line)
bulach 2014/03/13 17:22:57 I think logging is already hooked up to have a dev
aberent 2014/03/13 18:32:45 No, the device is added by RunShellCommand, but th
1894
1803 1895
1804 class NewLineNormalizer(object): 1896 class NewLineNormalizer(object):
1805 """A file-like object to normalize EOLs to '\n'. 1897 """A file-like object to normalize EOLs to '\n'.
1806 1898
1807 Pexpect runs adb within a pseudo-tty device (see 1899 Pexpect runs adb within a pseudo-tty device (see
1808 http://www.noah.org/wiki/pexpect), so any '\n' printed by adb is written 1900 http://www.noah.org/wiki/pexpect), so any '\n' printed by adb is written
1809 as '\r\n' to the logfile. Since adb already uses '\r\n' to terminate 1901 as '\r\n' to the logfile. Since adb already uses '\r\n' to terminate
1810 lines, the log ends up having '\r\r\n' at the end of each line. This 1902 lines, the log ends up having '\r\r\n' at the end of each line. This
1811 filter replaces the above with a single '\n' in the data stream. 1903 filter replaces the above with a single '\n' in the data stream.
1812 """ 1904 """
1813 def __init__(self, output): 1905 def __init__(self, output):
1814 self._output = output 1906 self._output = output
1815 1907
1816 def write(self, data): 1908 def write(self, data):
1817 data = data.replace('\r\r\n', '\n') 1909 data = data.replace('\r\r\n', '\n')
1818 self._output.write(data) 1910 self._output.write(data)
1819 1911
1820 def flush(self): 1912 def flush(self):
1821 self._output.flush() 1913 self._output.flush()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698