summaryrefslogtreecommitdiffstats
path: root/ipapython
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2009-11-30 15:28:09 -0500
committerRob Crittenden <rcritten@redhat.com>2009-11-30 15:28:41 -0500
commit7c2c2d6130648fb6dd7c0e52d802cc6eff39ef95 (patch)
treedd7e58b79a237757406bca959c2fff733ad09798 /ipapython
parent29aa8fb05dbebe96ba44a4f6547cb7580562ef48 (diff)
downloadfreeipa-7c2c2d6130648fb6dd7c0e52d802cc6eff39ef95.tar.gz
freeipa-7c2c2d6130648fb6dd7c0e52d802cc6eff39ef95.tar.xz
freeipa-7c2c2d6130648fb6dd7c0e52d802cc6eff39ef95.zip
Add option to have ipautil.run() not raise an exception
There are times where a caller will want to determine the course of action based on the returncode instead of relying on it != 0. This also lets the caller get the contents of stdout and stderr.
Diffstat (limited to 'ipapython')
-rw-r--r--ipapython/ipautil.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
index 10668793..1399c708 100644
--- a/ipapython/ipautil.py
+++ b/ipapython/ipautil.py
@@ -89,7 +89,7 @@ def write_tmp_file(txt):
return fd
-def run(args, stdin=None):
+def run(args, stdin=None, raiseonerr=True):
if stdin:
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
stdout,stderr = p.communicate(stdin)
@@ -101,10 +101,10 @@ def run(args, stdin=None):
logging.info('stdout=%s' % stdout)
logging.info('stderr=%s' % stderr)
- if p.returncode != 0:
+ if p.returncode != 0 and raiseonerr:
raise CalledProcessError(p.returncode, ' '.join(args))
- return (stdout, stderr)
+ return (stdout, stderr, p.returncode)
def file_exists(filename):
try: