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

Unified Diff: tools/memory_inspector/memory_inspector/backends/adb_client.py

Issue 934603002: [memory-inspector] Replace getprop line splitting with a regex (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Increment version number Created 5 years, 10 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 | « tools/memory_inspector/chrome_app/template/manifest.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/memory_inspector/memory_inspector/backends/adb_client.py
diff --git a/tools/memory_inspector/memory_inspector/backends/adb_client.py b/tools/memory_inspector/memory_inspector/backends/adb_client.py
index 3f8610597e8ddca8e97f00a74cc74d29edd736d4..076853ecac8468d65c5304d95a0944e916755f99 100644
--- a/tools/memory_inspector/memory_inspector/backends/adb_client.py
+++ b/tools/memory_inspector/memory_inspector/backends/adb_client.py
@@ -13,6 +13,7 @@ requiring only that an adb daemon (adb start-server) is running on the host.
import logging
import os
import pipes
+import re
import socket
import stat
import struct
@@ -22,6 +23,15 @@ ADB_PORT = 5037
TIMEOUT = 5
ADB_NOT_RUNNING_MESSAGE = 'ADB daemon not running. Run \'adb start-server\'.'
+"""Regular expression for matching the output of the 'getprop' Android command.
+Sample input:
+
+ [prop1]: [simple value]
+ [prop2]: [multiline
+ value]
+"""
+GETPROP_RE = re.compile(r'^\[([^\]]*)\]: \[(.*?)\]$', re.MULTILINE | re.DOTALL)
+
class ADBClientError(Exception):
"""ADB errors."""
@@ -119,10 +129,8 @@ class ADBDevice(object):
def __init__(self, serial):
assert isinstance(serial, str), type(serial)
self.serial = serial
- self._cached_props = {}
all_props = self.Shell(['getprop'])
- for name, value in (line.split(': ') for line in all_props.splitlines()):
- self._cached_props[name.strip('[]')] = value.strip('[]')
+ self._cached_props = dict(re.findall(GETPROP_RE, all_props))
def GetProp(self, name, cached=False):
if cached and name in self._cached_props:
« no previous file with comments | « tools/memory_inspector/chrome_app/template/manifest.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698