mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Add archive size to backup info and return info at creation
This commit is contained in:
parent
cf0af877d9
commit
89b6b79e60
3 changed files with 22 additions and 7 deletions
|
@ -635,6 +635,10 @@ backup:
|
||||||
arguments:
|
arguments:
|
||||||
name:
|
name:
|
||||||
help: Name of the local backup archive
|
help: Name of the local backup archive
|
||||||
|
-H:
|
||||||
|
full: --human-readable
|
||||||
|
help: Print sizes in human readable format
|
||||||
|
action: store_true
|
||||||
|
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
|
|
|
@ -213,6 +213,10 @@ def backup_create(name=None, description=None, output_directory=None,
|
||||||
|
|
||||||
msignals.display(m18n.n('backup_complete'), 'success')
|
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):
|
def backup_restore(name, hooks=[], apps=[], ignore_apps=False, force=False):
|
||||||
"""
|
"""
|
||||||
|
@ -350,14 +354,17 @@ def backup_list():
|
||||||
return { 'archives': result }
|
return { 'archives': result }
|
||||||
|
|
||||||
|
|
||||||
def backup_info(name):
|
def backup_info(name, 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
|
||||||
|
human_readable -- Print sizes in human readable format
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from yunohost.monitor import binary_to_human
|
||||||
|
|
||||||
archive_file = '%s/%s.tar.gz' % (archives_path, name)
|
archive_file = '%s/%s.tar.gz' % (archives_path, name)
|
||||||
if not os.path.isfile(archive_file):
|
if not os.path.isfile(archive_file):
|
||||||
logger.error("no local backup archive found at '%s'", archive_file)
|
logger.error("no local backup archive found at '%s'", archive_file)
|
||||||
|
@ -374,7 +381,10 @@ def backup_info(name):
|
||||||
info_file)
|
info_file)
|
||||||
raise MoulinetteError(errno.EIO, m18n.n('backup_invalid_archive'))
|
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 {
|
return {
|
||||||
'path': archive_file,
|
'path': archive_file,
|
||||||
'created_at': time.strftime(m18n.n('format_datetime_short'),
|
'created_at': time.strftime(m18n.n('format_datetime_short'),
|
||||||
|
@ -382,4 +392,5 @@ def backup_info(name):
|
||||||
'description': info['description'],
|
'description': info['description'],
|
||||||
'apps': info['apps'],
|
'apps': info['apps'],
|
||||||
'hooks': info['hooks'],
|
'hooks': info['hooks'],
|
||||||
|
'size': size,
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,7 @@ def monitor_disk(units=None, mountpoint=None, human_readable=False):
|
||||||
else:
|
else:
|
||||||
if human_readable:
|
if human_readable:
|
||||||
for i in ['used', 'avail', 'size']:
|
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)
|
_set(dname, d)
|
||||||
for dname in devices_names:
|
for dname in devices_names:
|
||||||
_set(dname, 'not-available')
|
_set(dname, 'not-available')
|
||||||
|
@ -201,7 +201,7 @@ def monitor_network(units=None, human_readable=False):
|
||||||
if human_readable:
|
if human_readable:
|
||||||
for k in i.keys():
|
for k in i.keys():
|
||||||
if k != 'time_since_update':
|
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
|
result[u][iname] = i
|
||||||
elif u == 'infos':
|
elif u == 'infos':
|
||||||
try:
|
try:
|
||||||
|
@ -261,10 +261,10 @@ def monitor_system(units=None, human_readable=False):
|
||||||
if human_readable:
|
if human_readable:
|
||||||
for i in ram.keys():
|
for i in ram.keys():
|
||||||
if i != 'percent':
|
if i != 'percent':
|
||||||
ram[i] = _binary_to_human(ram[i]) + 'B'
|
ram[i] = binary_to_human(ram[i]) + 'B'
|
||||||
for i in swap.keys():
|
for i in swap.keys():
|
||||||
if i != 'percent':
|
if i != 'percent':
|
||||||
swap[i] = _binary_to_human(swap[i]) + 'B'
|
swap[i] = binary_to_human(swap[i]) + 'B'
|
||||||
result[u] = {
|
result[u] = {
|
||||||
'ram': ram,
|
'ram': ram,
|
||||||
'swap': swap
|
'swap': swap
|
||||||
|
@ -510,7 +510,7 @@ def _extract_inet(string, skip_netmask=False, skip_loopback=True):
|
||||||
return result
|
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
|
Convert bytes or bits into human readable format with binary prefix
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue