示例#1
0
    def get_plugin_by_vendor_product_id(cls, product_id, vendor_id):
        """Get a plugin by its product and vendor ids"""
        log.msg("get_plugin_by_id called with 0x%04x and 0x%04x"
                    % (product_id, vendor_id))
        for plugin in cls.get_plugins(interfaces.IDevicePlugin):
            props = flatten_list(plugin.__properties__.values())
            if int(product_id) in props and int(vendor_id) in props:
                if not plugin.mapping:
                    # regular plugin
                    return plugin

                # device has multiple personalities...
                # this will just return the default plugin for
                # the mapping, we keep a reference to the mapping
                # once the device is properly identified by
                # core.hardware.base::identify_device
                _plugin = plugin.mapping['default']()
                _plugin.mapping = plugin.mapping
                return _plugin

        return None
示例#2
0
    def test_flatten_list(self):
        self.assertEqual(flatten_list([1, 2, [5, 6]]), [1, 2, 5, 6])
        self.assertEqual(flatten_list([1, 2, (5, 6)]), [1, 2, 5, 6])

        self.assertEqual(flatten_list([1, iter([2, 3, 4])]), [1, 2, 3, 4])