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

Unified Diff: build/android/pylib/android_commands.py

Issue 132463007: Enable presubmit pylint in build/android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: build/android/pylib/android_commands.py
diff --git a/build/android/pylib/android_commands.py b/build/android/pylib/android_commands.py
index d4e17fa2640972dbc5ef10fabce5cad1799749d8..f35480fda5200b58d04ec0785346544a73624318 100644
--- a/build/android/pylib/android_commands.py
+++ b/build/android/pylib/android_commands.py
@@ -27,7 +27,7 @@ import system_properties
try:
from pylib import pexpect
-except:
+except ImportError:
pexpect = None
sys.path.append(os.path.join(
@@ -350,7 +350,7 @@ class AndroidCommands(object):
logging.warning('Restarting and retrying after timeout: %s', e)
retries -= 1
self.RestartShell()
- raise last_err # Only reached after max retries, re-raise the last error.
+ raise last_err # Only reached after max retries, re-raise the last error.
def RestartShell(self):
"""Restarts the shell on the device. Does not block for it to return."""
@@ -489,7 +489,7 @@ class AndroidCommands(object):
if not adb_pids:
raise errors.MsgException('Unable to obtain adbd pid')
try:
- self.KillAll('adbd', signal=signal.SIGTERM, with_su=True)
+ self.KillAll('adbd', signum=signal.SIGTERM, with_su=True)
logging.info('Waiting for device to settle...')
self._adb.SendCommand('wait-for-device')
new_adb_pids = self.ExtractPid('adbd')
@@ -508,7 +508,8 @@ class AndroidCommands(object):
if ret != 0:
raise errors.MsgException('StartAdbServer: %d' % ret)
- def KillAdbServer(self):
+ @staticmethod
+ def KillAdbServer():
"""Kill adb server."""
adb_cmd = [constants.GetAdbPath(), 'kill-server']
ret = cmd_helper.RunCmd(adb_cmd)
@@ -638,7 +639,8 @@ class AndroidCommands(object):
"""
self._CheckCommandIsValid(command)
self._LogShell(command)
- if "'" in command: logging.warning(command + " contains ' quotes")
+ if "'" in command:
+ logging.warning(command + " contains ' quotes")
result = self._adb.SendShellCommand(
"'%s'" % command, timeout_time).splitlines()
if ['error: device not found'] == result:
@@ -666,12 +668,12 @@ class AndroidCommands(object):
lines = lines[:-1] + [last_line[:status_pos]]
return (status, lines)
- def KillAll(self, process, signal=9, with_su=False):
+ def KillAll(self, process, signum=9, with_su=False):
"""Android version of killall, connected via adb.
Args:
process: name of the process to kill off.
- signal: signal to use, 9 (SIGKILL) by default.
+ signum: signal to use, 9 (SIGKILL) by default.
with_su: wether or not to use su to kill the processes.
Returns:
@@ -679,7 +681,7 @@ class AndroidCommands(object):
"""
pids = self.ExtractPid(process)
if pids:
- cmd = 'kill -%d %s' % (signal, ' '.join(pids))
+ cmd = 'kill -%d %s' % (signum, ' '.join(pids))
if with_su:
self.RunShellCommandWithSU(cmd)
else:
@@ -711,7 +713,8 @@ class AndroidCommands(object):
return 0
return processes_killed
- def _GetActivityCommand(self, package, activity, wait_for_completion, action,
+ @staticmethod
+ def _GetActivityCommand(package, activity, wait_for_completion, action,
category, data, extras, trace_file_name, force_stop,
flags):
"""Creates command to start |package|'s activity on the device.
@@ -1070,7 +1073,7 @@ class AndroidCommands(object):
r = self.RunShellCommandWithSU('cat /dev/null')
return r == [] or r[0].strip() == ''
- def GetProtectedFileContents(self, filename, log_result=False):
+ def GetProtectedFileContents(self, filename):
"""Gets contents from the protected file specified by |filename|.
This is less efficient than GetFileContents, but will work for protected
@@ -1318,7 +1321,8 @@ class AndroidCommands(object):
# Note this will block for upto the timeout _per log line_, so we need
# to calculate the overall timeout remaining since t0.
time_remaining = t0 + timeout - time.time()
- if time_remaining < 0: raise pexpect.TIMEOUT(self._logcat)
+ if time_remaining < 0:
+ raise pexpect.TIMEOUT(self._logcat)
self._logcat.expect(PEXPECT_LINE_RE, timeout=time_remaining)
line = self._logcat.match.group(1)
if error_re:
@@ -1347,7 +1351,7 @@ class AndroidCommands(object):
timeout=self._logcat.timeout,
logfile=self._logcat.logfile)
- def StartRecordingLogcat(self, clear=True, filters=['*:v']):
+ def StartRecordingLogcat(self, clear=True, filters=None):
"""Starts recording logcat output to eventually be saved as a string.
This call should come before some series of tests are run, with either
@@ -1357,6 +1361,8 @@ class AndroidCommands(object):
clear: True if existing log output should be cleared.
filters: A list of logcat filters to be used.
"""
+ if not filters:
+ filters = ['*:v']
if clear:
self._adb.SendCommand('logcat -c')
logcat_command = 'adb %s logcat -v threadtime %s' % (self._adb._target_arg,
@@ -1401,7 +1407,8 @@ class AndroidCommands(object):
self._logcat_tmpoutfile = None
return output
- def SearchLogcatRecord(self, record, message, thread_id=None, proc_id=None,
+ @staticmethod
+ def SearchLogcatRecord(record, message, thread_id=None, proc_id=None,
log_level=None, component=None):
"""Searches the specified logcat output and returns results.
@@ -1517,8 +1524,7 @@ class AndroidCommands(object):
usage_dict = collections.defaultdict(int)
smaps = collections.defaultdict(dict)
current_smap = ''
- for line in self.GetProtectedFileContents('/proc/%s/smaps' % pid,
- log_result=False):
+ for line in self.GetProtectedFileContents('/proc/%s/smaps' % pid):
items = line.split()
# See man 5 proc for more details. The format is:
# address perms offset dev inode pathname
@@ -1538,8 +1544,7 @@ class AndroidCommands(object):
# Presumably the process died between ps and calling this method.
logging.warning('Could not find memory usage for pid ' + str(pid))
- for line in self.GetProtectedFileContents('/d/nvmap/generic-0/clients',
- log_result=False):
+ for line in self.GetProtectedFileContents('/d/nvmap/generic-0/clients'):
match = re.match(NVIDIA_MEMORY_INFO_RE, line)
if match and match.group('pid') == pid:
usage_bytes = int(match.group('usage_bytes'))
@@ -1547,8 +1552,7 @@ class AndroidCommands(object):
break
peak_value_kb = 0
- for line in self.GetProtectedFileContents('/proc/%s/status' % pid,
- log_result=False):
+ for line in self.GetProtectedFileContents('/proc/%s/status' % pid):
if not line.startswith('VmHWM:'): # Format: 'VmHWM: +[0-9]+ kB'
continue
peak_value_kb = int(line.split(':')[1].strip().split(' ')[0])

Powered by Google App Engine
This is Rietveld 408576698