diff --git a/plinth/modules/backups/forms.py b/plinth/modules/backups/forms.py index 79aabd12f..60178e54f 100644 --- a/plinth/modules/backups/forms.py +++ b/plinth/modules/backups/forms.py @@ -15,7 +15,7 @@ from django.core.validators import (FileExtensionValidator, from django.utils.translation import ugettext from django.utils.translation import ugettext_lazy as _ -from plinth.modules.storage import get_disks +from plinth.modules.storage import get_mounts from plinth.utils import format_lazy from . import api, split_path @@ -158,7 +158,7 @@ def get_disk_choices(): if repository.storage_type == 'disk' ] choices = [] - for device in get_disks(): + for device in get_mounts(): if device['mount_point'] == '/': continue diff --git a/plinth/modules/samba/tests/test_views.py b/plinth/modules/samba/tests/test_views.py index 6a181ded7..2bf5ae490 100644 --- a/plinth/modules/samba/tests/test_views.py +++ b/plinth/modules/samba/tests/test_views.py @@ -88,11 +88,11 @@ def make_request(request, view, **kwargs): def test_samba_shares_view(rf): """Test that a share list has correct view data.""" - with patch('plinth.views.AppView.get_context_data', - return_value={'is_enabled': True}), patch( - 'plinth.modules.samba.get_users', - return_value=USERS), patch( - 'plinth.modules.storage.get_disks', return_value=DISKS): + with patch('plinth.views.AppView.get_context_data', return_value={ + 'is_enabled': True + }), patch('plinth.modules.samba.get_users', + return_value=USERS), patch('plinth.modules.storage.get_mounts', + return_value=DISKS): view = views.SambaAppView.as_view() response, _ = make_request(rf.get(''), view) diff --git a/plinth/modules/samba/views.py b/plinth/modules/samba/views.py index 942770364..3de708c44 100644 --- a/plinth/modules/samba/views.py +++ b/plinth/modules/samba/views.py @@ -28,7 +28,7 @@ class SambaAppView(views.AppView): def get_context_data(self, *args, **kwargs): """Return template context data.""" context = super().get_context_data(*args, **kwargs) - disks = storage.get_disks() + disks = storage.get_mounts() shares = samba.get_shares() for disk in disks: diff --git a/plinth/modules/storage/__init__.py b/plinth/modules/storage/__init__.py index b2d0e1949..b6d199539 100644 --- a/plinth/modules/storage/__init__.py +++ b/plinth/modules/storage/__init__.py @@ -75,7 +75,36 @@ def init(): def get_disks(): - """Returns list of disks by combining information from df and udisks.""" + """Returns list of disks and their free space. + + The primary source of information is UDisks' list of block devices. + Information from df is used for free space available. + + """ + disks_from_df = _get_disks_from_df() + disks = udisks2.get_disks() + for disk in disks: + disk['size'] = format_bytes(disk['size']) + + # Add info from df to the disks from udisks based on mount point. + for disk in disks: + for disk_from_df in disks_from_df: + if disk_from_df['mount_point'] in disk['mount_points']: + disk['mount_point'] = disk_from_df['mount_point'] + for key in ('percent_used', 'size', 'used', 'free', 'size_str', + 'used_str', 'free_str'): + disk[key] = disk_from_df[key] + + return sorted(disks, key=lambda disk: disk['device']) + + +def get_mounts(): + """Return list of mounts by combining information from df and UDisks. + + The primary source of information is the df command. Information from + UDisks is used for labels. + + """ disks = _get_disks_from_df() disks_from_udisks = udisks2.get_disks() for disk in disks_from_udisks: @@ -130,7 +159,7 @@ def get_filesystem_type(mount_point='/'): def get_disk_info(mount_point): """Get information about the free space of a drive""" disks = get_disks() - list_root = [disk for disk in disks if disk['mount_point'] == mount_point] + list_root = [disk for disk in disks if mount_point in disk['mount_points']] if not list_root: raise PlinthError('Mount point {} not found.'.format(mount_point)) @@ -147,8 +176,9 @@ def get_disk_info(mount_point): def get_root_device(disks): """Return the root partition's device from list of partitions.""" for disk in disks: - if disk['mount_point'] == '/': + if '/' in disk['mount_points']: return disk['device'] + return None diff --git a/plinth/modules/storage/forms.py b/plinth/modules/storage/forms.py index b825bc4b1..a5870a377 100644 --- a/plinth/modules/storage/forms.py +++ b/plinth/modules/storage/forms.py @@ -21,7 +21,7 @@ def get_available_samba_shares(): samba_shares = json.loads( actions.superuser_run('samba', ['get-shares'])) if samba_shares: - disks = storage.get_disks() + disks = storage.get_mounts() for share in samba_shares: for disk in disks: if share['mount_point'] == disk['mount_point']: diff --git a/plinth/modules/storage/templates/storage.html b/plinth/modules/storage/templates/storage.html index 91d693b77..e8776878a 100644 --- a/plinth/modules/storage/templates/storage.html +++ b/plinth/modules/storage/templates/storage.html @@ -35,7 +35,7 @@ {{ disk.device }} {{ disk.label|default_if_none:"" }} - {{ disk.mount_point }} + {{ disk.mount_points|join:"
" }} {{ disk.filesystem_type }}
diff --git a/plinth/modules/storage/udisks2.py b/plinth/modules/storage/udisks2.py index a91c2aded..70fd73eb4 100644 --- a/plinth/modules/storage/udisks2.py +++ b/plinth/modules/storage/udisks2.py @@ -143,13 +143,15 @@ def get_disks(): 'label': block.id_label, 'size': block.size, 'filesystem_type': block.id_type, - 'is_removable': not block.hint_system + 'is_removable': not block.hint_system, + 'mount_points': [], } try: file_system = Filesystem(object_) device['mount_points'] = file_system.mount_points except Exception: continue + devices.append(device) return devices