From d1cb0b0d80569aac7be7d6fd5d57744c2252fb14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Tue, 4 Nov 2014 14:11:18 +0100 Subject: [PATCH] [enh] Add basic 'list' and 'info' actions to the backup --- actionsmap/yunohost.yml | 17 +++++++++++++++++ backup.py | 42 +++++++++++++++++++++++++++++++++++++++++ locales/en.json | 5 ++++- locales/fr.json | 3 ++- 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/actionsmap/yunohost.yml b/actionsmap/yunohost.yml index a4e579425..cba6f095a 100644 --- a/actionsmap/yunohost.yml +++ b/actionsmap/yunohost.yml @@ -579,6 +579,23 @@ backup: path: help: Path of the restauration package + ### backup_list() + list: + action_help: List available local backup archives + api: GET /backup/archives + configuration: + lock: false + + ### backup_info() + info: + action_help: Show info about a local backup archive + api: GET /backup/archives/ + configuration: + lock: false + arguments: + name: + help: Name of the local backup archive + ############################# # Monitor # diff --git a/backup.py b/backup.py index a8db4fb8b..0d8285bfd 100644 --- a/backup.py +++ b/backup.py @@ -168,3 +168,45 @@ def backup_restore(path): msignals.display(m18n.n('restore_complete'), 'success') +def backup_list(): + """ + List available local backup archives + + """ + result = [] + + try: + # Retrieve local archives + archives = os.listdir(archives_path) + except IOError as e: + logging.info("unable to iterate over local archives: %s", str(e)) + else: + # Iterate over local archives + for f in archives: + try: + name = f[:f.rindex('.tar.gz')] + except ValueError: + continue + result.append(name) + + return { 'archives': result } + +def backup_info(name): + """ + Get info about a local backup archive + + Keyword arguments: + name -- Name of the local backup archive + + """ + archive_file = '%s/%s.tar.gz' % (archives_path, name) + if not os.path.isfile(archive_file): + logger.error("no local backup archive found at '%s'", archive_file) + raise MoulinetteError(errno.EIO, m18n.n('backup_archive_name_unknown')) + + return { + 'path': archive_file, + # TODO: Retrieve created_at from the info file + 'created_at': time.strftime(m18n.n('format_datetime_short'), + time.gmtime(int(name))), + } diff --git a/locales/en.json b/locales/en.json index 3c54b87aa..ff553847f 100644 --- a/locales/en.json +++ b/locales/en.json @@ -131,6 +131,7 @@ "backup_running_hooks" : "Running backup hooks...", "backup_creating_archive" : "Creating the backup archive...", "backup_archive_open_failed" : "Unable to open the backup archive", + "backup_archive_name_unknown" : "Unknown local backup archive name", "backup_complete" : "Backup complete", "invalid_restore_package" : "Invalid restore package", "restore_complete" : "Restore complete", @@ -168,6 +169,8 @@ "pattern_password" : "Must be at least 3 characters long", "pattern_domain" : "Must be a valid domain name (e.g. my-domain.org)", "pattern_listname" : "Must be alphanumeric and underscore characters only", - "pattern_port" : "Must be a valid port number (i.e. 0-65535)" + "pattern_port" : "Must be a valid port number (i.e. 0-65535)", + + "format_datetime_short" : "%m/%d/%Y %I:%M %p" } diff --git a/locales/fr.json b/locales/fr.json index a913951b3..e922c79b3 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -162,6 +162,7 @@ "pattern_password" : "Doit être composé d'au moins 3 caractères", "pattern_domain" : "Doit être un nom de domaine valide (ex : mon-domaine.org)", "pattern_listname" : "Doit être composé uniquement de caractères alphanumérique et de tiret bas", - "pattern_port" : "Doit être un numéro de port valide (0-65535)" + "pattern_port" : "Doit être un numéro de port valide (0-65535)", + "format_datetime_short" : "%d/%m/%Y %H:%M" }