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

Unified Diff: tools/skpbench/_adb.py

Issue 2481413003: skpbench: simplify adb and reduce number of invocations (Closed)
Patch Set: skpbench: simplify adb and reduce number of invocations Created 4 years, 1 month 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 | « no previous file | tools/skpbench/_adb_path.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/skpbench/_adb.py
diff --git a/tools/skpbench/_adb.py b/tools/skpbench/_adb.py
index 402e132a2b9fd7afff02099a081347e1ea491975..75c0173034a0d4d5d5eb0f605f0dc8407b753646 100644
--- a/tools/skpbench/_adb.py
+++ b/tools/skpbench/_adb.py
@@ -3,40 +3,50 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+from __future__ import print_function
import re
import subprocess
import sys
class Adb:
- def __init__(self, device_serial=None):
+ def __init__(self, device_serial=None, echofile=None):
self.__invocation = ['adb']
if device_serial:
self.__invocation.extend(['-s', device_serial])
+ self.__echofile = echofile
+ self.__is_root = None
def shell(self, cmd):
+ if self.__echofile:
+ self.__echo_cmd(cmd)
subprocess.call(self.__invocation + ['shell', cmd], stdout=sys.stderr)
def check(self, cmd):
+ if self.__echofile:
+ self.__echo_cmd(cmd)
result = subprocess.check_output(self.__invocation + ['shell', cmd])
- return result.rstrip()
-
- def check_lines(self, cmd):
- result = self.check(cmd)
- return re.split('[\r\n]+', result)
-
- def get_device_model(self):
- result = self.check('getprop | grep ro.product.model')
- result = re.match(r'\[ro.product.model\]:\s*\[(.*)\]', result)
- return result.group(1) if result else 'unknown_product'
+ if self.__echofile:
+ print(result, file=self.__echofile)
+ return result
+
+ def root(self):
+ if not self.is_root():
+ subprocess.call(self.__invocation + ['root'], stdout=sys.stderr)
+ self.__is_root = None
+ return self.is_root()
def is_root(self):
- return self.check('whoami') == 'root'
-
- def attempt_root(self):
- if self.is_root():
- return True
- subprocess.call(self.__invocation + ['root'], stdout=sys.stderr)
- return self.is_root()
+ if self.__is_root is None:
+ self.__is_root = ('root' == self.check('whoami').strip())
+ return self.__is_root
def remount(self):
subprocess.call(self.__invocation + ['remount'], stdout=sys.stderr)
+
+ def __echo_cmd(self, cmd):
+ escaped = [re.sub(r'([^a-zA-Z0-9])', r'\\\1', x)
+ for x in cmd.strip().splitlines()]
+ subprocess.call(self.__invocation + \
+ ['shell', 'echo', '$(whoami)@$(getprop ro.serialno)$',
+ " '\n>' ".join(escaped)],
+ stdout=self.__echofile)
« no previous file with comments | « no previous file | tools/skpbench/_adb_path.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698