DBus interface properties

11,299

Solution 1

In general, you can use the GetAll method on the org.freedesktop.DBus.Properties interface.

Solution 2

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.

Share:
11,299
S. Plekhanov
Author by

S. Plekhanov

Updated on June 19, 2022

Comments

  • S. Plekhanov
    S. Plekhanov almost 2 years

    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)