mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] Do not process app backup script as hook
This commit is contained in:
parent
3fe92d81f7
commit
4c37d8f273
3 changed files with 33 additions and 26 deletions
|
@ -351,7 +351,8 @@ def app_upgrade(auth, app=[], url=None, file=None):
|
|||
for line in lines:
|
||||
sources.write(re.sub(r''+ original_app_id +'', app_id, line))
|
||||
|
||||
# Add hooks
|
||||
# Clean hooks and add new ones
|
||||
hook_remove(app_id)
|
||||
if 'hooks' in os.listdir(app_tmp_folder):
|
||||
for hook in os.listdir(app_tmp_folder +'/hooks'):
|
||||
hook_add(app_id, app_tmp_folder +'/hooks/'+ hook)
|
||||
|
@ -451,7 +452,8 @@ def app_install(auth, app, label=None, args=None):
|
|||
os.makedirs(app_setting_path)
|
||||
os.system('touch %s/settings.yml' % app_setting_path)
|
||||
|
||||
# Add hooks
|
||||
# Clean hooks and add new ones
|
||||
hook_remove(app_id)
|
||||
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)
|
||||
|
|
|
@ -57,8 +57,7 @@ def backup_create(name=None, description=None, output_directory=None,
|
|||
|
||||
"""
|
||||
# TODO: Add a 'clean' argument to clean output directory
|
||||
from yunohost.hook import hook_add
|
||||
from yunohost.hook import hook_callback
|
||||
from yunohost.hook import hook_callback, hook_exec
|
||||
|
||||
tmp_dir = None
|
||||
|
||||
|
@ -117,6 +116,10 @@ def backup_create(name=None, description=None, output_directory=None,
|
|||
else:
|
||||
os.system('chown -hR admin: %s' % tmp_dir)
|
||||
|
||||
# Run system hooks
|
||||
msignals.display(m18n.n('backup_running_hooks'))
|
||||
hook_callback('backup', hooks, args=[tmp_dir])
|
||||
|
||||
# Initialize backup info
|
||||
info = {
|
||||
'description': description or '',
|
||||
|
@ -124,7 +127,7 @@ def backup_create(name=None, description=None, output_directory=None,
|
|||
'apps': {},
|
||||
}
|
||||
|
||||
# Add apps backup hook
|
||||
# Backup apps
|
||||
if not ignore_apps:
|
||||
from yunohost.app import app_info
|
||||
|
||||
|
@ -141,28 +144,28 @@ def backup_create(name=None, description=None, output_directory=None,
|
|||
else:
|
||||
apps_filtered = apps_list
|
||||
|
||||
try:
|
||||
for app_id in apps_filtered:
|
||||
hook = '/etc/yunohost/apps/%s/scripts/backup' % app_id
|
||||
if os.path.isfile(hook):
|
||||
hook_add(app_id, hook)
|
||||
# Run apps backup scripts
|
||||
for app_id in apps_filtered:
|
||||
script = '/etc/yunohost/apps/{:s}/scripts/backup'.format(app_id)
|
||||
if not os.path.isfile(script):
|
||||
logger.warning("backup script '%s' not found", script)
|
||||
msignals.display(m18n.n('unbackup_app', app_id),
|
||||
'warning')
|
||||
continue
|
||||
|
||||
# Add app info
|
||||
i = app_info(app_id)
|
||||
info['apps'][app_id] = {
|
||||
'version': i['version'],
|
||||
}
|
||||
else:
|
||||
logger.warning("unable to find app's backup hook '%s'",
|
||||
hook)
|
||||
msignals.display(m18n.n('unbackup_app', app_id),
|
||||
'warning')
|
||||
except IOError as e:
|
||||
logger.info("unable to add apps backup hook: %s", str(e))
|
||||
|
||||
# Run hooks
|
||||
msignals.display(m18n.n('backup_running_hooks'))
|
||||
hook_callback('backup', hooks, args=[tmp_dir])
|
||||
try:
|
||||
msignals.display(m18n.n('backup_running_app_script', app_id))
|
||||
hook_exec(script, args=[tmp_dir])
|
||||
except:
|
||||
logger.exception("error while executing script '%s'", script)
|
||||
msignals.display(m18n.n('unbackup_app', app_id),
|
||||
'error')
|
||||
else:
|
||||
# Add app info
|
||||
i = app_info(app_id)
|
||||
info['apps'][app_id] = {
|
||||
'version': i['version'],
|
||||
}
|
||||
|
||||
# Create backup info file
|
||||
with open("%s/info.json" % tmp_dir, 'w') as f:
|
||||
|
@ -367,6 +370,7 @@ def backup_info(name):
|
|||
info_file)
|
||||
raise MoulinetteError(errno.EIO, m18n.n('backup_invalid_archive'))
|
||||
|
||||
# TODO: TAILLE!
|
||||
return {
|
||||
'path': archive_file,
|
||||
'created_at': time.strftime(m18n.n('format_datetime_short'),
|
||||
|
|
|
@ -143,6 +143,7 @@
|
|||
"backup_output_directory_forbidden" : "Forbidden output directory",
|
||||
"backup_output_directory_not_empty" : "Output directory is not empty",
|
||||
"backup_running_hooks" : "Running backup hooks...",
|
||||
"backup_running_app_script" : "Running backup script of app '{:s}'...",
|
||||
"backup_creating_archive" : "Creating the backup archive...",
|
||||
"backup_extracting_archive" : "Extracting the backup archive...",
|
||||
"backup_archive_open_failed" : "Unable to open the backup archive",
|
||||
|
|
Loading…
Add table
Reference in a new issue