Searching HAL for a specific device type

David Zeuthen david at fubar.dk
Mon Jan 17 08:01:26 PST 2005


On Sun, 2005-01-16 at 18:29 -0800, Jono Bacon wrote:
> Hi all,
> 

Hi,

> Right, I have been making progress with my HAL and
> Python coding, and thanks for the help you have given
> me. I have successfully managed to connect to HAL and
> dig out some information, but I am only getting
> information about the Computer (at the top of the HAL
> Device Manager). Here is my code:
> 
> 		bus = dbus.Bus(dbus.Bus.TYPE_SYSTEM)
> 		hal_service = bus.get_service("org.freedesktop.Hal")
> 		hal_manager =
> hal_service.get_object("/org/freedesktop/Hal/Manager",
> "org.freedesktop.Hal.Manager")
> 

This looks good so far

> 		# Add listeners for all devices

That's not really what you do below

> 		try:
> 			device_names = hal_manager.GetAllDevices()
> 		except:
> 			print "Could not get device list"
> 			sys.exit(0)
> 

It seems that you retrieve all UDI representing device objects
in HAL. The output of the program may be useful to paste into
your mail.

> 		for name in device_names:
> 			device_udi_obj =
> hal_service.get_object("/org/freedesktop/Hal/devices/pci_8086_24c7",
> "org.freedesktop.Hal.Device")
> 			device_dbus_obj = hal_service.get_object(name,
> "org.freedesktop.Hal.Device")

You should be able to just say

 hal_device = dbus_obj = hal_service.get_object(name,
"org.freedesktop.Hal.Device")

Not sure where the "/org/freedesktop/Hal/devices/pci_8086_24c7"
comes from..

> 			properties = device_dbus_obj.GetAllProperties()

Here you get the properties of the each object which
is good.

> 		print properties		

Indentation does matter in Python! Since this is not indented it
is not part of the loop so you only print the last set of
properties; which may happen to be the Computer device object.

> 		item = ("kernel", properties['kernel.machine'])
>                	self.model.append(item)
> 
> I now need to figure out how I can find out if there
> are USB Mass Storage devices attached to the system,
> so I can list them in my tree view. How can I do this?
> 

The docs may be useful

 http://cvs.freedesktop.org/*checkout*/hal/hal/doc/spec/hal-
spec.html#AEN2292

and there is this example (which may be out of date, but..)


http://cvs.freedesktop.org/*checkout*/hal/hal/examples/volumed/volumed.py?content-type=text%2Fplain

You can use 'lshal --monitor' to see the various signals that hald
emits as well as the properties. 

Hope this helps,
David


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



More information about the Hal mailing list