[enh] Add archive size to backup info and return info at creation

This commit is contained in:
Jérôme Lebleu 2015-10-01 03:06:32 +02:00
parent cf0af877d9
commit 89b6b79e60
3 changed files with 22 additions and 7 deletions

View file

@ -635,6 +635,10 @@ backup:
arguments:
name:
help: Name of the local backup archive
-H:
full: --human-readable
help: Print sizes in human readable format
action: store_true
#############################

View file

@ -213,6 +213,10 @@ def backup_create(name=None, description=None, output_directory=None,
msignals.display(m18n.n('backup_complete'), 'success')
# Return backup info
info['name'] = name
return { 'archive': info }
def backup_restore(name, hooks=[], apps=[], ignore_apps=False, force=False):
"""
@ -350,14 +354,17 @@ def backup_list():
return { 'archives': result }
def backup_info(name):
def backup_info(name, human_readable=False):
"""
Get info about a local backup archive
Keyword arguments:
name -- Name of the local backup archive
human_readable -- Print sizes in human readable format
"""
from yunohost.monitor import binary_to_human
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)
@ -374,7 +381,10 @@ def backup_info(name):
info_file)
raise MoulinetteError(errno.EIO, m18n.n('backup_invalid_archive'))
# TODO: TAILLE!
size = os.path.getsize(archive_file)
if human_readable:
size = binary_to_human(size) + 'B'
return {
'path': archive_file,
'created_at': time.strftime(m18n.n('format_datetime_short'),
@ -382,4 +392,5 @@ def backup_info(name):
'description': info['description'],
'apps': info['apps'],
'hooks': info['hooks'],
'size': size,
}

View file

@ -130,7 +130,7 @@ def monitor_disk(units=None, mountpoint=None, human_readable=False):
else:
if human_readable:
for i in ['used', 'avail', 'size']:
d[i] = _binary_to_human(d[i]) + 'B'
d[i] = binary_to_human(d[i]) + 'B'
_set(dname, d)
for dname in devices_names:
_set(dname, 'not-available')
@ -201,7 +201,7 @@ def monitor_network(units=None, human_readable=False):
if human_readable:
for k in i.keys():
if k != 'time_since_update':
i[k] = _binary_to_human(i[k]) + 'B'
i[k] = binary_to_human(i[k]) + 'B'
result[u][iname] = i
elif u == 'infos':
try:
@ -261,10 +261,10 @@ def monitor_system(units=None, human_readable=False):
if human_readable:
for i in ram.keys():
if i != 'percent':
ram[i] = _binary_to_human(ram[i]) + 'B'
ram[i] = binary_to_human(ram[i]) + 'B'
for i in swap.keys():
if i != 'percent':
swap[i] = _binary_to_human(swap[i]) + 'B'
swap[i] = binary_to_human(swap[i]) + 'B'
result[u] = {
'ram': ram,
'swap': swap
@ -510,7 +510,7 @@ def _extract_inet(string, skip_netmask=False, skip_loopback=True):
return result
def _binary_to_human(n, customary=False):
def binary_to_human(n, customary=False):
"""
Convert bytes or bits into human readable format with binary prefix