'''shellcmd - simple invocation of shell commands from Python'''
def call(cmd, *args, **kwds):
if args or kwds:
cmd = cmd.format(*args, **kwds)
return subprocess.call(cmd, shell=True)
def check_call(cmd, *args, **kwds):
if args or kwds:
cmd = cmd.format(*args, **kwds)
return subprocess.check_call(cmd, shell=True)
def check_output(cmd, *args, **kwds):
if args or kwds:
cmd = cmd.format(*args, **kwds)
return subprocess.check_output(cmd, shell=True)
Diff to Previous Revision
--- revision 1 2011-10-04 23:50:17
+++ revision 2 2011-10-21 05:52:48
@@ -1,20 +1,16 @@
-"""subshell - simple non-persistent subshell for command execution"""
+'''shellcmd - simple invocation of shell commands from Python'''
-import os
-import subprocess
+def call(cmd, *args, **kwds):
+ if args or kwds:
+ cmd = cmd.format(*args, **kwds)
+ return subprocess.call(cmd, shell=True)
-class SubShell(object):
- # Slight misnomer since it isn't persistent, but close enough...
+def check_call(cmd, *args, **kwds):
+ if args or kwds:
+ cmd = cmd.format(*args, **kwds)
+ return subprocess.check_call(cmd, shell=True)
- def __init__(self, env=None):
- if env is None:
- env = os.environ.copy()
- self.env = env
-
- def capture(self, cmd):
- """Captures stdout for shell command"""
- return subprocess.check_output(cmd, shell=True, env=self.env)
-
- def run(self, cmd):
- """Result is True if return code was 0, False otherwise"""
- return not subprocess.call(cmd, shell=True, env=self.env)
+def check_output(cmd, *args, **kwds):
+ if args or kwds:
+ cmd = cmd.format(*args, **kwds)
+ return subprocess.check_output(cmd, shell=True)