summaryrefslogtreecommitdiffstats
path: root/build/android/pylib/cmd_helper.py
diff options
context:
space:
mode:
authorbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-09 09:11:57 +0000
committerbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-09 09:11:57 +0000
commit3f31956ff9df0f78a83f6ac5a1e3e66386622591 (patch)
tree7c4f31eb5b7646cbfb0f481359e71548800090ee /build/android/pylib/cmd_helper.py
parent6f26551ca36d415a50118a6b45c44458c98f5094 (diff)
downloadchromium_src-3f31956ff9df0f78a83f6ac5a1e3e66386622591.zip
chromium_src-3f31956ff9df0f78a83f6ac5a1e3e66386622591.tar.gz
chromium_src-3f31956ff9df0f78a83f6ac5a1e3e66386622591.tar.bz2
[android] Split top-level scripts and libraries from build/android.
- Top-level scripts are kept under build/android. - Utility libraries have been moved to build/android/pylib. - Fixes all imports and headers. This is in preparation for landing the "instrumentation" (java-based) tests, which will reuse several of these components. BUG= TEST=existing android tests Review URL: https://chromiumcodereview.appspot.com/10693110 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145653 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build/android/pylib/cmd_helper.py')
-rwxr-xr-xbuild/android/pylib/cmd_helper.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/build/android/pylib/cmd_helper.py b/build/android/pylib/cmd_helper.py
new file mode 100755
index 0000000..8b50130
--- /dev/null
+++ b/build/android/pylib/cmd_helper.py
@@ -0,0 +1,50 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""A wrapper for subprocess to make calling shell commands easier."""
+
+
+import logging
+import subprocess
+
+
+def RunCmd(args, cwd=None):
+ """Opens a subprocess to execute a program and returns its return value.
+
+ Args:
+ args: A string or a sequence of program arguments. The program to execute is
+ the string or the first item in the args sequence.
+ cwd: If not None, the subprocess's current directory will be changed to
+ |cwd| before it's executed.
+
+ Returns:
+ Return code from the command execution.
+ """
+ logging.info(str(args) + ' ' + (cwd or ''))
+ p = subprocess.Popen(args=args, cwd=cwd)
+ return p.wait()
+
+
+def GetCmdOutput(args, cwd=None, shell=False):
+ """Open a subprocess to execute a program and returns its output.
+
+ Args:
+ args: A string or a sequence of program arguments. The program to execute is
+ the string or the first item in the args sequence.
+ cwd: If not None, the subprocess's current directory will be changed to
+ |cwd| before it's executed.
+ shell: Whether to execute args as a shell command.
+
+ Returns:
+ Captures and returns the command's stdout.
+ Prints the command's stderr to logger (which defaults to stdout).
+ """
+ logging.info(str(args) + ' ' + (cwd or ''))
+ p = subprocess.Popen(args=args, cwd=cwd, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE, shell=shell)
+ stdout, stderr = p.communicate()
+ if stderr:
+ logging.critical(stderr)
+ logging.info(stdout[:4096]) # Truncate output longer than 4k.
+ return stdout