[enh] Add execution dir in env on hook exec (#293)

* [enh] Add execution dir in env on hook exec
* [enh] YNH_EXECUTION_DIR become YNH_CWD
* [fix] Hook exec with no env fail
* [enh] Remove dead condition
This commit is contained in:
ljf (zamentur) 2017-05-03 19:11:01 +02:00 committed by Alexandre Aubin
parent caa63f7022
commit afe28470c0

View file

@ -326,6 +326,11 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
else:
cmd_script = path
# Add Execution dir to environment var
if env is None:
env = {}
env['YNH_CWD'] = chdir
# Construct command to execute
if user == "root":
command = ['sh', '-c']
@ -337,11 +342,11 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
else:
# use xtrace on fd 7 which is redirected to stdout
cmd = 'BASH_XTRACEFD=7 /bin/bash -x "{script}" {args} 7>&1'
if env:
# prepend environment variables
cmd = '{0} {1}'.format(
' '.join(['{0}={1}'.format(k, shell_quote(v)) \
for k, v in env.items()]), cmd)
# prepend environment variables
cmd = '{0} {1}'.format(
' '.join(['{0}={1}'.format(k, shell_quote(v)) \
for k, v in env.items()]), cmd)
command.append(cmd.format(script=cmd_script, args=cmd_args))
if logger.isEnabledFor(log.DEBUG):