diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index bbeba80d3..69a3cb291 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -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 ############################# diff --git a/lib/yunohost/backup.py b/lib/yunohost/backup.py index 81693ca70..b63b2c864 100644 --- a/lib/yunohost/backup.py +++ b/lib/yunohost/backup.py @@ -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, } diff --git a/lib/yunohost/monitor.py b/lib/yunohost/monitor.py index 541e0892e..9db5e3234 100644 --- a/lib/yunohost/monitor.py +++ b/lib/yunohost/monitor.py @@ -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