gdbrunner: expose adb.split_lines, use it.
Change-Id: I895aacaababf87c1e82ff5604c028cc475207304
This commit is contained in:
@@ -51,7 +51,7 @@ def get_devices(adb_path='adb'):
|
|||||||
with open(os.devnull, 'wb') as devnull:
|
with open(os.devnull, 'wb') as devnull:
|
||||||
subprocess.check_call([adb_path, 'start-server'], stdout=devnull,
|
subprocess.check_call([adb_path, 'start-server'], stdout=devnull,
|
||||||
stderr=devnull)
|
stderr=devnull)
|
||||||
out = _split_lines(subprocess.check_output([adb_path, 'devices']))
|
out = split_lines(subprocess.check_output([adb_path, 'devices']))
|
||||||
|
|
||||||
# The first line of `adb devices` just says "List of attached devices", so
|
# The first line of `adb devices` just says "List of attached devices", so
|
||||||
# skip that.
|
# skip that.
|
||||||
@@ -213,7 +213,7 @@ def _subprocess_Popen(*args, **kwargs):
|
|||||||
return subprocess.Popen(*_get_subprocess_args(args), **kwargs)
|
return subprocess.Popen(*_get_subprocess_args(args), **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def _split_lines(s):
|
def split_lines(s):
|
||||||
"""Splits lines in a way that works even on Windows and old devices.
|
"""Splits lines in a way that works even on Windows and old devices.
|
||||||
|
|
||||||
Windows will see \r\n instead of \n, old devices do the same, old devices
|
Windows will see \r\n instead of \n, old devices do the same, old devices
|
||||||
@@ -271,7 +271,7 @@ class AndroidDevice(object):
|
|||||||
def features(self):
|
def features(self):
|
||||||
if self._features is None:
|
if self._features is None:
|
||||||
try:
|
try:
|
||||||
self._features = _split_lines(self._simple_call(['features']))
|
self._features = split_lines(self._simple_call(['features']))
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
self._features = []
|
self._features = []
|
||||||
return self._features
|
return self._features
|
||||||
@@ -475,7 +475,7 @@ class AndroidDevice(object):
|
|||||||
def get_props(self):
|
def get_props(self):
|
||||||
result = {}
|
result = {}
|
||||||
output, _ = self.shell(['getprop'])
|
output, _ = self.shell(['getprop'])
|
||||||
output = _split_lines(output)
|
output = split_lines(output)
|
||||||
pattern = re.compile(r'^\[([^]]+)\]: \[(.*)\]')
|
pattern = re.compile(r'^\[([^]]+)\]: \[(.*)\]')
|
||||||
for line in output:
|
for line in output:
|
||||||
match = pattern.match(line)
|
match = pattern.match(line)
|
||||||
@@ -489,7 +489,7 @@ class AndroidDevice(object):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def get_prop(self, prop_name):
|
def get_prop(self, prop_name):
|
||||||
output = _split_lines(self.shell(['getprop', prop_name])[0])
|
output = split_lines(self.shell(['getprop', prop_name])[0])
|
||||||
if len(output) != 1:
|
if len(output) != 1:
|
||||||
raise RuntimeError('Too many lines in getprop output:\n' +
|
raise RuntimeError('Too many lines in getprop output:\n' +
|
||||||
'\n'.join(output))
|
'\n'.join(output))
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ def get_processes(device):
|
|||||||
output, _ = device.shell([ps_script])
|
output, _ = device.shell([ps_script])
|
||||||
|
|
||||||
processes = dict()
|
processes = dict()
|
||||||
output = output.replace("\r", "").splitlines()
|
output = adb.split_lines(output.replace("\r", ""))
|
||||||
columns = output.pop(0).split()
|
columns = output.pop(0).split()
|
||||||
try:
|
try:
|
||||||
pid_column = columns.index("PID")
|
pid_column = columns.index("PID")
|
||||||
|
|||||||
Reference in New Issue
Block a user