How do I get the list of available DBus interface properties?
I am writing a script that would be tracking specific type of usb devices connections. A way to distinguish the connections to be tracked from all usb connections I guess is to check the properties of signals' interfaces DBus is sending on a usb connection. I'd like to get the list of all such properties to chose the relevant.
My code is:
import sys
import dbus
from dbus.mainloop.glib import DBusGMainLoop
import gobject
def deviceAdded(udi):
device = bus.get_object("org.freedesktop.Hal", udi)
device_if = dbus.Interface(device, 'org.freedesktop.Hal.Device')
if device_if.GetPropertyString('info.subsystem') == 'usb_device':
#
# Properties can be accesed like this:
# vendor_id = device_if.GetPropertyInteger('usb_device.vendor_id')
#
# how to get the list of all properties?
#
# do something
def deviceRemoved(udi):
# do something
pass
if __name__ == "__main__":
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
bus.add_signal_receiver(
deviceAdded,
'DeviceAdded',
'org.freedesktop.Hal.Manager',
'org.freedesktop.Hal',
'/org/freedesktop/Hal/Manager')
bus.add_signal_receiver(
deviceRemoved,
'DeviceRemoved',
'org.freedesktop.Hal.Manager',
'org.freedesktop.Hal',
'/org/freedesktop/Hal/Manager')
loop = gobject.MainLoop()
try:
loop.run()
except KeyboardInterrupt:
print "usb-device-tracker: keyboad interrupt received, shutting down"
loop.quit()
sys.exit(0)
In general, you can use the GetAll
method on the org.freedesktop.DBus.Properties
interface.
First of all, check hal documentation and sources, they are always your friend.
import dbus
bus = dbus.SystemBus()
dev = bus.get_object("org.freedesktop.Hal", u'/org/freedesktop/Hal/devices/computer_logicaldev_input')
iface = dbus.Interface(dev, 'org.freedesktop.Hal.Device')
props = iface.GetAllProperties()
print "\n".join(("%s: %s" % (k, props[k]) for k in props))
As a last resort you can always find properties you are interested in with 'lshal' command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With