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

Commit

Permalink
Merge pull request #17 from sirpengi/master
Browse files Browse the repository at this point in the history
overriding environment variables
  • Loading branch information
Kenneth Reitz committed Jan 6, 2012
2 parents 1ee6ccd + 4d23067 commit 04e88fe
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions envoy/core.py
Expand Up @@ -27,14 +27,16 @@ def __init__(self, cmd):
self.returncode = None
self.data = None

def run(self, data, timeout):
def run(self, data, timeout, env):
self.data = data
environ = dict(os.environ).update(env or {})

def target():

self.process = subprocess.Popen(self.cmd,
universal_newlines=True,
shell=False,
env=os.environ,
env=environ,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand Down Expand Up @@ -152,7 +154,7 @@ def expand_args(command):
return command


def run(command, data=None, timeout=None):
def run(command, data=None, timeout=None, env=None):
"""Executes a given commmand and returns Response.
Blocks until process is complete, or timeout is reached.
Expand All @@ -168,7 +170,7 @@ def run(command, data=None, timeout=None):
data = history[-1].std_out[0:10*1024]

cmd = Command(c)
out, err = cmd.run(data, timeout)
out, err = cmd.run(data, timeout, env)

r = Response(process=cmd)

Expand All @@ -185,16 +187,17 @@ def run(command, data=None, timeout=None):
return r


def connect(command, data=None):
def connect(command, data=None, env=None):
"""Spawns a new process from the given command."""

# TODO: support piped commands
command_str = expand_args(command).pop()
environ = dict(os.environ).update(env or {})

process = subprocess.Popen(command_str,
universal_newlines=True,
shell=False,
env=os.environ,
env=environ,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand Down

0 comments on commit 04e88fe

Please sign in to comment.