diff --git a/plinth/modules/udiskie/__init__.py b/plinth/modules/udiskie/__init__.py index 51e78c113..f506d8a8b 100644 --- a/plinth/modules/udiskie/__init__.py +++ b/plinth/modules/udiskie/__init__.py @@ -22,9 +22,7 @@ from django.utils.translation import ugettext_lazy as _ from plinth import action_utils, actions from plinth import service as service_module -from plinth import utils from plinth.menu import main_menu -from plinth.modules.storage import format_bytes version = 1 @@ -90,49 +88,3 @@ def enable(): def disable(): """Disable the module.""" actions.superuser_run('udiskie', ['disable']) - - -def list_devices(): - """List devices that can be ejected.""" - udisks = utils.import_from_gi('UDisks', '2.0') - - client = udisks.Client.new_sync() - object_manager = client.get_object_manager() - - block = None - devices = [] - for obj in object_manager.get_objects(): - if not obj.get_block(): - continue - - block = obj.get_block() - if block.props.id_usage != 'filesystem' or \ - block.props.hint_system or \ - block.props.read_only: - continue - - device_name = block.props.device - if not device_name: - continue - - device = { - 'device': block.props.device, - 'label': block.props.id_label, - 'size': format_bytes(block.props.size), - 'filesystem_type': block.props.id_type - } - - try: - drive = client.get_drive_for_block(block) - device['ejectable'] = drive.props.id_type - except Exception: - pass - - try: - device['mount_points'] = obj.get_filesystem().props.mount_points - except Exception: - pass - - devices.append(device) - - return devices diff --git a/plinth/modules/udiskie/udisks2.py b/plinth/modules/udiskie/udisks2.py new file mode 100644 index 000000000..32da61ebe --- /dev/null +++ b/plinth/modules/udiskie/udisks2.py @@ -0,0 +1,68 @@ +# +# This file is part of FreedomBox. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +""" +Library for interacting with udisks2 D-Bus service. +""" + +from plinth import utils +from plinth.modules.storage import format_bytes + + +def list_devices(): + """List devices that can be ejected.""" + udisks = utils.import_from_gi('UDisks', '2.0') + + client = udisks.Client.new_sync() + object_manager = client.get_object_manager() + + block = None + devices = [] + for obj in object_manager.get_objects(): + if not obj.get_block(): + continue + + block = obj.get_block() + if block.props.id_usage != 'filesystem' or \ + block.props.hint_system or \ + block.props.read_only: + continue + + device_name = block.props.device + if not device_name: + continue + + device = { + 'device': block.props.device, + 'label': block.props.id_label, + 'size': format_bytes(block.props.size), + 'filesystem_type': block.props.id_type + } + + try: + drive = client.get_drive_for_block(block) + device['ejectable'] = drive.props.id_type + except Exception: + pass + + try: + device['mount_points'] = obj.get_filesystem().props.mount_points + except Exception: + pass + + devices.append(device) + + return devices diff --git a/plinth/modules/udiskie/views.py b/plinth/modules/udiskie/views.py index f493498ad..42bf11474 100644 --- a/plinth/modules/udiskie/views.py +++ b/plinth/modules/udiskie/views.py @@ -18,9 +18,10 @@ Views for udiskie module. """ -from plinth.modules import udiskie from plinth.views import ServiceView +from . import udisks2 + class UdiskieView(ServiceView): """View to show devices.""" @@ -29,5 +30,5 @@ class UdiskieView(ServiceView): def get_context_data(self, **kwargs): """Return the context data rendering the template.""" context = super().get_context_data(**kwargs) - context['devices'] = udiskie.list_devices() + context['devices'] = udisks2.list_devices() return context