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

Unified Diff: chromite/lib/cros_build_lib.py

Issue 3323019: Add shell parameter to allow running commands directly. (Closed) Base URL: http://git.chromium.org/git/crosutils.git
Patch Set: Address review comments. Created 10 years, 3 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromite/lib/cros_build_lib.py
diff --git a/chromite/lib/cros_build_lib.py b/chromite/lib/cros_build_lib.py
index a0cd73c6edaac26c2324c7af158a5c00d7bf762d..86a70e49563edf5f9a246b38591aaeb21eb3cd3f 100644
--- a/chromite/lib/cros_build_lib.py
+++ b/chromite/lib/cros_build_lib.py
@@ -11,12 +11,11 @@ _STDOUT_IS_TTY = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None,
exit_code=False, redirect_stdout=False, redirect_stderr=False,
- cwd=None, input=None, enter_chroot=False):
- """Runs a shell command.
+ cwd=None, input=None, enter_chroot=False, shell=False):
+ """Runs a command.
Keyword arguments:
- cmd - cmd to run. Should be input to subprocess.POpen. If a string,
- converted to an array using split().
+ cmd - cmd to run. Should be input to subprocess.Popen.
print_cmd -- prints the command before running it.
error_ok -- does not raise an exception on error.
error_message -- prints out this message when an error occurrs.
@@ -27,6 +26,7 @@ def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None,
input -- input to pipe into this command through stdin.
enter_chroot -- this command should be run from within the chroot. If set,
cwd must point to the scripts directory.
+ shell -- If shell is True, the specified command will be executed through the shell.
sosa 2010/09/09 17:45:21 80 chars :p
Raises:
Exception: Raises generic exception on error with optional error_message.
"""
@@ -40,21 +40,27 @@ def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None,
if redirect_stdout: stdout = subprocess.PIPE
if redirect_stderr: stderr = subprocess.PIPE
if input: stdin = subprocess.PIPE
- if enter_chroot: cmd = ['./enter_chroot.sh', '--'] + cmd
+ if isinstance(cmd, basestring):
+ if enter_chroot: cmd = './enter_chroot.sh -- ' + cmd
+ cmd_str = cmd
+ else:
+ if enter_chroot: cmd = ['./enter_chroot.sh', '--'] + cmd
+ cmd_str = ' '.join(cmd)
# Print out the command before running.
if print_cmd:
- Info('RunCommand: %s' % ' '.join(cmd))
+ Info('RunCommand: %s' % cmd_str)
try:
proc = subprocess.Popen(cmd, cwd=cwd, stdin=stdin,
- stdout=stdout, stderr=stderr)
+ stdout=stdout, stderr=stderr,
+ shell=shell)
(output, error) = proc.communicate(input)
if exit_code:
return proc.returncode
if not error_ok and proc.returncode:
- raise Exception('Command "%s" failed.\n' % (' '.join(cmd)) +
+ raise Exception('Command "%s" failed.\n' % cmd_str +
(error_message or error or output or ''))
except Exception,e:
if not error_ok:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698