コード例 #1
0
ファイル: device.py プロジェクト: PSC-SR/robotpy
    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)
コード例 #2
0
ファイル: test_util.py プロジェクト: cjmayo/pyudev
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')]
コード例 #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')]
コード例 #4
0
ファイル: device.py プロジェクト: headphones81/impulse-cube
    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)
コード例 #5
0
ファイル: _device.py プロジェクト: chzhong/pyudev
 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))
コード例 #6
0
ファイル: _device.py プロジェクト: badboy-wq/python_package
 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))
コード例 #7
0
ファイル: test_util.py プロジェクト: skruppy/pyudev
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')]
コード例 #8
0
ファイル: device.py プロジェクト: PSC-SR/robotpy
    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)
コード例 #9
0
ファイル: test_util.py プロジェクト: fork-for-humanity/pyudev
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"),
        ]
コード例 #10
0
ファイル: device.py プロジェクト: PSC-SR/robotpy
 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
コード例 #11
0
ファイル: device.py プロジェクト: headphones81/impulse-cube
 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
コード例 #12
0
ファイル: device.py プロジェクト: headphones81/impulse-cube
    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)
コード例 #13
0
ファイル: core.py プロジェクト: AlexisCaffa/multibootusb
    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)
コード例 #14
0
ファイル: device.py プロジェクト: PSC-SR/robotpy
    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)
コード例 #15
0
ファイル: test_util.py プロジェクト: lanstat/pyudev
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')]
コード例 #16
0
ファイル: device.py プロジェクト: headphones81/impulse-cube
    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)
コード例 #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)
コード例 #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
コード例 #19
0
ファイル: device.py プロジェクト: AlexisCaffa/multibootusb
 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
コード例 #20
0
ファイル: core.py プロジェクト: suyashbansal/pyudev
    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
コード例 #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)
コード例 #22
0
ファイル: _device.py プロジェクト: badboy-wq/python_package
    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)
コード例 #23
0
ファイル: _device.py プロジェクト: cjmayo/pyudev
    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)
コード例 #24
0
ファイル: test_util.py プロジェクト: csleex/pyudev
def test_udev_list_iterate_no_entry():
    assert not list(_util.udev_list_iterate(None))
コード例 #25
0
ファイル: device.py プロジェクト: headphones81/impulse-cube
 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)
コード例 #26
0
ファイル: test_util.py プロジェクト: skruppy/pyudev
def test_udev_list_iterate_no_entry():
    assert not list(_util.udev_list_iterate(Mock(), None))
コード例 #27
0
ファイル: device.py プロジェクト: PSC-SR/robotpy
 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)
コード例 #28
0
ファイル: test_util.py プロジェクト: bjornarg/pyudev
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")]