Skip to content

Instantly share code, notes, and snippets.

@alyssonbruno
Created July 3, 2012 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alyssonbruno/3037221 to your computer and use it in GitHub Desktop.
Save alyssonbruno/3037221 to your computer and use it in GitHub Desktop.
Mount and Unmount UDisks Device example
#http://hal.freedesktop.org/docs/udisks/Device.html
def mount(device, fs):
"""
>>> mount('/dev/sdb1','ext3')
/media/pendrive
>>> mount('/dev/sdc2','ext2')
''
"""
res = ''
_bus = dbus.SystemBus()
_proxy = _bus.get_object('org.freedesktop.UDisks','/org/freedesktop/UDisks')
_iface = dbus.Interface(_proxy, 'org.freedesktop.UDisks')
for _dev in _iface.EnumerateDevices():
_dev_obj = _bus.get_object('org.freedesktop.UDisks', _dev)
_dev_prop = dbus.Interface(_dev_obj, 'org.freedesktop.DBus.Properties')
if _dev_prop.Get('','DeviceFile')==device:
_idev = dbus.Interface(_dev_obj, 'org.freedesktop.DBus.UDisks.Device')
res = _idev.get_dbus_method('FilesystemMount', dbus_interface='org.freedesktop.UDisks.Device')(fs,[])
return res
def unmount(device):
"""
>>> unmount('/dev/sdb1')
"""
_bus = dbus.SystemBus()
_proxy = _bus.get_object('org.freedesktop.UDisks','/org/freedesktop/UDisks')
_iface = dbus.Interface(_proxy, 'org.freedesktop.UDisks')
for _dev in _iface.EnumerateDevices():
_dev_obj = _bus.get_object('org.freedesktop.UDisks', _dev)
_dev_prop = dbus.Interface(_dev_obj, 'org.freedesktop.DBus.Properties')
if _dev_prop.Get('','DeviceFile')==device:
_idev = dbus.Interface(_dev_obj, 'org.freedesktop.DBus.UDisks.Device')
_idev.get_dbus_method('FilesystemUnmount', dbus_interface='org.freedesktop.UDisks.Device')([])
@mbusb
Copy link

mbusb commented Apr 14, 2016

How about implementing the above functions in udisks2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment