summaryrefslogtreecommitdiffstats
path: root/ipalib/plugable.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-12-21 17:12:00 -0700
committerJason Gerard DeRose <jderose@redhat.com>2008-12-21 17:12:00 -0700
commit4390523b7f854cefcb91843e1df3ca7575d43fea (patch)
tree6f3fddfa3b78dc425683cab1afe28b33ca6f0175 /ipalib/plugable.py
parentb71d1e6b6f7d2ab31f26c21e4246056a808766c0 (diff)
downloadfreeipa-4390523b7f854cefcb91843e1df3ca7575d43fea.tar.gz
freeipa-4390523b7f854cefcb91843e1df3ca7575d43fea.tar.xz
freeipa-4390523b7f854cefcb91843e1df3ca7575d43fea.zip
Improved Plugin.call() method and added its unit test
Diffstat (limited to 'ipalib/plugable.py')
-rw-r--r--ipalib/plugable.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index e6b5c1ac8..f3b35d30b 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -367,15 +367,22 @@ class Plugin(ReadOnly):
assert not hasattr(self, name)
setattr(self, name, getattr(api, name))
- def call(self, *args):
+ def call(self, executable, *args):
"""
- Call an external command via ``subprocess.call``.
+ Call ``executable`` with ``args`` using subprocess.call().
- Returns the exit status of the call.
+ If the call exits with a non-zero exit status,
+ `ipalib.errors.SubprocessError` is raised, from which you can retrieve
+ the exit code by checking the SubprocessError.returncode attribute.
+
+ This method does *not* return what ``executable`` sent to stdout... for
+ that, use `Plugin.callread()`.
"""
- if hasattr(self, 'log'):
- self.log.debug('Calling %r', args)
- return subprocess.call(args)
+ argv = (executable,) + args
+ self.debug('Calling %r', argv)
+ returncode = subprocess.call(argv)
+ if returncode != 0:
+ raise errors.SubprocessError(returncode, argv)
def __repr__(self):
"""