disks: add low disk space warning to system and disks page

Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Johannes Keyser 2017-08-29 23:55:04 +02:00 committed by Sunil Mohan Adapa
parent 82475522f9
commit 3c4c770404
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
3 changed files with 24 additions and 12 deletions

View File

@ -19,13 +19,17 @@
Views for disks module. Views for disks module.
""" """
import logging
from django.contrib import messages from django.contrib import messages
from django.shortcuts import redirect from django.shortcuts import redirect
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.urls import reverse from django.urls import reverse
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from plinth.modules import disks as disks_module from plinth.modules import disks as disks_module
from plinth.utils import format_lazy
logger = logging.getLogger(__name__)
def index(request): def index(request):
@ -35,6 +39,8 @@ def index(request):
expandable_root_size = disks_module.is_expandable(root_device) expandable_root_size = disks_module.is_expandable(root_device)
expandable_root_size = _format_bytes(expandable_root_size) expandable_root_size = _format_bytes(expandable_root_size)
warn_about_low_disk_space(request)
return TemplateResponse(request, 'disks.html', return TemplateResponse(request, 'disks.html',
{'title': _('Disks'), {'title': _('Disks'),
'disks': disks, 'disks': disks,
@ -68,7 +74,7 @@ def expand_partition(request, device):
messages.success(request, _('Partition expanded successfully.')) messages.success(request, _('Partition expanded successfully.'))
def warn_about_insufficient_root_space(request): def warn_about_low_disk_space(request):
"""Warn about insufficient space on root partition.""" """Warn about insufficient space on root partition."""
disks = disks_module.get_disks() disks = disks_module.get_disks()
list_root = [disk for disk in disks if disk['mountpoint'] == '/'] list_root = [disk for disk in disks if disk['mountpoint'] == '/']
@ -80,18 +86,19 @@ def warn_about_insufficient_root_space(request):
free_str = _format_bytes(free_Bytes) free_str = _format_bytes(free_Bytes)
if perc_used < 0 or free_GiB < 0: if perc_used < 0 or free_GiB < 0:
# FIXME: Log read error. logger.exception('Error getting information about root partition.')
return return
msg_str = _('Warning: Low disk space on root partition ({percent_used}%' msg_str = format_lazy(
' used, {free_space} free). FIXME: Link to disk module.').format( _('Warning: Low space on system partition ({percent_used}% used, '
percent_used=perc_used, free_space=free_str) '{free_space} free). Check the Disks Configuration to resolve '
'this problem.'),
percent_used=perc_used, free_space=free_str)
# FIXME: Match with existing coloring in disk module. if perc_used > 90 or free_GiB < 1:
if perc_used > 90 or free_GiB < 3:
messages.error(request, msg_str) messages.error(request, msg_str)
elif perc_used > 80 or free_GiB < 2: elif perc_used > 75 or free_GiB < 2:
messages.warning(request, msg_str) messages.warning(request, msg_str)

View File

@ -29,6 +29,5 @@ urlpatterns = [
url(r'^$', views.index, name='index'), url(r'^$', views.index, name='index'),
url(r'^apps/$', TemplateView.as_view(template_name='apps.html'), url(r'^apps/$', TemplateView.as_view(template_name='apps.html'),
name='apps'), name='apps'),
url(r'^sys/$', TemplateView.as_view(template_name='system.html'), url(r'^sys/$', views.system_index, name='system'),
name='system'),
] ]

View File

@ -46,7 +46,7 @@ def index(request):
details_label = frontpage.shortcuts[selection]['label'] details_label = frontpage.shortcuts[selection]['label']
configure_url = frontpage.shortcuts[selection]['configure_url'] configure_url = frontpage.shortcuts[selection]['configure_url']
disk_views.warn_about_insufficient_root_space(request) disk_views.warn_about_low_disk_space(request)
return TemplateResponse(request, 'index.html', return TemplateResponse(request, 'index.html',
{'title': _('FreedomBox'), {'title': _('FreedomBox'),
@ -57,6 +57,12 @@ def index(request):
'configure_url': configure_url}) 'configure_url': configure_url})
def system_index(request):
"""Serve the system index page."""
disk_views.warn_about_low_disk_space(request)
return TemplateResponse(request, 'system.html')
class ServiceView(FormView): class ServiceView(FormView):
"""A generic view for configuring simple services.""" """A generic view for configuring simple services."""
service_id = None service_id = None