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

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

Issue 270833004: Android: Make sure temporary scripts are deleted from the device (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« 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 # pylint: disable-all 9 # pylint: disable-all
10 10
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 return command_runner(command) 1153 return command_runner(command)
1154 else: 1154 else:
1155 logging.warning('Could not access protected file: %s' % filename) 1155 logging.warning('Could not access protected file: %s' % filename)
1156 return [] 1156 return []
1157 1157
1158 def SetProtectedFileContents(self, filename, contents): 1158 def SetProtectedFileContents(self, filename, contents):
1159 """Writes |contents| to the protected file specified by |filename|. 1159 """Writes |contents| to the protected file specified by |filename|.
1160 1160
1161 This is less efficient than SetFileContents. 1161 This is less efficient than SetFileContents.
1162 """ 1162 """
1163 # TODO(skyostil): Remove this once it has been through all the bots.
jbudorick 2014/05/08 15:37:25 I'm not sure I like this idea, but I suppose this
Sami 2014/05/08 15:57:11 Yeah, AFAIK we don't have any easy way to run thes
Yaron 2014/05/08 17:08:16 I think it's the easiest way to clean up the curre
1164 for file_name in (AndroidCommands._TEMP_FILE_BASE_FMT,
1165 AndroidCommands._TEMP_SCRIPT_FILE_BASE_FMT):
1166 self.RunShellCommand('rm ' + self.GetExternalStorage() + '/' +
1167 file_name.replace('%d', '*'))
1168
1163 temp_file = self._GetDeviceTempFileName(AndroidCommands._TEMP_FILE_BASE_FMT) 1169 temp_file = self._GetDeviceTempFileName(AndroidCommands._TEMP_FILE_BASE_FMT)
1164 temp_script = self._GetDeviceTempFileName( 1170 temp_script = self._GetDeviceTempFileName(
1165 AndroidCommands._TEMP_SCRIPT_FILE_BASE_FMT) 1171 AndroidCommands._TEMP_SCRIPT_FILE_BASE_FMT)
1166 1172
1167 # Put the contents in a temporary file 1173 try:
1168 self.SetFileContents(temp_file, contents) 1174 # Put the contents in a temporary file
1169 # Create a script to copy the file contents to its final destination 1175 self.SetFileContents(temp_file, contents)
1170 self.SetFileContents(temp_script, 'cat %s > %s' % (temp_file, filename)) 1176 # Create a script to copy the file contents to its final destination
1177 self.SetFileContents(temp_script, 'cat %s > %s' % (temp_file, filename))
1171 1178
1172 command = 'sh %s' % temp_script 1179 command = 'sh %s' % temp_script
1173 command_runner = self._GetProtectedFileCommandRunner() 1180 command_runner = self._GetProtectedFileCommandRunner()
1174 if command_runner: 1181 if command_runner:
1175 return command_runner(command) 1182 return command_runner(command)
1176 else: 1183 else:
1177 logging.warning('Could not set contents of protected file: %s' % filename) 1184 logging.warning(
1178 1185 'Could not set contents of protected file: %s' % filename)
1179 # And remove the temporary files 1186 finally:
1180 self.RunShellCommand('rm ' + temp_file) 1187 # And remove the temporary files
1181 self.RunShellCommand('rm ' + temp_script) 1188 self.RunShellCommand('rm ' + temp_file)
1189 self.RunShellCommand('rm ' + temp_script)
1182 1190
1183 def RemovePushedFiles(self): 1191 def RemovePushedFiles(self):
1184 """Removes all files pushed with PushIfNeeded() from the device.""" 1192 """Removes all files pushed with PushIfNeeded() from the device."""
1185 for p in self._pushed_files: 1193 for p in self._pushed_files:
1186 self.RunShellCommand('rm -r %s' % p, timeout_time=2 * 60) 1194 self.RunShellCommand('rm -r %s' % p, timeout_time=2 * 60)
1187 1195
1188 def ListPathContents(self, path): 1196 def ListPathContents(self, path):
1189 """Lists files in all subdirectories of |path|. 1197 """Lists files in all subdirectories of |path|.
1190 1198
1191 Args: 1199 Args:
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 dest: absolute path of destination directory 1892 dest: absolute path of destination directory
1885 """ 1893 """
1886 logging.info('In EfficientDeviceDirectoryCopy %s %s', source, dest) 1894 logging.info('In EfficientDeviceDirectoryCopy %s %s', source, dest)
1887 temp_script_file = self._GetDeviceTempFileName( 1895 temp_script_file = self._GetDeviceTempFileName(
1888 AndroidCommands._TEMP_SCRIPT_FILE_BASE_FMT) 1896 AndroidCommands._TEMP_SCRIPT_FILE_BASE_FMT)
1889 host_script_path = os.path.join(constants.DIR_SOURCE_ROOT, 1897 host_script_path = os.path.join(constants.DIR_SOURCE_ROOT,
1890 'build', 1898 'build',
1891 'android', 1899 'android',
1892 'pylib', 1900 'pylib',
1893 'efficient_android_directory_copy.sh') 1901 'efficient_android_directory_copy.sh')
1894 self._adb.Push(host_script_path, temp_script_file) 1902 try:
1895 self.EnableAdbRoot 1903 self._adb.Push(host_script_path, temp_script_file)
1896 out = self.RunShellCommand('sh %s %s %s' % (temp_script_file, source, dest), 1904 self.EnableAdbRoot
Sami 2014/05/08 15:14:36 This line makes me say hmm...
bulach 2014/05/08 15:25:03 my bad, I didn't spot this.. :( https://coderevie
1897 timeout_time=120) 1905 out = self.RunShellCommand('sh %s %s %s' % (temp_script_file,
1898 if self._device: 1906 source,
1899 device_repr = self._device[-4:] 1907 dest),
1900 else: 1908 timeout_time=120)
1901 device_repr = '????' 1909 if self._device:
1902 for line in out: 1910 device_repr = self._device[-4:]
1903 logging.info('[%s]> %s', device_repr, line) 1911 else:
1904 self.RunShellCommand('rm %s' % temp_script_file) 1912 device_repr = '????'
1913 for line in out:
1914 logging.info('[%s]> %s', device_repr, line)
1915 finally:
1916 self.RunShellCommand('rm %s' % temp_script_file)
1905 1917
1906 def _GetControlUsbChargingCommand(self): 1918 def _GetControlUsbChargingCommand(self):
1907 if self._control_usb_charging_command['cached']: 1919 if self._control_usb_charging_command['cached']:
1908 return self._control_usb_charging_command['command'] 1920 return self._control_usb_charging_command['command']
1909 self._control_usb_charging_command['cached'] = True 1921 self._control_usb_charging_command['cached'] = True
1910 for command in CONTROL_USB_CHARGING_COMMANDS: 1922 for command in CONTROL_USB_CHARGING_COMMANDS:
1911 # Assert command is valid. 1923 # Assert command is valid.
1912 assert 'disable_command' in command 1924 assert 'disable_command' in command
1913 assert 'enable_command' in command 1925 assert 'enable_command' in command
1914 assert 'witness_file' in command 1926 assert 'witness_file' in command
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1963 """ 1975 """
1964 def __init__(self, output): 1976 def __init__(self, output):
1965 self._output = output 1977 self._output = output
1966 1978
1967 def write(self, data): 1979 def write(self, data):
1968 data = data.replace('\r\r\n', '\n') 1980 data = data.replace('\r\r\n', '\n')
1969 self._output.write(data) 1981 self._output.write(data)
1970 1982
1971 def flush(self): 1983 def flush(self):
1972 self._output.flush() 1984 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