def build_device_tree(self):
        """Retrieves the device list from the HAL daemon and builds
        a tree of Device (Python) objects. The root is a virtual
        device"""
        device_names = self.hal_manager.GetAllDevices()
        device_names.sort()

        virtual_root = Device("virtual_root", None, {})
        self.device_list = [virtual_root]
        
        # first build list of Device objects
        # name == device's udi 
        for name in device_names:
            device_dbus_obj = self.bus.get_object("org.freedesktop.Hal" ,name)

            # properties is the list of hal properies of "name"
            properties = device_dbus_obj.GetAllProperties(dbus_interface="org.freedesktop.Hal.Device")
            #print 
            #print "#######################"
            #print properties
            #print "#######################" 
            try:
                parent_name = properties["info.parent"]
            except KeyError:
                # no parent, must be parent of virtual_root
                parent_name = "/"
            except TypeError:
                print "Error: no properties for device %s"%name
                continue
            device = Device(name, parent_name, properties)
            self.device_list.append(device)

        # set parent_device and children for each Device object
        for device in self.device_list:
            parent_name = device.parent_name
            device.parent_device = virtual_root
            if parent_name!="/":
                for p in self.device_list:
                    if p.device_name==parent_name:
                        device.parent_device = p
                        p.children.append(device)
            if device!=virtual_root and device.parent_device==virtual_root:
                virtual_root.children.append(device)
            if device==virtual_root:
                device.parent_device=None
        return virtual_root
Example #2
0
        parent_name = properties["info.parent"]
    except KeyError:
        # no parent, must be parent of virtual_roo
        parent_name = "/"
    except TypeError:
        print "Error: no properties for device %s"%name
        continue
    device = Device(name, parent_name, properties)
    device_list.append(device)

#print device_list

for device in device_list:
    parent_name = device.parent_name
    #print parent_name
    device.parent_device = virtual_root
    if parent_name!="/":
        for p in device_list:
            if p.device_name==parent_name:
                device.parent_device = p
                p.children.append(device)
    if device!=virtual_root and device.parent_device==virtual_root:
        virtual_root.children.append(device)
    if device==virtual_root:
        device.parent_device=None

#device_obj = virtual_root.find_by_udi(device_udi)
if len(sys.argv) == 1:
    device_udi=device_names
else:
    device_udi=[sys.argv[1]]