mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-02-18 08:33:41 +00:00
udiskie: Import glib and udisks only inside methods
The module can be imported even before gir1.2-udisks-2.0 is installed. Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
15345aeb47
commit
c733339719
@ -23,12 +23,10 @@ from django.utils.translation import ugettext as _
|
||||
from plinth import utils
|
||||
from plinth.modules.storage import format_bytes
|
||||
|
||||
glib = utils.import_from_gi('GLib', '2.0')
|
||||
udisks = utils.import_from_gi('UDisks', '2.0')
|
||||
|
||||
|
||||
def _get_options():
|
||||
"""Return the common options used for udisks2 operations."""
|
||||
glib = utils.import_from_gi('GLib', '2.0')
|
||||
options = glib.Variant(
|
||||
'a{sv}', {'auth.no_user_interaction': glib.Variant('b', True)})
|
||||
return options
|
||||
@ -36,6 +34,7 @@ def _get_options():
|
||||
|
||||
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()
|
||||
|
||||
@ -76,6 +75,7 @@ def eject_drive_of_device(device_path):
|
||||
|
||||
Return the details (model, vendor) of drives ejected.
|
||||
"""
|
||||
udisks = utils.import_from_gi('UDisks', '2.0')
|
||||
client = udisks.Client.new_sync()
|
||||
object_manager = client.get_object_manager()
|
||||
|
||||
@ -120,6 +120,7 @@ def umount_filesystem(filesystem):
|
||||
|
||||
def umount_all_filesystems_of_drive(drive_object_path):
|
||||
"""Unmount all filesystems on block devices of a drive."""
|
||||
udisks = utils.import_from_gi('UDisks', '2.0')
|
||||
client = udisks.Client.new_sync()
|
||||
object_manager = client.get_object_manager()
|
||||
|
||||
@ -133,6 +134,7 @@ def umount_all_filesystems_of_drive(drive_object_path):
|
||||
|
||||
def get_error_message(error):
|
||||
"""Return an error message given an exception."""
|
||||
udisks = utils.import_from_gi('UDisks', '2.0')
|
||||
if error.matches(udisks.Error.quark(), udisks.Error.FAILED):
|
||||
message = _('The operation failed.')
|
||||
elif error.matches(udisks.Error.quark(), udisks.Error.CANCELLED):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user