From e9a10e79fb9356ddc20b6cc48bf47005efc47285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Thu, 1 Oct 2015 19:27:19 +0200 Subject: [PATCH] [enh] Allow to show backup information at listing --- data/actionsmap/yunohost.yml | 13 +++++++++++++ lib/yunohost/backup.py | 25 ++++++++++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index 69a3cb29..ca539090 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -625,6 +625,15 @@ backup: api: GET /backup/archives configuration: lock: false + arguments: + -i: + full: --with-info + help: Show backup information for each archive + action: store_true + -H: + full: --human-readable + help: Print sizes in human readable format + action: store_true ### backup_info() info: @@ -635,6 +644,10 @@ backup: arguments: name: help: Name of the local backup archive + -d: + full: --with-details + help: Show additional backup information + action: store_true -H: full: --human-readable help: Print sizes in human readable format diff --git a/lib/yunohost/backup.py b/lib/yunohost/backup.py index 5e56f543..703f4a28 100644 --- a/lib/yunohost/backup.py +++ b/lib/yunohost/backup.py @@ -31,6 +31,7 @@ import errno import time import tarfile import subprocess +from collections import OrderedDict from moulinette.core import MoulinetteError from moulinette.utils.log import getActionLogger @@ -332,10 +333,14 @@ def backup_restore(name, hooks=[], apps=[], ignore_apps=False, force=False): msignals.display(m18n.n('restore_complete'), 'success') -def backup_list(): +def backup_list(with_info=False, human_readable=False): """ List available local backup archives + Keyword arguments: + with_info -- Show backup information for each archive + human_readable -- Print sizes in human readable format + """ result = [] @@ -354,15 +359,22 @@ def backup_list(): result.append(name) result.sort() + if result and with_info: + d = OrderedDict() + for a in result: + d[a] = backup_info(a, human_readable=human_readable) + result = d + return { 'archives': result } -def backup_info(name, human_readable=False): +def backup_info(name, with_details=False, human_readable=False): """ Get info about a local backup archive Keyword arguments: name -- Name of the local backup archive + with_details -- Show additional backup information human_readable -- Print sizes in human readable format """ @@ -388,12 +400,15 @@ def backup_info(name, human_readable=False): if human_readable: size = binary_to_human(size) + 'B' - return { + result = { 'path': archive_file, 'created_at': time.strftime(m18n.n('format_datetime_short'), time.gmtime(info['created_at'])), 'description': info['description'], - 'apps': info['apps'], - 'hooks': info['hooks'], 'size': size, } + + if with_details: + for d in ['apps', 'hooks']: + result[d] = info[d] + return result