Skip to content

Instantly share code, notes, and snippets.

@mbusb
Created April 30, 2014 06:02
Show Gist options
  • Save mbusb/f674183c169e431c356e to your computer and use it in GitHub Desktop.
Save mbusb/f674183c169e431c356e to your computer and use it in GitHub Desktop.
#!/usr/bin/python2.7
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
import dbus
import re
bus = dbus.SystemBus()
devs = bus.get_object('org.freedesktop.UDisks2',
'/org/freedesktop/UDisks2/block_devices')
xml = devs.Introspect(dbus_interface='org.freedesktop.DBus.Introspectable')
for dev in re.finditer(r'name=[\'"](.+?)[\'"]', type(u'')(xml)):
bd = bus.get_object('org.freedesktop.UDisks2',
'/org/freedesktop/UDisks2/block_devices/%s'%dev.group(1))
try:
device = bd.Get('org.freedesktop.UDisks2.Block', 'Device',
dbus_interface='org.freedesktop.DBus.Properties')
device = bytearray(device).replace(b'\x00', b'').decode('utf-8')
print device
#print bd
except:
print "No Device Found..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment