Index: build/android/pylib/device/adb_wrapper.py |
diff --git a/build/android/pylib/device/adb_wrapper.py b/build/android/pylib/device/adb_wrapper.py |
index 4981f28df033f82966c76ea6ceb8679bcb05430b..e73d66c9a7c8efe0dbe0c445e7cf61b893ae1591 100644 |
--- a/build/android/pylib/device/adb_wrapper.py |
+++ b/build/android/pylib/device/adb_wrapper.py |
@@ -8,6 +8,7 @@ This is a thin wrapper around the adb interface. Any additional complexity |
should be delegated to a higher level (ex. DeviceUtils). |
""" |
+import collections |
import errno |
import logging |
import os |
@@ -36,6 +37,10 @@ def _VerifyLocalFileExists(path): |
raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), path) |
+DeviceStat = collections.namedtuple('DeviceStat', |
+ ['st_mode', 'st_size', 'st_time']) |
+ |
+ |
class AdbWrapper(object): |
"""A wrapper around a local Android Debug Bridge executable.""" |
@@ -200,6 +205,38 @@ class AdbWrapper(object): |
args, output, status, self._device_serial) |
return output |
+ def Ls(self, path, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): |
+ """List the contents of a directory on the device. |
+ |
+ Args: |
+ path: Path on the device filesystem. |
+ timeout: (optional) Timeout per try in seconds. |
+ retries: (optional) Number of retries to attempt. |
+ |
+ Returns: |
+ A list of pairs (filename, stat) for each file found in the directory, |
+ where the stat object has the properties: st_mode, st_size, and st_time. |
+ |
+ Raises: |
+ AdbCommandFailedError if |path| does not specify a valid and accessible |
+ directory in the device. |
+ """ |
+ def ParseLine(line): |
+ cols = line.split(None, 3) |
+ filename = cols.pop() |
+ stat = DeviceStat(*[int(num, base=16) for num in cols]) |
+ return (filename, stat) |
+ |
+ cmd = ['ls', path] |
+ lines = self._RunDeviceAdbCmd( |
+ cmd, timeout=timeout, retries=retries).splitlines() |
+ if lines: |
+ return [ParseLine(line) for line in lines] |
+ else: |
+ raise device_errors.AdbCommandFailedError( |
+ cmd, 'path does not specify an accessible directory in the device', |
+ device_serial=self._device_serial) |
+ |
def Logcat(self, filter_spec=None, timeout=_DEFAULT_TIMEOUT, |
retries=_DEFAULT_RETRIES): |
"""Get the logcat output. |