From ab1d3d16f16c94e42174ccdcedd791c69bb970c8 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 15:51:00 +0200 Subject: [PATCH] implement: dont return command output by default Signed-off-by: Steven Armstrong --- lib/cdist/exec/local.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/cdist/exec/local.py b/lib/cdist/exec/local.py index bef44e21..56c29cb7 100644 --- a/lib/cdist/exec/local.py +++ b/lib/cdist/exec/local.py @@ -87,7 +87,7 @@ class Local(object): # FIXME: dont set mode here, fix unittest mkdtemp instead os.makedirs(path, mode=0o700, exist_ok=True) - def run(self, command, env=None): + def run(self, command, env=None, return_output=False): """Run the given command with the given environment. Return the output as a string. @@ -95,13 +95,16 @@ class Local(object): assert isinstance(command, (list, tuple)), "list or tuple argument expected, got: %s" % command self.log.debug("Local run: %s", command) try: - return subprocess.check_output(command, env=env).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. Return the output as a string. @@ -114,7 +117,10 @@ class Local(object): self.log.debug("Local run script env: %s", env) try: - return subprocess.check_output(command, env=env).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)