mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Update hook.py to use logging instead of msignals.display
This commit is contained in:
parent
85d579b9ff
commit
b7d0e977b9
2 changed files with 20 additions and 17 deletions
|
@ -37,7 +37,8 @@
|
||||||
"mysql_db_initialized" : "MySQL database successfully initialized",
|
"mysql_db_initialized" : "MySQL database successfully initialized",
|
||||||
"extracting" : "Extracting...",
|
"extracting" : "Extracting...",
|
||||||
"downloading" : "Downloading...",
|
"downloading" : "Downloading...",
|
||||||
"executing_script": "Executing script...",
|
"executing_script": "Executing script '{script:s}'...",
|
||||||
|
"executing_command": "Executing command '{command:s}'...",
|
||||||
"done" : "Done.",
|
"done" : "Done.",
|
||||||
|
|
||||||
"path_removal_failed" : "Unable to remove path {:s}",
|
"path_removal_failed" : "Unable to remove path {:s}",
|
||||||
|
|
|
@ -32,12 +32,12 @@ import subprocess
|
||||||
from glob import iglob
|
from glob import iglob
|
||||||
|
|
||||||
from moulinette.core import MoulinetteError
|
from moulinette.core import MoulinetteError
|
||||||
from moulinette.utils.log import getActionLogger
|
from moulinette.utils import log
|
||||||
|
|
||||||
hook_folder = '/usr/share/yunohost/hooks/'
|
hook_folder = '/usr/share/yunohost/hooks/'
|
||||||
custom_hook_folder = '/etc/yunohost/hooks.d/'
|
custom_hook_folder = '/etc/yunohost/hooks.d/'
|
||||||
|
|
||||||
logger = getActionLogger('yunohost.hook')
|
logger = log.getActionLogger('yunohost.hook')
|
||||||
|
|
||||||
|
|
||||||
def hook_add(app, file):
|
def hook_add(app, file):
|
||||||
|
@ -264,14 +264,9 @@ def hook_callback(action, hooks=[], args=None):
|
||||||
state = 'succeed'
|
state = 'succeed'
|
||||||
filename = '%s-%s' % (priority, name)
|
filename = '%s-%s' % (priority, name)
|
||||||
try:
|
try:
|
||||||
ret = hook_exec(info['path'], args=args)
|
hook_exec(info['path'], args=args, raise_on_error=True)
|
||||||
except:
|
except MoulinetteError as e:
|
||||||
logger.exception("error while executing hook '%s'",
|
logger.error(e.strerror)
|
||||||
info['path'])
|
|
||||||
state = 'failed'
|
|
||||||
if ret != 0:
|
|
||||||
logger.error("error while executing hook '%s', retcode: %d",
|
|
||||||
info['path'], ret)
|
|
||||||
state = 'failed'
|
state = 'failed'
|
||||||
try:
|
try:
|
||||||
result[state][name].append(info['path'])
|
result[state][name].append(info['path'])
|
||||||
|
@ -364,12 +359,19 @@ def hook_exec(file, args=None, raise_on_error=False):
|
||||||
# bash related issue if an argument is empty and is not the last
|
# bash related issue if an argument is empty and is not the last
|
||||||
arg_str = '"{:s}"'.format('" "'.join(str(s) for s in arg_list))
|
arg_str = '"{:s}"'.format('" "'.join(str(s) for s in arg_list))
|
||||||
|
|
||||||
msignals.display(m18n.n('executing_script'))
|
# Construct command to execute
|
||||||
|
command = [
|
||||||
|
'sudo', '-u', 'admin', '-H', 'sh', '-c',
|
||||||
|
'cd "{:s}" && /bin/bash -x "{:s}" {:s}'.format(
|
||||||
|
file_path, file, arg_str),
|
||||||
|
]
|
||||||
|
if logger.isEnabledFor(log.DEBUG):
|
||||||
|
logger.info(m18n.n('executing_command', command=' '.join(command)))
|
||||||
|
else:
|
||||||
|
logger.info(m18n.n('executing_script', script='{0}/{1}'.format(
|
||||||
|
file_path, file)))
|
||||||
|
|
||||||
p = subprocess.Popen(
|
p = subprocess.Popen(command,
|
||||||
['sudo', '-u', 'admin', '-H', 'sh', '-c', 'cd "{:s}" && ' \
|
|
||||||
'/bin/bash -x "{:s}" {:s}'.format(
|
|
||||||
file_path, file, arg_str)],
|
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||||
shell=False)
|
shell=False)
|
||||||
|
|
||||||
|
@ -383,7 +385,7 @@ def hook_exec(file, args=None, raise_on_error=False):
|
||||||
if returncode is not None:
|
if returncode is not None:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
msignals.display(line.rstrip(), 'log')
|
logger.info(line.rstrip())
|
||||||
stream.close()
|
stream.close()
|
||||||
|
|
||||||
if raise_on_error and returncode != 0:
|
if raise_on_error and returncode != 0:
|
||||||
|
|
Loading…
Add table
Reference in a new issue