Skip to content
This repository has been archived by the owner on Apr 24, 2018. It is now read-only.

Commit

Permalink
Portable command expansion.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Reitz committed Sep 24, 2011
1 parent 52219d7 commit 26bfc43
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions envoy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,8 @@ def __repr__(self):
else:
return '<Response>'


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):
Expand All @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit 26bfc43

Please sign in to comment.