forked from ungleich-public/cdist
easier check for remote_prefix
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
parent
24b8a57df5
commit
6e73572a95
1 changed files with 9 additions and 13 deletions
|
@ -26,16 +26,13 @@ log = logging.getLogger(__name__)
|
||||||
|
|
||||||
import cdist
|
import cdist
|
||||||
|
|
||||||
def shell_run_or_debug_fail(script, *args, **kargs):
|
def shell_run_or_debug_fail(script, *args, remote_prefix=False, **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:
|
||||||
if "remote_prefix" in kargs:
|
args[0][:0] = remote_prefix
|
||||||
remote = True
|
|
||||||
args[0][:0] = kargs["remote_prefix"]
|
|
||||||
del kargs["remote_prefix"]
|
|
||||||
|
|
||||||
log.debug("Shell exec cmd: %s", args)
|
log.debug("Shell exec cmd: %s", args)
|
||||||
|
|
||||||
|
@ -46,9 +43,9 @@ def shell_run_or_debug_fail(script, *args, **kargs):
|
||||||
subprocess.check_call(*args, **kargs)
|
subprocess.check_call(*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_prefix:
|
||||||
# FIXME: included in Path!
|
run_or_fail(["cat", script], remote_prefix=remote_prefix)
|
||||||
remote_cat(script)
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
script_fd = open(script)
|
script_fd = open(script)
|
||||||
|
@ -62,10 +59,9 @@ def shell_run_or_debug_fail(script, *args, **kargs):
|
||||||
raise cdist.Error(" ".join(*args) + ": " + error.args[1])
|
raise cdist.Error(" ".join(*args) + ": " + error.args[1])
|
||||||
|
|
||||||
|
|
||||||
def run_or_fail(*args, **kargs):
|
def run_or_fail(*args, remote_prefix=False, **kargs):
|
||||||
if "remote_prefix" in kargs:
|
if remote_prefix:
|
||||||
args[0][:0] = kargs["remote_prefix"]
|
args[0][:0] = remote_prefix
|
||||||
del kargs["remote_prefix"]
|
|
||||||
|
|
||||||
log.debug("Exec: " + " ".join(*args))
|
log.debug("Exec: " + " ".join(*args))
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue