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

Unified Diff: build/android/pylib/device/device_utils.py

Issue 885443002: Roll Chrome into Mojo. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebase to ToT mojo Created 5 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
« no previous file with comments | « build/android/pylib/constants.py ('k') | build/android/pylib/device/device_utils_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/device/device_utils.py
diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py
index a4ddef1328057f6376175ae4f448e8eb314420c3..fab3c5d399b2fbe7f5c9094e8b18ac110e6ac72f 100644
--- a/build/android/pylib/device/device_utils.py
+++ b/build/android/pylib/device/device_utils.py
@@ -91,6 +91,13 @@ def _GetTimeStamp():
return time.strftime('%Y%m%dT%H%M%S', time.localtime())
+def _JoinLines(lines):
+ # makes sure that the last line is also terminated, and is more memory
+ # efficient than first appending an end-line to each line and then joining
+ # all of them together.
+ return ''.join(s for line in lines for s in (line, '\n'))
+
+
class DeviceUtils(object):
_VALID_SHELL_VARIABLE = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$')
@@ -883,7 +890,8 @@ class DeviceUtils(object):
self.adb.Pull(device_path, host_path)
@decorators.WithTimeoutAndRetriesFromInstance()
- def ReadFile(self, device_path, as_root=False, timeout=None, retries=None):
+ def ReadFile(self, device_path, as_root=False,
+ timeout=None, retries=None):
"""Reads the contents of a file from the device.
Args:
@@ -895,22 +903,17 @@ class DeviceUtils(object):
retries: number of retries
Returns:
- The contents of the file at |device_path| as a list of lines.
+ The contents of |device_path| as a string. Contents are intepreted using
+ universal newlines, so the caller will see them encoded as '\n'. Also,
+ all lines will be terminated.
Raises:
- CommandFailedError if the file can't be read.
+ AdbCommandFailedError if the file can't be read.
CommandTimeoutError on timeout.
DeviceUnreachableError on missing device.
"""
- # TODO(jbudorick) Evaluate whether we want to return a list of lines after
- # the implementation switch, and if file not found should raise exception.
- if as_root:
- if not self.old_interface.CanAccessProtectedFileContents():
- raise device_errors.CommandFailedError(
- 'Cannot read from %s with root privileges.' % device_path)
- return self.old_interface.GetProtectedFileContents(device_path)
- else:
- return self.old_interface.GetFileContents(device_path)
+ return _JoinLines(self.RunShellCommand(
+ ['cat', device_path], as_root=as_root, check_return=True))
@decorators.WithTimeoutAndRetriesFromInstance()
def WriteFile(self, device_path, contents, as_root=False, force_push=False,
« no previous file with comments | « build/android/pylib/constants.py ('k') | build/android/pylib/device/device_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698