Mind Bending

Python Logo

Recently I received some requests asking is USBManager will someday support DeviceKit/UDev, since HAL is officially deprecated. After some researches I retook this application development.

During the research I found out some mismatching informations and a lack of examples, so I decided to post some informations about Python development with DeviceKit/UDev and DBus. I’ll cover essentially the USB storage devices issue.

Some months ago, I made a research about Python and DeviceKit and I ran into this blog post: Accessing DeviceKit with DBus and Python. I made some tests and the code worked properly. Then I wrote some more lines and leaved there for some months. Later, after a long time (and a distribution update) I retook the code to work on USBManager and noticed that it doesn’t work anymore:

>>> import dbus
>>>
>>> bus = dbus.SystemBus()
>>>
>>> proxy = bus.get_object("org.freedesktop.DeviceKit.Disks", "/org/freedesktop/DeviceKit/Disks")
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 244, in get_object
follow_name_owner_changes=follow_name_owner_changes)
File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 241, in __init__
self._named_service = conn.activate_name_owner(bus_name)
File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 183, in activate_name_owner
self.start_service_by_name(bus_name)
File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 281, in start_service_by_name
'su', (bus_name, flags)))
File "/usr/lib/pymodules/python2.6/dbus/connection.py", line 620, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.DeviceKit.Disks was not provided by any .service files
>>>

I checked the path that has some DBus configuration files and noticed that that service doesn’t exist:

$ ls /etc/dbus-1/system.d/ | grep freedesktop
org.freedesktop.ModemManager.conf
org.freedesktop.PolicyKit1.conf
org.freedesktop.RealtimeKit1.conf
org.freedesktop.SystemToolsBackends.conf
org.freedesktop.UDisks.conf
org.freedesktop.UPower.conf

Accordingly to the UDisks 1.0.0 announcement the System Bus Name org.freedesktop.DeviceKit.Disks was replaced by org.freedesktop.UDisks. With this minor change I made my way to enumerate all the storage devices connected to my computer:

>>> import dbus
>>>
>>> bus = dbus.SystemBus()
>>> proxy = bus.get_object("org.freedesktop.UDisks", "/org/freedesktop/UDisks")
>>> iface = dbus.Interface(proxy, "org.freedesktop.UDisks")
>>> print iface.EnumerateDevices()
dbus.Array([dbus.ObjectPath('/org/freedesktop/UDisks/devices/fd0'),
dbus.ObjectPath('/org/freedesktop/UDisks/devices/sdc'),
dbus.ObjectPath('/org/freedesktop/UDisks/devices/sdb'),
dbus.ObjectPath('/org/freedesktop/UDisks/devices/sr0'),
dbus.ObjectPath('/org/freedesktop/UDisks/devices/sda1'),
dbus.ObjectPath('/org/freedesktop/UDisks/devices/sda2'),
dbus.ObjectPath('/org/freedesktop/UDisks/devices/sdb1'),
dbus.ObjectPath('/org/freedesktop/UDisks/devices/sda'),
dbus.ObjectPath('/org/freedesktop/UDisks/devices/sdb2'),
dbus.ObjectPath('/org/freedesktop/UDisks/devices/sdc1'),
dbus.ObjectPath('/org/freedesktop/UDisks/devices/sdb3')],
signature=dbus.Signature('o'))
>>>
>>> for i in iface.EnumerateDevices(): print i
...
/org/freedesktop/UDisks/devices/fd0
/org/freedesktop/UDisks/devices/sdc
/org/freedesktop/UDisks/devices/sdb
/org/freedesktop/UDisks/devices/sr0
/org/freedesktop/UDisks/devices/sda1
/org/freedesktop/UDisks/devices/sda2
/org/freedesktop/UDisks/devices/sdb1
/org/freedesktop/UDisks/devices/sda
/org/freedesktop/UDisks/devices/sdb2
/org/freedesktop/UDisks/devices/sdc1
/org/freedesktop/UDisks/devices/sdb3
>>>

Thats a good start! In a future post I’ll show how to list some devices properties. Until then…

Magnun

Magnun

Graduated in Telecommunication Engineering, but currently working with GNU/Linux infrastructure and in the spare time I'm an Open Source programmer (Python and C), a drawer and author in the Mind Bending Blog.


Comments

comments powered by Disqus