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

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

Issue 371813005: [Android] Switch to DeviceUtils versions of Ls, SetJavaAsserts, GetProp, and SetProp. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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
« no previous file with comments | « build/android/enable_asserts.py ('k') | build/android/pylib/content_settings.py » ('j') | 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 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 """Lists files in all subdirectories of |path|. 1223 """Lists files in all subdirectories of |path|.
1224 1224
1225 Args: 1225 Args:
1226 path: The path to list. 1226 path: The path to list.
1227 1227
1228 Returns: 1228 Returns:
1229 A dict of {"name": (size, lastmod), ...}. 1229 A dict of {"name": (size, lastmod), ...}.
1230 """ 1230 """
1231 # Example output: 1231 # Example output:
1232 # /foo/bar: 1232 # /foo/bar:
1233 # -rw-r----- 1 user group 102 2011-05-12 12:29:54.131623387 +0100 baz.txt 1233 # -rw-r----- user group 102 2011-05-12 12:29:54.131623387 +0100 baz.txt
1234 re_file = re.compile('^-(?P<perms>[^\s]+)\s+' 1234 re_file = re.compile('^-(?P<perms>[^\s]+)\s+'
1235 '(?P<user>[^\s]+)\s+' 1235 '(?P<user>[^\s]+)\s+'
1236 '(?P<group>[^\s]+)\s+' 1236 '(?P<group>[^\s]+)\s+'
1237 '(?P<size>[^\s]+)\s+' 1237 '(?P<size>[^\s]+)\s+'
1238 '(?P<date>[^\s]+)\s+' 1238 '(?P<date>[^\s]+)\s+'
1239 '(?P<time>[^\s]+)\s+' 1239 '(?P<time>[^\s]+)\s+'
1240 '(?P<filename>[^\s]+)$') 1240 '(?P<filename>[^\s]+)$')
1241 return _GetFilesFromRecursiveLsOutput( 1241 return _GetFilesFromRecursiveLsOutput(
1242 path, self.RunShellCommand('ls -lR %s' % path), re_file, 1242 path, self.RunShellCommand('ls -lR %s' % path), re_file,
1243 self.GetUtcOffset()) 1243 self.GetUtcOffset())
1244 1244
1245 def GetUtcOffset(self): 1245 def GetUtcOffset(self):
1246 if not self._device_utc_offset: 1246 if not self._device_utc_offset:
1247 self._device_utc_offset = self.RunShellCommand('date +%z')[0] 1247 self._device_utc_offset = self.RunShellCommand('date +%z')[0]
1248 return self._device_utc_offset 1248 return self._device_utc_offset
1249 1249
1250 def SetJavaAssertsEnabled(self, enable): 1250 def SetJavaAssertsEnabled(self, enable):
1251 """Sets or removes the device java assertions property. 1251 """Sets or removes the device java assertions property.
1252 1252
1253 Args: 1253 Args:
1254 enable: If True the property will be set. 1254 enable: If True the property will be set.
1255 1255
1256 Returns: 1256 Returns:
1257 True if the file was modified (reboot is required for it to take effect). 1257 True if the file was modified (reboot is required for it to take effect).
1258 """ 1258 """
1259 # First ensure the desired property is persisted. 1259 # First ensure the desired property is persisted.
1260 temp_props_file = tempfile.NamedTemporaryFile() 1260 temp_props_file = tempfile.NamedTemporaryFile()
1261 properties = '' 1261 properties = ''
1262 if self._adb.Pull(LOCAL_PROPERTIES_PATH, temp_props_file.name): 1262 if self._adb.Pull(LOCAL_PROPERTIES_PATH, temp_props_file.name):
1263 properties = file(temp_props_file.name).read() 1263 with open(temp_props_file.name) as f:
1264 properties = f.read()
1264 re_search = re.compile(r'^\s*' + re.escape(JAVA_ASSERT_PROPERTY) + 1265 re_search = re.compile(r'^\s*' + re.escape(JAVA_ASSERT_PROPERTY) +
1265 r'\s*=\s*all\s*$', re.MULTILINE) 1266 r'\s*=\s*all\s*$', re.MULTILINE)
1266 if enable != bool(re.search(re_search, properties)): 1267 if enable != bool(re.search(re_search, properties)):
1267 re_replace = re.compile(r'^\s*' + re.escape(JAVA_ASSERT_PROPERTY) + 1268 re_replace = re.compile(r'^\s*' + re.escape(JAVA_ASSERT_PROPERTY) +
1268 r'\s*=\s*\w+\s*$', re.MULTILINE) 1269 r'\s*=\s*\w+\s*$', re.MULTILINE)
1269 properties = re.sub(re_replace, '', properties) 1270 properties = re.sub(re_replace, '', properties)
1270 if enable: 1271 if enable:
1271 properties += '\n%s=all\n' % JAVA_ASSERT_PROPERTY 1272 properties += '\n%s=all\n' % JAVA_ASSERT_PROPERTY
1272 1273
1273 file(temp_props_file.name, 'w').write(properties) 1274 file(temp_props_file.name, 'w').write(properties)
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
1968 """ 1969 """
1969 def __init__(self, output): 1970 def __init__(self, output):
1970 self._output = output 1971 self._output = output
1971 1972
1972 def write(self, data): 1973 def write(self, data):
1973 data = data.replace('\r\r\n', '\n') 1974 data = data.replace('\r\r\n', '\n')
1974 self._output.write(data) 1975 self._output.write(data)
1975 1976
1976 def flush(self): 1977 def flush(self):
1977 self._output.flush() 1978 self._output.flush()
OLDNEW
« no previous file with comments | « build/android/enable_asserts.py ('k') | build/android/pylib/content_settings.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698