Beispiel #1
0
    def device_links(self):
        """
        An iterator, which yields the absolute paths (including the device
        directory, see :attr:`Context.device_path`) of all symbolic links
        pointing to the :attr:`device_node` of this device.  The paths are
        unicode strings.

        UDev can create symlinks to the original device node (see
        :attr:`device_node`) inside the device directory.  This is often
        used to assign a constant, fixed device node to devices like
        removeable media, which technically do not have a constant device
        node, or to map a single device into multiple device hierarchies.
        The property provides access to all such symbolic links, which were
        created by UDev for this device.

        .. warning::

           Links are not necessarily resolved by
           :meth:`Device.from_device_file()`. Hence do *not* rely on
           ``Device.from_device_file(context, link).device_path ==
           device.device_path`` from any ``link`` in ``device.device_links``.
        """
        devlinks = libudev.udev_device_get_devlinks_list_entry(self)
        for name, _ in udev_list_iterate(devlinks):
            yield ensure_unicode_string(name)
Beispiel #2
0
def test_udev_list_iterate_mock():
    libudev = Mock(name='libudev')
    items = [('spam', 'eggs'), ('foo', 'bar')]
    with pytest.libudev_list(libudev, 'udev_enumerate_get_list_entry', items):
        udev_list = libudev.udev_enumerate_get_list_entry()
        assert list(_util.udev_list_iterate(libudev, udev_list)) == [
            ('spam', 'eggs'), ('foo', 'bar')]
Beispiel #3
0
def test_udev_list_iterate_mock():
    from pyudev._libudev import libudev
    items = [('spam', 'eggs'), ('foo', 'bar')]
    with pytest.libudev_list('udev_enumerate_get_list_entry', items):
        udev_list = libudev.udev_enumerate_get_list_entry()
        assert list(_util.udev_list_iterate(udev_list)) == [
            ('spam', 'eggs'), ('foo', 'bar')]
Beispiel #4
0
    def device_links(self):
        """
        An iterator, which yields the absolute paths (including the device
        directory, see :attr:`Context.device_path`) of all symbolic links
        pointing to the :attr:`device_node` of this device.  The paths are
        unicode strings.

        UDev can create symlinks to the original device node (see
        :attr:`device_node`) inside the device directory.  This is often
        used to assign a constant, fixed device node to devices like
        removeable media, which technically do not have a constant device
        node, or to map a single device into multiple device hierarchies.
        The property provides access to all such symbolic links, which were
        created by UDev for this device.

        .. warning::

           Links are not necessarily resolved by
           :meth:`Device.from_device_file()`. Hence do *not* rely on
           ``Device.from_device_file(context, link).device_path ==
           device.device_path`` from any ``link`` in ``device.device_links``.
        """
        devlinks = libudev.udev_device_get_devlinks_list_entry(self)
        for name, _ in udev_list_iterate(devlinks):
            yield ensure_unicode_string(name)
Beispiel #5
0
 def __len__(self):
     """
     Return the amount of properties defined for this device as integer.
     """
     properties = \
        self._libudev.udev_device_get_properties_list_entry(self.device)
     return sum(1 for _ in udev_list_iterate(self._libudev, properties))
Beispiel #6
0
 def __len__(self):
     """
     Return the amount of properties defined for this device as integer.
     """
     properties = \
        self._libudev.udev_device_get_properties_list_entry(self.device)
     return sum(1 for _ in udev_list_iterate(self._libudev, properties))
Beispiel #7
0
def test_udev_list_iterate_mock():
    libudev = Mock(name='libudev')
    items = [('spam', 'eggs'), ('foo', 'bar')]
    with pytest.libudev_list(libudev, 'udev_enumerate_get_list_entry', items):
        udev_list = libudev.udev_enumerate_get_list_entry()
        assert list(_util.udev_list_iterate(libudev,
                                            udev_list)) == [('spam', 'eggs'),
                                                            ('foo', 'bar')]
Beispiel #8
0
    def __iter__(self):
        """
        Iterate over all tags.

        Yield each tag as unicode string.
        """
        tags = libudev.udev_device_get_tags_list_entry(self.device)
        for tag, _ in udev_list_iterate(tags):
            yield ensure_unicode_string(tag)
Beispiel #9
0
def test_udev_list_iterate_mock():
    libudev = Mock(name="libudev")
    items = [("spam", "eggs"), ("foo", "bar")]
    with pytest.libudev_list(libudev, "udev_enumerate_get_list_entry", items):
        udev_list = libudev.udev_enumerate_get_list_entry()
        assert list(_util.udev_list_iterate(libudev, udev_list)) == [
            ("spam", "eggs"),
            ("foo", "bar"),
        ]
Beispiel #10
0
 def __len__(self):
     """
     Return the amount of properties defined for this device as integer.
     """
     properties = libudev.udev_device_get_properties_list_entry(self)
     i = 0
     for i, _ in enumerate(udev_list_iterate(properties), start=1):
         pass
     return i
Beispiel #11
0
 def __len__(self):
     """
     Return the amount of properties defined for this device as integer.
     """
     properties = libudev.udev_device_get_properties_list_entry(self)
     i = 0
     for i, _ in enumerate(udev_list_iterate(properties), start=1):
         pass
     return i
Beispiel #12
0
    def __iter__(self):
        """
        Iterate over all tags.

        Yield each tag as unicode string.
        """
        tags = libudev.udev_device_get_tags_list_entry(self.device)
        for tag, _ in udev_list_iterate(tags):
            yield ensure_unicode_string(tag)
Beispiel #13
0
    def __iter__(self):
        """
        Iterate over all matching devices.

        Yield :class:`Device` objects.
        """
        self._libudev.udev_enumerate_scan_devices(self)
        entry = self._libudev.udev_enumerate_get_list_entry(self)
        for name, _ in udev_list_iterate(self._libudev, entry):
            yield Device.from_sys_path(self.context, name)
Beispiel #14
0
    def __iter__(self):
        """
        Iterate over the names of all properties defined for this device.

        Return a generator yielding the names of all properties of this
        device as unicode strings.
        """
        properties = libudev.udev_device_get_properties_list_entry(self)
        for name, _ in udev_list_iterate(properties):
            yield ensure_unicode_string(name)
Beispiel #15
0
def test_udev_list_iterate_mock():
    test_list = ['spam', 'eggs', 'foo', 'bar']
    get_list_entry = 'udev_enumerate_get_list_entry'
    with pytest.patch_libudev_list(test_list, get_list_entry) as get_list_entry:
        items = list(_util.udev_list_iterate(get_list_entry()))
        assert items == [
            ('spam', 'value of spam'),
            ('eggs', 'value of eggs'),
            ('foo', 'value of foo'),
            ('bar', 'value of bar')]
Beispiel #16
0
    def __iter__(self):
        """
        Iterate over the names of all properties defined for this device.

        Return a generator yielding the names of all properties of this
        device as unicode strings.
        """
        properties = libudev.udev_device_get_properties_list_entry(self)
        for name, _ in udev_list_iterate(properties):
            yield ensure_unicode_string(name)
Beispiel #17
0
    def __iter__(self):
        """
        Iterate over all matching devices.

        Yield :class:`Device` objects.
        """
        libudev.udev_enumerate_scan_devices(self)
        entry = libudev.udev_enumerate_get_list_entry(self)
        for name, _ in udev_list_iterate(entry):
            yield Device.from_sys_path(self.context, name)
Beispiel #18
0
 def _get_attributes(self):
     if hasattr(self._libudev, 'udev_device_get_sysattr_list_entry'):
         attrs = self._libudev.udev_device_get_sysattr_list_entry(
             self.device)
         for attribute, _ in udev_list_iterate(self._libudev, attrs):
             yield ensure_unicode_string(attribute)
     else:
         sys_path = self.device.sys_path
         for filename in os.listdir(sys_path):
             filepath = os.path.join(sys_path, filename)
             if _is_attribute_file(filepath):
                 yield filename
Beispiel #19
0
 def _get_attributes(self):
     if hasattr(self._libudev, 'udev_device_get_sysattr_list_entry'):
         attrs = self._libudev.udev_device_get_sysattr_list_entry(
             self.device)
         for attribute, _ in udev_list_iterate(self._libudev, attrs):
             yield ensure_unicode_string(attribute)
     else:
         sys_path = self.device.sys_path
         for filename in os.listdir(sys_path):
             filepath = os.path.join(sys_path, filename)
             if _is_attribute_file(filepath):
                 yield filename
Beispiel #20
0
    def __iter__(self):
        """
        Iterate over all matching devices.

        Yield :class:`Device` objects.
        """
        self._libudev.udev_enumerate_scan_devices(self)
        entry = self._libudev.udev_enumerate_get_list_entry(self)
        for name, _ in udev_list_iterate(self._libudev, entry):
            try:
                yield Device.from_sys_path(self.context, name)
            except DeviceNotFoundAtPathError:
                continue
Beispiel #21
0
    def device_links(self):
        """
        An iterator, which yields the absolute paths (including the device
        directory, see :attr:`Context.device_path`) of all symbolic links
        pointing to the :attr:`device_node` of this device.  The paths are
        unicode strings.

        UDev can create symlinks to the original device node (see
        :attr:`device_node`) inside the device directory.  This is often
        used to assign a constant, fixed device node to devices like
        removeable media, which technically do not have a constant device
        node, or to map a single device into multiple device hierarchies.
        The property provides access to all such symbolic links, which were
        created by UDev for this device.
        """
        devlinks = self._libudev.udev_device_get_devlinks_list_entry(self)
        for name, _ in udev_list_iterate(self._libudev, devlinks):
            yield ensure_unicode_string(name)
Beispiel #22
0
    def available_attributes(self):
        """
        Yield the ``available`` attributes for the device.

        It is not guaranteed that a key in this list will have a value.
        It is not guaranteed that a key not in this list will not have a value.

        It is guaranteed that the keys in this list are the keys that libudev
        considers to be "available" attributes.

        If libudev version does not define udev_device_get_sysattr_list_entry()
        yields nothing.

        See rhbz#1267584.
        """
        if not hasattr(self._libudev, 'udev_device_get_sysattr_list_entry'):
            return  # pragma: no cover
        attrs = self._libudev.udev_device_get_sysattr_list_entry(self.device)
        for attribute, _ in udev_list_iterate(self._libudev, attrs):
            yield ensure_unicode_string(attribute)
Beispiel #23
0
    def available_attributes(self):
        """
        Yield the ``available`` attributes for the device.

        It is not guaranteed that a key in this list will have a value.
        It is not guaranteed that a key not in this list will not have a value.

        It is guaranteed that the keys in this list are the keys that libudev
        considers to be "available" attributes.

        If libudev version does not define udev_device_get_sysattr_list_entry()
        yields nothing.

        See rhbz#1267584.
        """
        if not hasattr(self._libudev, 'udev_device_get_sysattr_list_entry'):
            return # pragma: no cover
        attrs = self._libudev.udev_device_get_sysattr_list_entry(self.device)
        for attribute, _ in udev_list_iterate(self._libudev, attrs):
            yield ensure_unicode_string(attribute)
Beispiel #24
0
def test_udev_list_iterate_no_entry():
    assert not list(_util.udev_list_iterate(None))
Beispiel #25
0
 def _attributes(self):
     attrs = libudev.udev_device_get_sysattr_list_entry(self.device)
     for attribute, _ in udev_list_iterate(attrs):
         yield ensure_unicode_string(attribute)
Beispiel #26
0
def test_udev_list_iterate_no_entry():
    assert not list(_util.udev_list_iterate(Mock(), None))
Beispiel #27
0
 def _attributes(self):
     attrs = libudev.udev_device_get_sysattr_list_entry(self.device)
     for attribute, _ in udev_list_iterate(attrs):
         yield ensure_unicode_string(attribute)
Beispiel #28
0
def test_udev_list_iterate_mock():
    libudev = Mock(name="libudev")
    items = [("spam", "eggs"), ("foo", "bar")]
    with pytest.libudev_list(libudev, "udev_enumerate_get_list_entry", items):
        udev_list = libudev.udev_enumerate_get_list_entry()
        assert list(_util.udev_list_iterate(libudev, udev_list)) == [("spam", "eggs"), ("foo", "bar")]