diff options
author | Martin Gracik <mgracik@redhat.com> | 2009-03-24 11:05:40 +0100 |
---|---|---|
committer | Martin Gracik <mgracik@redhat.com> | 2009-03-24 14:41:55 +0100 |
commit | ac83df7815ff3db042875db51a43c107e982ee70 (patch) | |
tree | a8b67d04cf0b00ea92b6fa1d4c162123dc9fa0e3 /anate/baseutils.py | |
download | anate-ac83df7815ff3db042875db51a43c107e982ee70.tar.gz anate-ac83df7815ff3db042875db51a43c107e982ee70.tar.xz anate-ac83df7815ff3db042875db51a43c107e982ee70.zip |
Diffstat (limited to 'anate/baseutils.py')
-rw-r--r-- | anate/baseutils.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/anate/baseutils.py b/anate/baseutils.py new file mode 100644 index 0000000..f084e64 --- /dev/null +++ b/anate/baseutils.py @@ -0,0 +1,44 @@ +import logging +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger('anate.baseutils') + +import os +import subprocess + + +class Subprocess(object): + def __init__(self, cmd, *args): + self._cmd = [cmd] + self._args = map(str, list(args)) + + self._rc = None + self._stdout = [] + self._stderr = [] + + def run(self): + logger.info('running command %s', self._cmd + self._args) + proc = subprocess.Popen(self._cmd + self._args, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + while True: + (out_str, err_str) = proc.communicate() + if out_str: + self._stdout.append(out_str) + if err_str: + self._stderr.append(err_str) + + if proc.returncode is not None: + self._rc = proc.returncode + break + + @property + def rc(self): + return self._rc + + @property + def stdout(self): + return self._stdout + + @property + def stderr(self): + return self._stderr |