mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge remote-tracking branch 'origin/unstable' into unstable
This commit is contained in:
commit
1c6e368e61
1 changed files with 8 additions and 23 deletions
|
@ -307,8 +307,7 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False):
|
||||||
no_trace -- Do not print each command that will be executed
|
no_trace -- Do not print each command that will be executed
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import time
|
from moulinette.utils.process import call_async_output
|
||||||
from moulinette.utils.stream import start_async_file_reading
|
|
||||||
from yunohost.app import _value_for_locale
|
from yunohost.app import _value_for_locale
|
||||||
|
|
||||||
# Validate hook path
|
# Validate hook path
|
||||||
|
@ -379,28 +378,14 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False):
|
||||||
logger.info(m18n.n('executing_script', script='{0}/{1}'.format(
|
logger.info(m18n.n('executing_script', script='{0}/{1}'.format(
|
||||||
cmd_fdir, cmd_fname)))
|
cmd_fdir, cmd_fname)))
|
||||||
|
|
||||||
process = subprocess.Popen(command,
|
# Define output callbacks and call command
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
callbacks = (
|
||||||
shell=False)
|
lambda l: logger.info(l.rstrip()),
|
||||||
|
lambda l: logger.warning(l.rstrip()),
|
||||||
|
)
|
||||||
|
returncode = call_async_output(command, callbacks, shell=False)
|
||||||
|
|
||||||
# Wrap and get process outputs
|
# Check and return process' return code
|
||||||
stdout_reader, stdout_queue = start_async_file_reading(process.stdout)
|
|
||||||
stderr_reader, stderr_queue = start_async_file_reading(process.stderr)
|
|
||||||
while not stdout_reader.eof() and not stderr_reader.eof():
|
|
||||||
while not stdout_queue.empty():
|
|
||||||
line = stdout_queue.get()
|
|
||||||
logger.info(line.rstrip())
|
|
||||||
while not stderr_queue.empty():
|
|
||||||
line = stderr_queue.get()
|
|
||||||
logger.warning(line.rstrip())
|
|
||||||
time.sleep(.1)
|
|
||||||
|
|
||||||
# Terminate outputs readers
|
|
||||||
stdout_reader.join()
|
|
||||||
stderr_reader.join()
|
|
||||||
|
|
||||||
# Get and return process' return code
|
|
||||||
returncode = process.poll()
|
|
||||||
if returncode is None:
|
if returncode is None:
|
||||||
if raise_on_error:
|
if raise_on_error:
|
||||||
raise MoulinetteError(m18n.n('hook_exec_not_terminated'))
|
raise MoulinetteError(m18n.n('hook_exec_not_terminated'))
|
||||||
|
|
Loading…
Add table
Reference in a new issue