mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
We ain't using argument user nor no_trace
This commit is contained in:
parent
28b8a0ef6a
commit
e0ac7de432
1 changed files with 9 additions and 19 deletions
|
@ -211,7 +211,7 @@ def hook_list(action, list_by='name', show_info=False):
|
||||||
return {'hooks': result}
|
return {'hooks': result}
|
||||||
|
|
||||||
|
|
||||||
def hook_callback(action, hooks=[], args=None, no_trace=False, chdir=None,
|
def hook_callback(action, hooks=[], args=None, chdir=None,
|
||||||
env=None, pre_callback=None, post_callback=None):
|
env=None, pre_callback=None, post_callback=None):
|
||||||
"""
|
"""
|
||||||
Execute all scripts binded to an action
|
Execute all scripts binded to an action
|
||||||
|
@ -220,7 +220,6 @@ def hook_callback(action, hooks=[], args=None, no_trace=False, chdir=None,
|
||||||
action -- Action name
|
action -- Action name
|
||||||
hooks -- List of hooks names to execute
|
hooks -- List of hooks names to execute
|
||||||
args -- Ordered list of arguments to pass to the scripts
|
args -- Ordered list of arguments to pass to the scripts
|
||||||
no_trace -- Do not print each command that will be executed
|
|
||||||
chdir -- The directory from where the scripts will be executed
|
chdir -- The directory from where the scripts will be executed
|
||||||
env -- Dictionnary of environment variables to export
|
env -- Dictionnary of environment variables to export
|
||||||
pre_callback -- An object to call before each script execution with
|
pre_callback -- An object to call before each script execution with
|
||||||
|
@ -281,7 +280,7 @@ def hook_callback(action, hooks=[], args=None, no_trace=False, chdir=None,
|
||||||
hook_args = pre_callback(name=name, priority=priority,
|
hook_args = pre_callback(name=name, priority=priority,
|
||||||
path=path, args=args)
|
path=path, args=args)
|
||||||
hook_return = hook_exec(path, args=hook_args, chdir=chdir, env=env,
|
hook_return = hook_exec(path, args=hook_args, chdir=chdir, env=env,
|
||||||
no_trace=no_trace, raise_on_error=True)[1]
|
raise_on_error=True)[1]
|
||||||
except YunohostError as e:
|
except YunohostError as e:
|
||||||
state = 'failed'
|
state = 'failed'
|
||||||
hook_return = {}
|
hook_return = {}
|
||||||
|
@ -297,8 +296,8 @@ def hook_callback(action, hooks=[], args=None, no_trace=False, chdir=None,
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
|
def hook_exec(path, args=None, raise_on_error=False,
|
||||||
chdir=None, env=None, user="root", return_format="json"):
|
chdir=None, env=None, return_format="json"):
|
||||||
"""
|
"""
|
||||||
Execute hook from a file with arguments
|
Execute hook from a file with arguments
|
||||||
|
|
||||||
|
@ -306,11 +305,8 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
|
||||||
path -- Path of the script to execute
|
path -- Path of the script to execute
|
||||||
args -- Ordered list of arguments to pass to the script
|
args -- Ordered list of arguments to pass to the script
|
||||||
raise_on_error -- Raise if the script returns a non-zero exit code
|
raise_on_error -- Raise if the script returns a non-zero exit code
|
||||||
no_trace -- Do not print each command that will be executed
|
|
||||||
chdir -- The directory from where the script will be executed
|
chdir -- The directory from where the script will be executed
|
||||||
env -- Dictionnary of environment variables to export
|
env -- Dictionnary of environment variables to export
|
||||||
user -- User with which to run the command
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Validate hook path
|
# Validate hook path
|
||||||
|
@ -348,7 +344,7 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
|
||||||
if hook_type == 'text/x-python':
|
if hook_type == 'text/x-python':
|
||||||
returncode, returndata = _hook_exec_python(path, args, env, loggers)
|
returncode, returndata = _hook_exec_python(path, args, env, loggers)
|
||||||
else:
|
else:
|
||||||
returncode, returndata = _hook_exec_bash(path, args, no_trace, chdir, env, user, return_format, loggers)
|
returncode, returndata = _hook_exec_bash(path, args, chdir, env, return_format, loggers)
|
||||||
|
|
||||||
# Check and return process' return code
|
# Check and return process' return code
|
||||||
if returncode is None:
|
if returncode is None:
|
||||||
|
@ -363,7 +359,7 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
|
||||||
return returncode, returndata
|
return returncode, returndata
|
||||||
|
|
||||||
|
|
||||||
def _hook_exec_bash(path, args, no_trace, chdir, env, user, return_format, loggers):
|
def _hook_exec_bash(path, args, chdir, env, return_format, loggers):
|
||||||
|
|
||||||
from moulinette.utils.process import call_async_output
|
from moulinette.utils.process import call_async_output
|
||||||
|
|
||||||
|
@ -395,16 +391,10 @@ def _hook_exec_bash(path, args, no_trace, chdir, env, user, return_format, logge
|
||||||
env['YNH_STDRETURN'] = stdreturn
|
env['YNH_STDRETURN'] = stdreturn
|
||||||
|
|
||||||
# Construct command to execute
|
# Construct command to execute
|
||||||
if user == "root":
|
command = ['sh', '-c']
|
||||||
command = ['sh', '-c']
|
|
||||||
else:
|
|
||||||
command = ['sudo', '-n', '-u', user, '-H', 'sh', '-c']
|
|
||||||
|
|
||||||
if no_trace:
|
# use xtrace on fd 7 which is redirected to stdout
|
||||||
cmd = '/bin/bash "{script}" {args}'
|
cmd = 'BASH_XTRACEFD=7 /bin/bash -x "{script}" {args} 7>&1'
|
||||||
else:
|
|
||||||
# use xtrace on fd 7 which is redirected to stdout
|
|
||||||
cmd = 'BASH_XTRACEFD=7 /bin/bash -x "{script}" {args} 7>&1'
|
|
||||||
|
|
||||||
# prepend environment variables
|
# prepend environment variables
|
||||||
cmd = '{0} {1}'.format(
|
cmd = '{0} {1}'.format(
|
||||||
|
|
Loading…
Add table
Reference in a new issue