forked from ungleich-public/cdist
use remote_prefix internally
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
parent
c8dc4181f6
commit
bc9bc37aab
2 changed files with 16 additions and 16 deletions
|
@ -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):
|
def shell_run_or_debug_fail(script, *args, **kargs):
|
||||||
# Manually execute /bin/sh, because sh -e does what we want
|
# Manually execute /bin/sh, because sh -e does what we want
|
||||||
# and sh -c -e does not exit if /bin/false called
|
# and sh -c -e does not exit if /bin/false called
|
||||||
args[0][:0] = [ "/bin/sh", "-e" ]
|
args[0][:0] = [ "/bin/sh", "-e" ]
|
||||||
|
|
||||||
remote = False
|
if "remote_prefix" in kargs:
|
||||||
if "remote" in kargs:
|
remote = True
|
||||||
if kargs["remote"]:
|
|
||||||
args[0][:0] = kargs["remote_prefix"]
|
args[0][:0] = kargs["remote_prefix"]
|
||||||
remote = true
|
|
||||||
|
|
||||||
del kargs["remote"]
|
|
||||||
del kargs["remote_prefix"]
|
del kargs["remote_prefix"]
|
||||||
|
|
||||||
log.debug("Shell exec cmd: %s", args)
|
log.debug("Shell exec cmd: %s", args)
|
||||||
|
@ -41,6 +43,7 @@ def shell_run_or_debug_fail(script, *args, **kargs):
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
log.error("Code that raised the error:\n")
|
log.error("Code that raised the error:\n")
|
||||||
if remote:
|
if remote:
|
||||||
|
# FIXME: included in Path!
|
||||||
remote_cat(script)
|
remote_cat(script)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
@ -55,12 +58,9 @@ def shell_run_or_debug_fail(script, *args, **kargs):
|
||||||
raise CdistError(" ".join(*args) + ": " + error.args[1])
|
raise CdistError(" ".join(*args) + ": " + error.args[1])
|
||||||
|
|
||||||
|
|
||||||
def run_or_fail(self, *args, **kargs):
|
def run_or_fail(*args, **kargs):
|
||||||
if "remote" in kargs:
|
if "remote_prefix" in kargs:
|
||||||
if kargs["remote"]:
|
|
||||||
args[0][:0] = kargs["remote_prefix"]
|
args[0][:0] = kargs["remote_prefix"]
|
||||||
|
|
||||||
del kargs["remote"]
|
|
||||||
del kargs["remote_prefix"]
|
del kargs["remote_prefix"]
|
||||||
|
|
||||||
log.debug("Exec: " + " ".join(*args))
|
log.debug("Exec: " + " ".join(*args))
|
||||||
|
|
|
@ -121,14 +121,14 @@ class Path:
|
||||||
|
|
||||||
def remote_mkdir(self, directory):
|
def remote_mkdir(self, directory):
|
||||||
"""Create directory on remote side"""
|
"""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):
|
def remote_cat(filename):
|
||||||
"""Use cat on the remote side for output"""
|
"""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):
|
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):
|
def transfer_dir(self, source, destination):
|
||||||
"""Transfer directory and previously delete the remote destination"""
|
"""Transfer directory and previously delete the remote destination"""
|
||||||
|
|
Loading…
Reference in a new issue