示例#1
0
    def device_changed(self, gudevice, subsystem):
        '''Called when a device has been updated'''

        dev = device.get_device_object(gudevice)
        old_dev = self.devices_tree[dev.path]
        self.devices_tree[dev.path] = dev
        self.emit('changed', dev, old_dev)
示例#2
0
    def device_changed(self, gudevice, subsystem):
        '''Called when a device has been updated'''

        dev = device.get_device_object(gudevice)
        old_dev = self.devices_tree[dev.path]
        self.devices_tree[dev.path] = dev
        self.emit('changed', dev, old_dev)
示例#3
0
    def device_removed(self, gudevice, subsystem):
        '''Called when a device has been removed from the system'''

        dev = device.get_device_object(gudevice)

        if dev in self.devices_list: self.devices_list.remove(dev)
        if self.devices_tree.has_key(dev.path): del(self.devices_tree[dev.path])

        self.emit('removed', dev)
示例#4
0
    def scan_subsystems(self, subsystems="", parent_tree=False):
        self.client = gudev.Client(subsystems)
        self.subsystems = subsystems
        self.devices_tree = {}
        self.devices_list = []

        if subsystems == "":
            subsystems = ["*"]
        for subsystem in subsystems:
            for gudevice in self.client.query_by_subsystem(subsystem):
                if parent_tree:
                    self.__explore_parent(gudevice, self.devices_tree, self.devices_list)
                else:
                    self.devices_list.append(device.get_device_object(gudevice))
                    self.devices_tree[gudevice.get_sysfs_path()] = device.get_device_object(gudevice)

        self.client.connect("uevent", self.event)
        self.parent_tree = parent_tree
示例#5
0
    def device_removed(self, gudevice, subsystem):
        '''Called when a device has been removed from the system'''

        dev = device.get_device_object(gudevice)

        if dev in self.devices_list: self.devices_list.remove(dev)
        if self.devices_tree.has_key(dev.path):
            del (self.devices_tree[dev.path])

        self.emit('removed', dev)
示例#6
0
    def device_added(self, gudevice, subsystem):
        '''Called when a device has been added to the system'''

        dev = device.get_device_object(gudevice)

        if self.parent_tree: 
            self.__explore_parent(gudevice, self.devices_tree, self.devices_list, True)
        else:
            self.devices_list.append(dev)
            self.devices_tree[dev.path] = dev
            self.emit('added', dev)
示例#7
0
    def scan_subsystems(self, subsystems='', parent_tree=False):
        self.client = GUdev.Client.new(subsystems)
        self.subsystems = subsystems
        self.devices_tree = {}
        self.devices_list = []

        if subsystems == '': subsystems = ['*']
        for subsystem in subsystems:
            for gudevice in self.client.query_by_subsystem(subsystem):
                if parent_tree:
                    self.__explore_parent(gudevice, self.devices_tree,
                                          self.devices_list)
                else:
                    self.devices_list.append(
                        device.get_device_object(gudevice))
                    self.devices_tree[gudevice.get_sysfs_path()] = \
                        device.get_device_object(gudevice)

        self.client.connect('uevent', self.event)
        self.parent_tree = parent_tree
示例#8
0
    def device_added(self, gudevice, subsystem):
        '''Called when a device has been added to the system'''

        dev = device.get_device_object(gudevice)

        if self.parent_tree:
            self.__explore_parent(gudevice, self.devices_tree,
                                  self.devices_list, True)
        else:
            self.devices_list.append(dev)
            self.devices_tree[dev.path] = dev
            self.emit('added', dev)
示例#9
0
    def __explore_parent(self, gudevice, devices_tree, devices_list, emit=False):
        path = gudevice.get_sysfs_path()
        parent = gudevice.get_parent()

        if parent: 
            self.__explore_parent(parent, devices_tree, devices_list, emit)

        if not devices_tree.has_key(path):
            dev = device.get_device_object(gudevice)
            devices_tree[path] = dev
            devices_list.append(dev)

            if emit:
                self.emit('added', dev)
示例#10
0
    def __explore_parent(self,
                         gudevice,
                         devices_tree,
                         devices_list,
                         emit=False):
        path = gudevice.get_sysfs_path()
        parent = gudevice.get_parent()

        if parent:
            self.__explore_parent(parent, devices_tree, devices_list, emit)

        if not devices_tree.has_key(path):
            dev = device.get_device_object(gudevice)
            devices_tree[path] = dev
            devices_list.append(dev)

            if emit:
                self.emit('added', dev)
示例#11
0
    def device_changed(self, gudevice, subsystem):
        '''Called when a device has been updated'''

        dev = device.get_device_object(gudevice)
        self.emit('changed', dev)
    def device_changed(self, gudevice, subsystem):
        '''Called when a device has been updated'''

        dev = device.get_device_object(gudevice)
        self.emit('changed', dev)
示例#13
0
    def device_changed(self, gudevice, subsystem):
        """Called when a device has been updated"""

        dev = device.get_device_object(gudevice)
        self.emit("changed", dev)