From bc9bc37aab80bc85d991621da9addd016ac9d0d4 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 26 Sep 2011 10:17:02 +0200 Subject: [PATCH] use remote_prefix internally Signed-off-by: Nico Schottelius --- lib/cdist/exec.py | 26 +++++++++++++------------- lib/cdist/path.py | 6 +++--- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/cdist/exec.py b/lib/cdist/exec.py index a4cf4592..aca1d689 100644 --- a/lib/cdist/exec.py +++ b/lib/cdist/exec.py @@ -19,19 +19,21 @@ # # +import logging +import subprocess + +logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s') +log = logging.getLogger() + def shell_run_or_debug_fail(script, *args, **kargs): # Manually execute /bin/sh, because sh -e does what we want # and sh -c -e does not exit if /bin/false called args[0][:0] = [ "/bin/sh", "-e" ] - remote = False - if "remote" in kargs: - if kargs["remote"]: - args[0][:0] = kargs["remote_prefix"] - remote = true - - del kargs["remote"] + if "remote_prefix" in kargs: + remote = True + args[0][:0] = kargs["remote_prefix"] del kargs["remote_prefix"] log.debug("Shell exec cmd: %s", args) @@ -41,6 +43,7 @@ def shell_run_or_debug_fail(script, *args, **kargs): except subprocess.CalledProcessError: log.error("Code that raised the error:\n") if remote: + # FIXME: included in Path! remote_cat(script) else: try: @@ -55,12 +58,9 @@ def shell_run_or_debug_fail(script, *args, **kargs): raise CdistError(" ".join(*args) + ": " + error.args[1]) -def run_or_fail(self, *args, **kargs): - if "remote" in kargs: - if kargs["remote"]: - args[0][:0] = kargs["remote_prefix"] - - del kargs["remote"] +def run_or_fail(*args, **kargs): + if "remote_prefix" in kargs: + args[0][:0] = kargs["remote_prefix"] del kargs["remote_prefix"] log.debug("Exec: " + " ".join(*args)) diff --git a/lib/cdist/path.py b/lib/cdist/path.py index 1e9d7195..c2cef1a6 100644 --- a/lib/cdist/path.py +++ b/lib/cdist/path.py @@ -121,14 +121,14 @@ class Path: def remote_mkdir(self, directory): """Create directory on remote side""" - cdist.exec.run_or_fail(["mkdir", "-p", directory], remote=True) + cdist.exec.run_or_fail(["mkdir", "-p", directory], remote_prefix=self.remote_prefix) def remote_cat(filename): """Use cat on the remote side for output""" - cdist.exec.run_or_fail(["cat", filename], remote=True) + cdist.exec.run_or_fail(["cat", filename], remote_prefix=self.remote_prefix) def remove_remote_dir(self, destination): - cdist.exec.run_or_fail(["rm", "-rf", destination], remote=True) + cdist.exec.run_or_fail(["rm", "-rf", destination], remote_prefix=self.remote_prefix) def transfer_dir(self, source, destination): """Transfer directory and previously delete the remote destination"""