Merge pull request #360 from YunoHost/enh-add-post-hook-for-apps

Add post hooks for apps operation
This commit is contained in:
Laurent Peuch 2018-02-08 03:10:03 +01:00 committed by GitHub
commit c88cafbcbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -432,7 +432,7 @@ def app_change_url(auth, app, domain, path):
path -- New path at which the application will be move path -- New path at which the application will be move
""" """
from yunohost.hook import hook_exec from yunohost.hook import hook_exec, hook_callback
installed = _is_installed(app) installed = _is_installed(app)
if not installed: if not installed:
@ -527,6 +527,8 @@ def app_change_url(auth, app, domain, path):
logger.success(m18n.n("app_change_url_success", logger.success(m18n.n("app_change_url_success",
app=app, domain=domain, path=path)) app=app, domain=domain, path=path))
hook_callback('post_app_change_url', args=args_list, env=env_dict)
def app_upgrade(auth, app=[], url=None, file=None): def app_upgrade(auth, app=[], url=None, file=None):
""" """
@ -538,7 +540,8 @@ def app_upgrade(auth, app=[], url=None, file=None):
url -- Git url to fetch for upgrade url -- Git url to fetch for upgrade
""" """
from yunohost.hook import hook_add, hook_remove, hook_exec from yunohost.hook import hook_add, hook_remove, hook_exec, hook_callback
# Retrieve interface # Retrieve interface
is_api = msettings.get('interface') == 'api' is_api = msettings.get('interface') == 'api'
@ -641,6 +644,9 @@ def app_upgrade(auth, app=[], url=None, file=None):
upgraded_apps.append(app_instance_name) upgraded_apps.append(app_instance_name)
logger.success(m18n.n('app_upgraded', app=app_instance_name)) logger.success(m18n.n('app_upgraded', app=app_instance_name))
hook_callback('post_app_upgrade', args=args_list, env=env_dict)
if not upgraded_apps: if not upgraded_apps:
raise MoulinetteError(errno.ENODATA, m18n.n('app_no_upgrade')) raise MoulinetteError(errno.ENODATA, m18n.n('app_no_upgrade'))
@ -664,7 +670,7 @@ def app_install(auth, app, label=None, args=None, no_remove_on_failure=False):
no_remove_on_failure -- Debug option to avoid removing the app on a failed installation no_remove_on_failure -- Debug option to avoid removing the app on a failed installation
""" """
from yunohost.hook import hook_add, hook_remove, hook_exec from yunohost.hook import hook_add, hook_remove, hook_exec, hook_callback
# Fetch or extract sources # Fetch or extract sources
try: try:
@ -806,6 +812,8 @@ def app_install(auth, app, label=None, args=None, no_remove_on_failure=False):
logger.success(m18n.n('installation_complete')) logger.success(m18n.n('installation_complete'))
hook_callback('post_app_install', args=args_list, env=env_dict)
def app_remove(auth, app): def app_remove(auth, app):
""" """
@ -815,7 +823,7 @@ def app_remove(auth, app):
app -- App(s) to delete app -- App(s) to delete
""" """
from yunohost.hook import hook_exec, hook_remove from yunohost.hook import hook_exec, hook_remove, hook_callback
if not _is_installed(app): if not _is_installed(app):
raise MoulinetteError(errno.EINVAL, raise MoulinetteError(errno.EINVAL,
@ -844,6 +852,8 @@ def app_remove(auth, app):
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)) logger.success(m18n.n('app_removed', app=app))
hook_callback('post_app_remove', args=args_list, env=env_dict)
if os.path.exists(app_setting_path): if os.path.exists(app_setting_path):
shutil.rmtree(app_setting_path) shutil.rmtree(app_setting_path)
shutil.rmtree('/tmp/yunohost_remove') shutil.rmtree('/tmp/yunohost_remove')