Backups: show free disk space on upload+restore page

Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Michael Pimmer authored and James Valleroy committed 2018-11-17 09:00:36 -05:00
1 parent 8cc74bd203
commit d4d5c15566
4 files changed
+46 -19

No files matched your search

+20 -1
View File
@@ -25,8 +25,9 @@ from django.utils.translation import ugettext_lazy as _
from plinth import service as service_module
from plinth import action_utils, actions, cfg
from plinth.errors import PlinthError
from plinth.menu import main_menu
from plinth.utils import format_lazy
from plinth.utils import format_lazy, is_user_admin
from .manifest import backup
@@ -77,6 +78,24 @@ def get_disks():
return combined_list
def get_disk_info(mountpoint, request):
"""Get information about the free space of a drive"""
if not is_user_admin(request, cached=True):
raise PermissionError
disks = get_disks()
list_root = [disk for disk in disks if disk['mountpoint'] == mountpoint]
if not list_root:
raise PlinthError
percent_used = list_root[0]['percent_used']
free_bytes = list_root[0]['free']
free_gib = free_bytes / (1024**3)
return {
"percent_used": percent_used,
"free_bytes": free_bytes,
"free_gib": free_gib
}
def _get_disks_from_df():
"""Return the list of disks and free space available using 'df'."""
command = [
+10 -16
View File
@@ -30,10 +30,11 @@ from django.utils.translation import ugettext as _
from django.views.decorators.http import require_POST
from plinth import actions
from plinth.errors import PlinthError
from plinth.modules import storage
from plinth.utils import format_lazy, is_user_admin
from plinth.utils import format_lazy
from . import udisks2
from . import udisks2, get_disk_info
logger = logging.getLogger(__name__)
@@ -91,29 +92,22 @@ def expand_partition(request, device):
def warn_about_low_disk_space(request):
"""Warn about insufficient space on root partition."""
if not is_user_admin(request, cached=True):
return
disks = storage.get_disks()
list_root = [disk for disk in disks if disk['mountpoint'] == '/']
if not list_root:
try:
root_info = get_disk_info('/', request)
except (PlinthError, PermissionError):
logger.error('Error getting information about root partition.')
return
percent_used = list_root[0]['percent_used']
free_bytes = list_root[0]['free']
free_gib = free_bytes / (1024**3)
message = format_lazy(
# Translators: xgettext:no-python-format
_('Warning: Low space on system partition ({percent_used}% used, '
'{free_space} free).'),
percent_used=percent_used,
free_space=storage.format_bytes(free_bytes))
percent_used=root_info["percent_used"],
free_space=storage.format_bytes(root_info["free_bytes"]))
if percent_used > 90 or free_gib < 1:
if root_info["percent_used"] > 90 or root_info["free_gib"] < 1:
messages.error(request, message)
elif percent_used > 75 or free_gib < 2:
elif root_info["percent_used"] > 75 or root_info["free_gib"] < 2:
messages.warning(request, message)