From 26bfc438d4182279bdd2e08856bf0f664387cd5b Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sat, 24 Sep 2011 11:27:55 -0400 Subject: [PATCH] Portable command expansion. --- envoy/core.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/envoy/core.py b/envoy/core.py index af315ba..f328059 100644 --- a/envoy/core.py +++ b/envoy/core.py @@ -74,12 +74,8 @@ class Response(object): else: return '' - -def run(command, data=None, timeout=None): - """Executes a given commmand and returns Response. - - Blocks until process is complete, or timeout is reached. - """ +def prep_args(command): + """Parses command strings and returns a Popen-ready list.""" # Prepare arguments. if isinstance(command, basestring): @@ -95,14 +91,24 @@ def run(command, data=None, timeout=None): break command = map(shlex.split, command) - + + return command + + +def run(command, data=None, timeout=None): + """Executes a given commmand and returns Response. + + Blocks until process is complete, or timeout is reached. + """ + + command = prep_args(command) + history = [] for c in command: if len(history): # due to broken pipe problems pass only first 10MB data = history[-1].std_out[0:10*1024] - cmd = Command(c) out, err = cmd.run(data, timeout) @@ -113,7 +119,7 @@ def run(command, data=None, timeout=None): r.std_out = out r.std_err = err r.status_code = cmd.returncode - + history.append(r)