use remote_prefix internally

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
Nico Schottelius 2011-09-26 10:17:02 +02:00
parent c8dc4181f6
commit bc9bc37aab
2 changed files with 16 additions and 16 deletions

View file

@ -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))

View file

@ -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"""