Writing a HAL/DBUS Python program

Joe Shaw joeshaw at novell.com
Wed Jan 12 08:49:49 PST 2005


Hi Jono,

On Wed, 2005-01-12 at 04:13 -0800, Jono Bacon wrote:
>  - Firstly, in terms of detecting if the device has
> been plugged in, is this a HAL or DBUS thing?

Right now, libhal is C only and hasn't been bound into any other
languages, so from python you have to use the "pure" dbus APIs.
Fortunately HAL's dbus integration is pretty straightforward.

>  - What kind of code would I need to write to detect
> if a USB device has been plugged in?

David's sample code looks pretty good.  You may also need
hal_manager.GetAllDevices(), which returns a list of all the UDIs that
HAL knows about.  FindDeviceStringMatch() and FindDeviceByCapability()
(also on Hal.Manager) may also be helpful.  You can check libhal.c for a
list of the dbus methods you can use, if they're not in the docs.

You can use the "info.bus" property (set to "usb") to find what USB
devices have been attached, and you'll probably want to use the
"storage" and/or "volume" (or is it "storage.volume"?  I forget)
capabilities to find out if it's a storage device or not.  Whether or
not it's a keychain flash device or an external hard drive might be
tough to figure out, though... most devices can't identify themselves
one way or another that specifically.

Joe

_______________________________________________
hal mailing list
hal at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/hal



More information about the Hal mailing list