mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #383 from YunoHost/app-stdinfo
[enh] Add ynh_info helper for app scripts
This commit is contained in:
commit
c36ba42809
3 changed files with 26 additions and 4 deletions
|
@ -5,6 +5,14 @@ ynh_die() {
|
|||
exit "${2:-1}"
|
||||
}
|
||||
|
||||
# Display a message in the 'INFO' logging category
|
||||
#
|
||||
# usage: ynh_info "Some message"
|
||||
ynh_info()
|
||||
{
|
||||
echo "$1" >>"$YNH_STDINFO"
|
||||
}
|
||||
|
||||
# Ignore the yunohost-cli log to prevent errors with conditionals commands
|
||||
#
|
||||
# [internal]
|
||||
|
|
|
@ -512,7 +512,8 @@ def app_change_url(operation_logger, auth, app, domain, path):
|
|||
os.system('chmod +x %s' % os.path.join(os.path.join(APP_TMP_FOLDER, "scripts")))
|
||||
os.system('chmod +x %s' % os.path.join(os.path.join(APP_TMP_FOLDER, "scripts", "change_url")))
|
||||
|
||||
if hook_exec(os.path.join(APP_TMP_FOLDER, 'scripts/change_url'), args=args_list, env=env_dict, user="root") != 0:
|
||||
if hook_exec(os.path.join(APP_TMP_FOLDER, 'scripts/change_url'),
|
||||
args=args_list, env=env_dict, user="root") != 0:
|
||||
msg = "Failed to change '%s' url." % app
|
||||
logger.error(msg)
|
||||
operation_logger.error(msg)
|
||||
|
@ -638,7 +639,8 @@ def app_upgrade(auth, app=[], url=None, file=None):
|
|||
|
||||
# Execute App upgrade script
|
||||
os.system('chown -hR admin: %s' % INSTALL_TMP)
|
||||
if hook_exec(extracted_app_folder + '/scripts/upgrade', args=args_list, env=env_dict, user="root") != 0:
|
||||
if hook_exec(extracted_app_folder + '/scripts/upgrade',
|
||||
args=args_list, env=env_dict, user="root") != 0:
|
||||
msg = m18n.n('app_upgrade_failed', app=app_instance_name)
|
||||
logger.error(msg)
|
||||
operation_logger.error(msg)
|
||||
|
@ -909,7 +911,8 @@ def app_remove(operation_logger, auth, app):
|
|||
operation_logger.extra.update({'env': env_dict})
|
||||
operation_logger.flush()
|
||||
|
||||
if hook_exec('/tmp/yunohost_remove/scripts/remove', args=args_list, env=env_dict, user="root") == 0:
|
||||
if hook_exec('/tmp/yunohost_remove/scripts/remove', args=args_list,
|
||||
env=env_dict, user="root") == 0:
|
||||
logger.success(m18n.n('app_removed', app=app))
|
||||
|
||||
hook_callback('post_app_remove', args=args_list, env=env_dict)
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
import os
|
||||
import re
|
||||
import errno
|
||||
import tempfile
|
||||
from glob import iglob
|
||||
|
||||
from moulinette import m18n
|
||||
|
@ -337,6 +338,9 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
|
|||
env = {}
|
||||
env['YNH_CWD'] = chdir
|
||||
|
||||
stdinfo = os.path.join(tempfile.mkdtemp(), "stdinfo")
|
||||
env['YNH_STDINFO'] = stdinfo
|
||||
|
||||
# Construct command to execute
|
||||
if user == "root":
|
||||
command = ['sh', '-c']
|
||||
|
@ -365,9 +369,16 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
|
|||
stdout_callback if stdout_callback else lambda l: logger.debug(l.rstrip()),
|
||||
stderr_callback if stderr_callback else lambda l: logger.warning(l.rstrip()),
|
||||
)
|
||||
|
||||
if stdinfo:
|
||||
callbacks = ( callbacks[0], callbacks[1],
|
||||
lambda l: logger.info(l.rstrip()))
|
||||
|
||||
logger.debug("About to run the command '%s'" % command)
|
||||
|
||||
returncode = call_async_output(
|
||||
command, callbacks, shell=False, cwd=chdir
|
||||
command, callbacks, shell=False, cwd=chdir,
|
||||
stdinfo=stdinfo
|
||||
)
|
||||
|
||||
# Check and return process' return code
|
||||
|
|
Loading…
Add table
Reference in a new issue