summaryrefslogtreecommitdiff
path: root/obalie/utils.py
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2010-04-20 23:02:42 -0400
committerMike Crute <mcrute@gmail.com>2010-04-20 23:02:42 -0400
commit5156d1d7635806a237bdf9857702068290fc6340 (patch)
tree0861c901c7d1e8b5f2003582f0460f0b2a713e9c /obalie/utils.py
downloadobalie-5156d1d7635806a237bdf9857702068290fc6340.tar.bz2
obalie-5156d1d7635806a237bdf9857702068290fc6340.tar.xz
obalie-5156d1d7635806a237bdf9857702068290fc6340.zip
First pass at the basic client
Diffstat (limited to 'obalie/utils.py')
-rw-r--r--obalie/utils.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/obalie/utils.py b/obalie/utils.py
new file mode 100644
index 0000000..dcf476a
--- /dev/null
+++ b/obalie/utils.py
@@ -0,0 +1,32 @@
1# vim: set filencoding=utf8
2"""
3Miscellaneous Utility Commands
4
5@author: Mike Crute (mcrute@ag.com)
6@organization: SoftGroup Interactive, Inc.
7@date: April 20, 2010
8"""
9
10
11import shlex
12from subprocess import Popen, PIPE
13from obalie.exceptions import ExecutableError
14
15
16def run_command(command, raw_output=False):
17 """
18 Run a command string returning the output. Passing raw_output
19 will cause the function to return the raw stdout; otherwise
20 lines will be split.
21 """
22 cmd = shlex.split(command.encode('ascii'))
23 proc = Popen(cmd, close_fds=False, stdout=PIPE, stderr=PIPE)
24 stdout, stderr = proc.communicate()
25
26 if proc.returncode != 0:
27 raise ExecutableError(proc.returncode, command)
28
29 if raw_output:
30 return stdout
31 else:
32 return stdout.splitlines(True)