From 829b0b2d0b3faa10366d2c8fcd95b01f01093b74 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 15:52:16 +0200 Subject: [PATCH] implement: dont return command output by default Signed-off-by: Steven Armstrong --- lib/cdist/exec/remote.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/cdist/exec/remote.py b/lib/cdist/exec/remote.py index 2ffc73fd..2de16426 100644 --- a/lib/cdist/exec/remote.py +++ b/lib/cdist/exec/remote.py @@ -85,7 +85,7 @@ class Remote(object): command.extend(["-r", source, self.target_host + ":" + destination]) self.run_command(command) - def run(self, command, env=None): + def run(self, command, env=None, return_output=False): """Run the given command with the given environment on the remote side. Return the output as a string. @@ -94,9 +94,9 @@ class Remote(object): cmd = self._exec.split() cmd.append(self.target_host) cmd.extend(command) - return self.run_command(cmd, env=env) + return self.run_command(cmd, env=env, return_output=return_output) - def run_command(self, command, env=None): + def run_command(self, command, env=None, return_output=False): """Run the given command with the given environment. Return the output as a string. @@ -113,13 +113,16 @@ class Remote(object): self.log.debug("Remote run: %s", command) try: - return subprocess.check_output(cmd).decode() + if return_output: + return subprocess.check_output(command, env=env).decode() + else: + subprocess.check_call(command, env=env) except subprocess.CalledProcessError: raise cdist.Error("Command failed: " + " ".join(command)) except OSError as error: raise cdist.Error(" ".join(*args) + ": " + error.args[1]) - def run_script(self, script, env=None): + def run_script(self, script, env=None, return_output=False): """Run the given script with the given environment on the remote side. Return the output as a string. @@ -140,7 +143,10 @@ class Remote(object): self.log.debug("Remote run script env: %s", env) try: - return subprocess.check_output(command).decode() + if return_output: + return subprocess.check_output(command, env=env).decode() + else: + subprocess.check_call(command, env=env) except subprocess.CalledProcessError as error: script_content = self.run(["cat", script]) self.log.error("Code that raised the error:\n%s", script_content)