mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Hooks hooks hooks
This commit is contained in:
parent
e6afa54b49
commit
2d90133e18
3 changed files with 60 additions and 16 deletions
|
@ -811,16 +811,21 @@ hook:
|
||||||
|
|
||||||
### hook_add()
|
### hook_add()
|
||||||
add:
|
add:
|
||||||
action_help: Store hook script to filsystem
|
action_help: Store hook script to filesystem
|
||||||
api: PUT /hook
|
api: PUT /hook
|
||||||
arguments:
|
arguments:
|
||||||
action:
|
app:
|
||||||
help: Action folder to store into
|
help: App to link with
|
||||||
file:
|
file:
|
||||||
help: Script to check
|
help: Script to add
|
||||||
-n:
|
|
||||||
full: --name
|
### hook_remove()
|
||||||
help: Destination name for the script
|
remove:
|
||||||
|
action_help: Remove hook scripts from filesystem
|
||||||
|
api: DELETE /hook
|
||||||
|
arguments:
|
||||||
|
app:
|
||||||
|
help: Scripts related to app will be removed
|
||||||
|
|
||||||
### hook_callback()
|
### hook_callback()
|
||||||
callback:
|
callback:
|
||||||
|
|
|
@ -36,7 +36,7 @@ import urlparse
|
||||||
from yunohost import YunoHostError, YunoHostLDAP, win_msg, random_password, is_true, validate
|
from yunohost import YunoHostError, YunoHostLDAP, win_msg, random_password, is_true, validate
|
||||||
from yunohost_domain import domain_list, domain_add
|
from yunohost_domain import domain_list, domain_add
|
||||||
from yunohost_user import user_info, user_list
|
from yunohost_user import user_info, user_list
|
||||||
from yunohost_hook import hook_exec
|
from yunohost_hook import hook_exec, hook_add, hook_remove
|
||||||
|
|
||||||
repo_path = '/var/cache/yunohost/repo'
|
repo_path = '/var/cache/yunohost/repo'
|
||||||
apps_path = '/usr/share/yunohost/apps'
|
apps_path = '/usr/share/yunohost/apps'
|
||||||
|
@ -374,7 +374,6 @@ def app_install(app, label=None, args=None):
|
||||||
|
|
||||||
# Replace app_id with the new one in scripts
|
# Replace app_id with the new one in scripts
|
||||||
for file in os.listdir(app_tmp_folder +'/scripts'):
|
for file in os.listdir(app_tmp_folder +'/scripts'):
|
||||||
#TODO: add hooks directory to the list
|
|
||||||
#TODO: do it with sed ?
|
#TODO: do it with sed ?
|
||||||
if file[:1] != '.':
|
if file[:1] != '.':
|
||||||
with open(app_tmp_folder +'/scripts/'+ file, "r") as sources:
|
with open(app_tmp_folder +'/scripts/'+ file, "r") as sources:
|
||||||
|
@ -383,6 +382,16 @@ def app_install(app, label=None, args=None):
|
||||||
for line in lines:
|
for line in lines:
|
||||||
sources.write(re.sub(r''+ app_id +'', app_id_forked, line))
|
sources.write(re.sub(r''+ app_id +'', app_id_forked, line))
|
||||||
|
|
||||||
|
if 'hooks' in os.listdir(app_tmp_folder):
|
||||||
|
for file in os.listdir(app_tmp_folder +'/hooks'):
|
||||||
|
#TODO: do it with sed ?
|
||||||
|
if file[:1] != '.':
|
||||||
|
with open(app_tmp_folder +'/hooks/'+ file, "r") as sources:
|
||||||
|
lines = sources.readlines()
|
||||||
|
with open(app_tmp_folder +'/hooks/'+ file, "w") as sources:
|
||||||
|
for line in lines:
|
||||||
|
sources.write(re.sub(r''+ app_id +'', app_id_forked, line))
|
||||||
|
|
||||||
# Change app_id for the rest of the process
|
# Change app_id for the rest of the process
|
||||||
app_id = app_id_forked
|
app_id = app_id_forked
|
||||||
|
|
||||||
|
@ -394,6 +403,11 @@ def app_install(app, label=None, args=None):
|
||||||
os.makedirs(app_setting_path)
|
os.makedirs(app_setting_path)
|
||||||
os.system('touch '+ app_setting_path +'/settings.yml')
|
os.system('touch '+ app_setting_path +'/settings.yml')
|
||||||
|
|
||||||
|
# Add hooks
|
||||||
|
if 'hooks' in os.listdir(app_tmp_folder):
|
||||||
|
for file in os.listdir(app_tmp_folder +'/hooks'):
|
||||||
|
hook_add(app_id, app_tmp_folder +'/hooks/'+ file)
|
||||||
|
|
||||||
app_setting(app_id, 'id', app_id)
|
app_setting(app_id, 'id', app_id)
|
||||||
app_setting(app_id, 'install_time', int(time.time()))
|
app_setting(app_id, 'install_time', int(time.time()))
|
||||||
|
|
||||||
|
@ -426,10 +440,12 @@ def app_install(app, label=None, args=None):
|
||||||
win_msg(_("Installation complete"))
|
win_msg(_("Installation complete"))
|
||||||
else:
|
else:
|
||||||
#TODO: display script fail messages
|
#TODO: display script fail messages
|
||||||
|
hook_remove(app_id)
|
||||||
shutil.rmtree(app_setting_path)
|
shutil.rmtree(app_setting_path)
|
||||||
shutil.rmtree(app_tmp_folder)
|
shutil.rmtree(app_tmp_folder)
|
||||||
raise YunoHostError(1, _("Installation failed"))
|
raise YunoHostError(1, _("Installation failed"))
|
||||||
except KeyboardInterrupt, EOFError:
|
except KeyboardInterrupt, EOFError:
|
||||||
|
hook_remove(app_id)
|
||||||
shutil.rmtree(app_setting_path)
|
shutil.rmtree(app_setting_path)
|
||||||
shutil.rmtree(app_tmp_folder)
|
shutil.rmtree(app_tmp_folder)
|
||||||
raise YunoHostError(125, _("Interrupted"))
|
raise YunoHostError(125, _("Interrupted"))
|
||||||
|
@ -463,6 +479,7 @@ def app_remove(app):
|
||||||
|
|
||||||
if os.path.exists(app_setting_path): shutil.rmtree(app_setting_path)
|
if os.path.exists(app_setting_path): shutil.rmtree(app_setting_path)
|
||||||
shutil.rmtree('/tmp/yunohost_remove')
|
shutil.rmtree('/tmp/yunohost_remove')
|
||||||
|
hook_remove(app)
|
||||||
app_ssowatconf()
|
app_ssowatconf()
|
||||||
win_msg(_("App removed: ")+ app)
|
win_msg(_("App removed: ")+ app)
|
||||||
|
|
||||||
|
|
|
@ -31,23 +31,45 @@ from yunohost import YunoHostError, YunoHostLDAP, win_msg, colorize
|
||||||
|
|
||||||
hook_folder = '/usr/share/yunohost/hooks/'
|
hook_folder = '/usr/share/yunohost/hooks/'
|
||||||
|
|
||||||
def hook_add(action, file, name=None):
|
def hook_add(app, file):
|
||||||
"""
|
"""
|
||||||
Store hook script to filsystem
|
Store hook script to filsystem
|
||||||
|
|
||||||
Keyword argument:
|
Keyword argument:
|
||||||
file -- Script to add
|
app -- App to link with
|
||||||
action -- Action folder to store into
|
file -- Script to add (/path/priority-file)
|
||||||
name -- Destination name
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
path, filename = os.path.split(file)
|
||||||
|
if '-' in filename:
|
||||||
|
priority, action = filename.split('-')
|
||||||
|
else:
|
||||||
|
priority = '50'
|
||||||
|
action = filename
|
||||||
|
|
||||||
try: os.listdir(hook_folder + action)
|
try: os.listdir(hook_folder + action)
|
||||||
except OSError: os.makedirs(hook_folder + action)
|
except OSError: os.makedirs(hook_folder + action)
|
||||||
|
|
||||||
if name is None:
|
finalpath = hook_folder + action +'/'+ priority +'-'+ app
|
||||||
name = ''
|
print app
|
||||||
|
os.system('cp '+ file +' '+ finalpath)
|
||||||
|
os.system('chown -hR admin: '+ hook_folder)
|
||||||
|
|
||||||
os.system('cp '+ file +' '+ hook_folder + action +'/'+ name)
|
return { 'hook': finalpath }
|
||||||
|
|
||||||
|
|
||||||
|
def hook_remove(app):
|
||||||
|
"""
|
||||||
|
Remove hooks linked to a specific app
|
||||||
|
|
||||||
|
Keyword argument:
|
||||||
|
app -- Scripts related to app will be removed
|
||||||
|
|
||||||
|
"""
|
||||||
|
for action in os.listdir(hook_folder):
|
||||||
|
for script in os.listdir(hook_folder + action):
|
||||||
|
if script.endswith(app):
|
||||||
|
os.remove(hook_folder + action +'/'+ script)
|
||||||
|
|
||||||
|
|
||||||
def hook_callback(action, args=None):
|
def hook_callback(action, args=None):
|
||||||
|
|
Loading…
Reference in a new issue