Merge branch 'master' into autorequire

This commit is contained in:
Steven Armstrong 2011-11-18 15:13:52 +01:00
commit 30da237405
5 changed files with 20 additions and 10 deletions

View file

@ -95,6 +95,12 @@ class Local(object):
"""
assert isinstance(command, (list, tuple)), "list or tuple argument expected, got: %s" % command
self.log.debug("Local run: %s", command)
if env is None:
env = os.environ.copy()
# Export __target_host for use in __remote_{copy,exec} scripts
env['__target_host'] = self.target_host
try:
if return_output:
return subprocess.check_output(command, env=env).decode()
@ -114,8 +120,13 @@ class Local(object):
command.append(script)
self.log.debug("Local run script: %s", command)
if env:
self.log.debug("Local run script env: %s", env)
if env is None:
env = os.environ.copy()
# Export __target_host for use in __remote_{copy,exec} scripts
env['__target_host'] = self.target_host
self.log.debug("Local run script env: %s", env)
try:
if return_output:

View file

@ -91,7 +91,7 @@ class Remote(object):
self.rmdir(destination)
command = self._copy.split()
command.extend(["-r", source, self.target_host + ":" + destination])
self.run_command(command)
self._run_command(command)
def run(self, command, env=None, return_output=False):
"""Run the given command with the given environment on the remote side.
@ -102,9 +102,9 @@ class Remote(object):
cmd = self._exec.split()
cmd.append(self.target_host)
cmd.extend(command)
return self.run_command(cmd, env=env, return_output=return_output)
return self._run_command(cmd, env=env, return_output=return_output)
def run_command(self, command, env=None, return_output=False):
def _run_command(self, command, env=None, return_output=False):
"""Run the given command with the given environment.
Return the output as a string.