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:
|
for line in lines:
|
||||||
sources.write(re.sub(r''+ original_app_id +'', app_id, line))
|
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):
|
if 'hooks' in os.listdir(app_tmp_folder):
|
||||||
for hook in os.listdir(app_tmp_folder +'/hooks'):
|
for hook in os.listdir(app_tmp_folder +'/hooks'):
|
||||||
hook_add(app_id, app_tmp_folder +'/hooks/'+ hook)
|
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.makedirs(app_setting_path)
|
||||||
os.system('touch %s/settings.yml' % 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):
|
if 'hooks' in os.listdir(app_tmp_folder):
|
||||||
for file in os.listdir(app_tmp_folder +'/hooks'):
|
for file in os.listdir(app_tmp_folder +'/hooks'):
|
||||||
hook_add(app_id, app_tmp_folder +'/hooks/'+ file)
|
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
|
# TODO: Add a 'clean' argument to clean output directory
|
||||||
from yunohost.hook import hook_add
|
from yunohost.hook import hook_callback, hook_exec
|
||||||
from yunohost.hook import hook_callback
|
|
||||||
|
|
||||||
tmp_dir = None
|
tmp_dir = None
|
||||||
|
|
||||||
|
@ -117,6 +116,10 @@ def backup_create(name=None, description=None, output_directory=None,
|
||||||
else:
|
else:
|
||||||
os.system('chown -hR admin: %s' % tmp_dir)
|
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
|
# Initialize backup info
|
||||||
info = {
|
info = {
|
||||||
'description': description or '',
|
'description': description or '',
|
||||||
|
@ -124,7 +127,7 @@ def backup_create(name=None, description=None, output_directory=None,
|
||||||
'apps': {},
|
'apps': {},
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add apps backup hook
|
# Backup apps
|
||||||
if not ignore_apps:
|
if not ignore_apps:
|
||||||
from yunohost.app import app_info
|
from yunohost.app import app_info
|
||||||
|
|
||||||
|
@ -141,28 +144,28 @@ def backup_create(name=None, description=None, output_directory=None,
|
||||||
else:
|
else:
|
||||||
apps_filtered = apps_list
|
apps_filtered = apps_list
|
||||||
|
|
||||||
try:
|
# Run apps backup scripts
|
||||||
for app_id in apps_filtered:
|
for app_id in apps_filtered:
|
||||||
hook = '/etc/yunohost/apps/%s/scripts/backup' % app_id
|
script = '/etc/yunohost/apps/{:s}/scripts/backup'.format(app_id)
|
||||||
if os.path.isfile(hook):
|
if not os.path.isfile(script):
|
||||||
hook_add(app_id, hook)
|
logger.warning("backup script '%s' not found", script)
|
||||||
|
msignals.display(m18n.n('unbackup_app', app_id),
|
||||||
|
'warning')
|
||||||
|
continue
|
||||||
|
|
||||||
# Add app info
|
try:
|
||||||
i = app_info(app_id)
|
msignals.display(m18n.n('backup_running_app_script', app_id))
|
||||||
info['apps'][app_id] = {
|
hook_exec(script, args=[tmp_dir])
|
||||||
'version': i['version'],
|
except:
|
||||||
}
|
logger.exception("error while executing script '%s'", script)
|
||||||
else:
|
msignals.display(m18n.n('unbackup_app', app_id),
|
||||||
logger.warning("unable to find app's backup hook '%s'",
|
'error')
|
||||||
hook)
|
else:
|
||||||
msignals.display(m18n.n('unbackup_app', app_id),
|
# Add app info
|
||||||
'warning')
|
i = app_info(app_id)
|
||||||
except IOError as e:
|
info['apps'][app_id] = {
|
||||||
logger.info("unable to add apps backup hook: %s", str(e))
|
'version': i['version'],
|
||||||
|
}
|
||||||
# Run hooks
|
|
||||||
msignals.display(m18n.n('backup_running_hooks'))
|
|
||||||
hook_callback('backup', hooks, args=[tmp_dir])
|
|
||||||
|
|
||||||
# Create backup info file
|
# Create backup info file
|
||||||
with open("%s/info.json" % tmp_dir, 'w') as f:
|
with open("%s/info.json" % tmp_dir, 'w') as f:
|
||||||
|
@ -367,6 +370,7 @@ def backup_info(name):
|
||||||
info_file)
|
info_file)
|
||||||
raise MoulinetteError(errno.EIO, m18n.n('backup_invalid_archive'))
|
raise MoulinetteError(errno.EIO, m18n.n('backup_invalid_archive'))
|
||||||
|
|
||||||
|
# TODO: TAILLE!
|
||||||
return {
|
return {
|
||||||
'path': archive_file,
|
'path': archive_file,
|
||||||
'created_at': time.strftime(m18n.n('format_datetime_short'),
|
'created_at': time.strftime(m18n.n('format_datetime_short'),
|
||||||
|
|
|
@ -143,6 +143,7 @@
|
||||||
"backup_output_directory_forbidden" : "Forbidden output directory",
|
"backup_output_directory_forbidden" : "Forbidden output directory",
|
||||||
"backup_output_directory_not_empty" : "Output directory is not empty",
|
"backup_output_directory_not_empty" : "Output directory is not empty",
|
||||||
"backup_running_hooks" : "Running backup hooks...",
|
"backup_running_hooks" : "Running backup hooks...",
|
||||||
|
"backup_running_app_script" : "Running backup script of app '{:s}'...",
|
||||||
"backup_creating_archive" : "Creating the backup archive...",
|
"backup_creating_archive" : "Creating the backup archive...",
|
||||||
"backup_extracting_archive" : "Extracting the backup archive...",
|
"backup_extracting_archive" : "Extracting the backup archive...",
|
||||||
"backup_archive_open_failed" : "Unable to open the backup archive",
|
"backup_archive_open_failed" : "Unable to open the backup archive",
|
||||||
|
|
Loading…
Add table
Reference in a new issue