[enh] Allow to show backup information at listing

This commit is contained in:
Jérôme Lebleu 2015-10-01 19:27:19 +02:00
parent 3bbe9ad7e2
commit e9a10e79fb
2 changed files with 33 additions and 5 deletions

View file

@ -625,6 +625,15 @@ backup:
api: GET /backup/archives api: GET /backup/archives
configuration: configuration:
lock: false 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() ### backup_info()
info: info:
@ -635,6 +644,10 @@ backup:
arguments: arguments:
name: name:
help: Name of the local backup archive help: Name of the local backup archive
-d:
full: --with-details
help: Show additional backup information
action: store_true
-H: -H:
full: --human-readable full: --human-readable
help: Print sizes in human readable format help: Print sizes in human readable format

View file

@ -31,6 +31,7 @@ import errno
import time import time
import tarfile import tarfile
import subprocess import subprocess
from collections import OrderedDict
from moulinette.core import MoulinetteError from moulinette.core import MoulinetteError
from moulinette.utils.log import getActionLogger 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') msignals.display(m18n.n('restore_complete'), 'success')
def backup_list(): def backup_list(with_info=False, human_readable=False):
""" """
List available local backup archives List available local backup archives
Keyword arguments:
with_info -- Show backup information for each archive
human_readable -- Print sizes in human readable format
""" """
result = [] result = []
@ -354,15 +359,22 @@ def backup_list():
result.append(name) result.append(name)
result.sort() 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 } 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 Get info about a local backup archive
Keyword arguments: Keyword arguments:
name -- Name of the local backup archive name -- Name of the local backup archive
with_details -- Show additional backup information
human_readable -- Print sizes in human readable format human_readable -- Print sizes in human readable format
""" """
@ -388,12 +400,15 @@ def backup_info(name, human_readable=False):
if human_readable: if human_readable:
size = binary_to_human(size) + 'B' size = binary_to_human(size) + 'B'
return { result = {
'path': archive_file, 'path': archive_file,
'created_at': time.strftime(m18n.n('format_datetime_short'), 'created_at': time.strftime(m18n.n('format_datetime_short'),
time.gmtime(info['created_at'])), time.gmtime(info['created_at'])),
'description': info['description'], 'description': info['description'],
'apps': info['apps'],
'hooks': info['hooks'],
'size': size, 'size': size,
} }
if with_details:
for d in ['apps', 'hooks']:
result[d] = info[d]
return result