Struggling with getting USb mount point python

Sunday, July 6, 2014

I'm writing a python script that lists USB mass storage devices. I want to print out the manufacturer, the size of the device and where it's mounted. The usb mass storage devices are automatically mounted by the OS. I've got the manufacturer thing and device size working; But I'm struggling with getting the mount point. When I do df -h I get this:


FS:/dev/sda1

Size:980M

Used:0

Available:980M

used:0%

mounted on:/media/usb0


It's the mounted on, that i'm after at. This is the code I've already got:



def fetchExternals():
bus = dbus.SystemBus()
ud_manager_obj = bus.get_object("org.freedesktop.UDisks", "/org/freedesktop/UDisks")
ud_manager = dbus.Interface(ud_manager_obj, 'org.freedesktop.UDisks')

for dev in ud_manager.EnumerateDevices():
device_obj = bus.get_object("org.freedesktop.UDisks", dev)
device_props = dbus.Interface(device_obj, dbus.PROPERTIES_IFACE)
if device_props.Get('org.freedesktop.UDisks.Device', "DeviceIsRemovable"):
print device_props.Get('org.freedesktop.UDisks.Device', "DriveVendor")
print str(math.ceil(device_props.Get('org.freedesktop.UDisks.Device', "PartitionSize")/1048576.0)/1000)+' GB'


Can somebody tell me if it's possible to get the mountpoint for the partition residing on the device?







http://ift.tt/1mwQnq2