|
|
fea5c0 |
diff --git a/pyudev/_libudev.py b/pyudev/_libudev.py
|
|
|
fea5c0 |
index efc27c9..7d97d35 100644
|
|
|
fea5c0 |
--- a/pyudev/_libudev.py
|
|
|
fea5c0 |
+++ b/pyudev/_libudev.py
|
|
|
fea5c0 |
@@ -284,6 +284,3 @@ def load_udev_library():
|
|
|
fea5c0 |
if errorchecker:
|
|
|
fea5c0 |
func.errcheck = errorchecker
|
|
|
fea5c0 |
return libudev
|
|
|
fea5c0 |
-
|
|
|
fea5c0 |
-
|
|
|
fea5c0 |
-libudev = load_udev_library()
|
|
|
fea5c0 |
diff --git a/pyudev/_util.py b/pyudev/_util.py
|
|
|
fea5c0 |
index a99da08..c11b0b2 100644
|
|
|
fea5c0 |
--- a/pyudev/_util.py
|
|
|
fea5c0 |
+++ b/pyudev/_util.py
|
|
|
fea5c0 |
@@ -33,7 +33,6 @@ import os
|
|
|
fea5c0 |
import sys
|
|
|
fea5c0 |
import stat
|
|
|
fea5c0 |
|
|
|
fea5c0 |
-from pyudev._libudev import libudev
|
|
|
fea5c0 |
|
|
|
fea5c0 |
if sys.version_info[0] == 2:
|
|
|
fea5c0 |
from pyudev._py2util import *
|
|
|
fea5c0 |
@@ -101,7 +100,7 @@ def string_to_bool(value):
|
|
|
fea5c0 |
return value == '1'
|
|
|
fea5c0 |
|
|
|
fea5c0 |
|
|
|
fea5c0 |
-def udev_list_iterate(entry):
|
|
|
fea5c0 |
+def udev_list_iterate(libudev, entry):
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
Iteration helper for udev list entry objects.
|
|
|
fea5c0 |
|
|
|
fea5c0 |
diff --git a/pyudev/core.py b/pyudev/core.py
|
|
|
fea5c0 |
index 83d2c7c..5017d80 100644
|
|
|
fea5c0 |
--- a/pyudev/core.py
|
|
|
fea5c0 |
+++ b/pyudev/core.py
|
|
|
fea5c0 |
@@ -35,7 +35,7 @@ except ImportError:
|
|
|
fea5c0 |
from pyudev._compat import check_output
|
|
|
fea5c0 |
|
|
|
fea5c0 |
from pyudev.device import Device
|
|
|
fea5c0 |
-from pyudev._libudev import libudev
|
|
|
fea5c0 |
+from pyudev._libudev import load_udev_library
|
|
|
fea5c0 |
from pyudev._util import (ensure_unicode_string, ensure_byte_string,
|
|
|
fea5c0 |
udev_list_iterate, property_value_to_bytes)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@@ -89,10 +89,11 @@ class Context(object):
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
Create a new context.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- self._as_parameter_ = libudev.udev_new()
|
|
|
fea5c0 |
+ self._libudev = load_udev_library()
|
|
|
fea5c0 |
+ self._as_parameter_ = self._libudev.udev_new()
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def __del__(self):
|
|
|
fea5c0 |
- libudev.udev_unref(self)
|
|
|
fea5c0 |
+ self._libudev.udev_unref(self)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@property
|
|
|
fea5c0 |
def sys_path(self):
|
|
|
fea5c0 |
@@ -102,7 +103,7 @@ class Context(object):
|
|
|
fea5c0 |
The mount point can be overwritten using the environment variable
|
|
|
fea5c0 |
:envvar:`SYSFS_PATH`. Use this for testing purposes.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- return ensure_unicode_string(libudev.udev_get_sys_path(self))
|
|
|
fea5c0 |
+ return ensure_unicode_string(self._libudev.udev_get_sys_path(self))
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@property
|
|
|
fea5c0 |
def device_path(self):
|
|
|
fea5c0 |
@@ -111,7 +112,7 @@ class Context(object):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
This can be overridden in the udev configuration.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- return ensure_unicode_string(libudev.udev_get_dev_path(self))
|
|
|
fea5c0 |
+ return ensure_unicode_string(self._libudev.udev_get_dev_path(self))
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@property
|
|
|
fea5c0 |
def run_path(self):
|
|
|
fea5c0 |
@@ -123,7 +124,7 @@ class Context(object):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
.. versionadded:: 0.10
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- return ensure_unicode_string(libudev.udev_get_run_path(self))
|
|
|
fea5c0 |
+ return ensure_unicode_string(self._libudev.udev_get_run_path(self))
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@property
|
|
|
fea5c0 |
def log_priority(self):
|
|
|
fea5c0 |
@@ -142,11 +143,11 @@ class Context(object):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
.. versionadded:: 0.9
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- return libudev.udev_get_log_priority(self)
|
|
|
fea5c0 |
+ return self._libudev.udev_get_log_priority(self)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@log_priority.setter
|
|
|
fea5c0 |
def log_priority(self, value):
|
|
|
fea5c0 |
- libudev.udev_set_log_priority(self, value)
|
|
|
fea5c0 |
+ self._libudev.udev_set_log_priority(self, value)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def list_devices(self, **kwargs):
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
@@ -205,10 +206,11 @@ class Enumerator(object):
|
|
|
fea5c0 |
if not isinstance(context, Context):
|
|
|
fea5c0 |
raise TypeError('Invalid context object')
|
|
|
fea5c0 |
self.context = context
|
|
|
fea5c0 |
- self._as_parameter_ = libudev.udev_enumerate_new(context)
|
|
|
fea5c0 |
+ self._as_parameter_ = context._libudev.udev_enumerate_new(context)
|
|
|
fea5c0 |
+ self._libudev = context._libudev
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def __del__(self):
|
|
|
fea5c0 |
- libudev.udev_enumerate_unref(self)
|
|
|
fea5c0 |
+ self._libudev.udev_enumerate_unref(self)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def match(self, **kwargs):
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
@@ -265,9 +267,9 @@ class Enumerator(object):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
Return the instance again.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- match = (libudev.udev_enumerate_add_match_subsystem
|
|
|
fea5c0 |
+ match = (self._libudev.udev_enumerate_add_match_subsystem
|
|
|
fea5c0 |
if not nomatch else
|
|
|
fea5c0 |
- libudev.udev_enumerate_add_nomatch_subsystem)
|
|
|
fea5c0 |
+ self._libudev.udev_enumerate_add_nomatch_subsystem)
|
|
|
fea5c0 |
match(self, ensure_byte_string(subsystem))
|
|
|
fea5c0 |
return self
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@@ -281,7 +283,7 @@ class Enumerator(object):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
.. versionadded:: 0.8
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- libudev.udev_enumerate_add_match_sysname(
|
|
|
fea5c0 |
+ self._libudev.udev_enumerate_add_match_sysname(
|
|
|
fea5c0 |
self, ensure_byte_string(sys_name))
|
|
|
fea5c0 |
return self
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@@ -301,7 +303,7 @@ class Enumerator(object):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
Return the instance again.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- libudev.udev_enumerate_add_match_property(
|
|
|
fea5c0 |
+ self._libudev.udev_enumerate_add_match_property(
|
|
|
fea5c0 |
self, ensure_byte_string(property), property_value_to_bytes(value))
|
|
|
fea5c0 |
return self
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@@ -332,9 +334,9 @@ class Enumerator(object):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
Return the instance again.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- match = (libudev.udev_enumerate_add_match_sysattr
|
|
|
fea5c0 |
+ match = (self._libudev.udev_enumerate_add_match_sysattr
|
|
|
fea5c0 |
if not nomatch else
|
|
|
fea5c0 |
- libudev.udev_enumerate_add_nomatch_sysattr)
|
|
|
fea5c0 |
+ self._libudev.udev_enumerate_add_nomatch_sysattr)
|
|
|
fea5c0 |
match(self, ensure_byte_string(attribute),
|
|
|
fea5c0 |
property_value_to_bytes(value))
|
|
|
fea5c0 |
return self
|
|
|
fea5c0 |
@@ -351,7 +353,7 @@ class Enumerator(object):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
.. versionadded:: 0.6
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- libudev.udev_enumerate_add_match_tag(self, ensure_byte_string(tag))
|
|
|
fea5c0 |
+ self._libudev.udev_enumerate_add_match_tag(self, ensure_byte_string(tag))
|
|
|
fea5c0 |
return self
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def match_is_initialized(self):
|
|
|
fea5c0 |
@@ -372,7 +374,7 @@ class Enumerator(object):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
.. versionadded:: 0.8
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- libudev.udev_enumerate_add_match_is_initialized(self)
|
|
|
fea5c0 |
+ self._libudev.udev_enumerate_add_match_is_initialized(self)
|
|
|
fea5c0 |
return self
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def match_parent(self, parent):
|
|
|
fea5c0 |
@@ -389,7 +391,7 @@ class Enumerator(object):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
.. versionadded:: 0.13
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- libudev.udev_enumerate_add_match_parent(self, parent)
|
|
|
fea5c0 |
+ self._libudev.udev_enumerate_add_match_parent(self, parent)
|
|
|
fea5c0 |
return self
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def __iter__(self):
|
|
|
fea5c0 |
@@ -398,7 +400,7 @@ class Enumerator(object):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
Yield :class:`Device` objects.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- libudev.udev_enumerate_scan_devices(self)
|
|
|
fea5c0 |
- entry = libudev.udev_enumerate_get_list_entry(self)
|
|
|
fea5c0 |
- for name, _ in udev_list_iterate(entry):
|
|
|
fea5c0 |
+ self._libudev.udev_enumerate_scan_devices(self)
|
|
|
fea5c0 |
+ entry = self._libudev.udev_enumerate_get_list_entry(self)
|
|
|
fea5c0 |
+ for name, _ in udev_list_iterate(self._libudev, entry):
|
|
|
fea5c0 |
yield Device.from_sys_path(self.context, name)
|
|
|
fea5c0 |
diff --git a/pyudev/device.py b/pyudev/device.py
|
|
|
fea5c0 |
index f9a4325..d5ae3da 100644
|
|
|
fea5c0 |
--- a/pyudev/device.py
|
|
|
fea5c0 |
+++ b/pyudev/device.py
|
|
|
fea5c0 |
@@ -32,7 +32,6 @@ import os
|
|
|
fea5c0 |
from collections import Mapping, Container, Iterable
|
|
|
fea5c0 |
from datetime import timedelta
|
|
|
fea5c0 |
|
|
|
fea5c0 |
-from pyudev._libudev import libudev
|
|
|
fea5c0 |
from pyudev._util import (ensure_byte_string, ensure_unicode_string,
|
|
|
fea5c0 |
udev_list_iterate, string_to_bool,
|
|
|
fea5c0 |
get_device_type)
|
|
|
fea5c0 |
@@ -219,7 +218,7 @@ class Device(Mapping):
|
|
|
fea5c0 |
Raise :exc:`DeviceNotFoundAtPathError` instead of
|
|
|
fea5c0 |
:exc:`NoSuchDeviceError`
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- device = libudev.udev_device_new_from_syspath(
|
|
|
fea5c0 |
+ device = context._libudev.udev_device_new_from_syspath(
|
|
|
fea5c0 |
context, ensure_byte_string(sys_path))
|
|
|
fea5c0 |
if not device:
|
|
|
fea5c0 |
raise DeviceNotFoundAtPathError(sys_path)
|
|
|
fea5c0 |
@@ -247,7 +246,7 @@ class Device(Mapping):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
.. versionadded:: 0.5
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- device = libudev.udev_device_new_from_subsystem_sysname(
|
|
|
fea5c0 |
+ device = context._libudev.udev_device_new_from_subsystem_sysname(
|
|
|
fea5c0 |
context, ensure_byte_string(subsystem),
|
|
|
fea5c0 |
ensure_byte_string(sys_name))
|
|
|
fea5c0 |
if not device:
|
|
|
fea5c0 |
@@ -295,7 +294,7 @@ class Device(Mapping):
|
|
|
fea5c0 |
if type not in ('char', 'block'):
|
|
|
fea5c0 |
raise ValueError('Invalid type: {0!r}. Must be one of "char" '
|
|
|
fea5c0 |
'or "block".'.format(type))
|
|
|
fea5c0 |
- device = libudev.udev_device_new_from_devnum(
|
|
|
fea5c0 |
+ device = context._libudev.udev_device_new_from_devnum(
|
|
|
fea5c0 |
context, ensure_byte_string(type[0]), number)
|
|
|
fea5c0 |
if not device:
|
|
|
fea5c0 |
raise DeviceNotFoundByNumberError(type, number)
|
|
|
fea5c0 |
@@ -360,7 +359,7 @@ class Device(Mapping):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
.. versionadded:: 0.6
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- device = libudev.udev_device_new_from_environment(context)
|
|
|
fea5c0 |
+ device = context._libudev.udev_device_new_from_environment(context)
|
|
|
fea5c0 |
if not device:
|
|
|
fea5c0 |
raise DeviceNotFoundInEnvironmentError()
|
|
|
fea5c0 |
return cls(context, device)
|
|
|
fea5c0 |
@@ -368,9 +367,10 @@ class Device(Mapping):
|
|
|
fea5c0 |
def __init__(self, context, _device):
|
|
|
fea5c0 |
self.context = context
|
|
|
fea5c0 |
self._as_parameter_ = _device
|
|
|
fea5c0 |
+ self._libudev = context._libudev
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def __del__(self):
|
|
|
fea5c0 |
- libudev.udev_device_unref(self)
|
|
|
fea5c0 |
+ self._libudev.udev_device_unref(self)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def __repr__(self):
|
|
|
fea5c0 |
return 'Device({0.sys_path!r})'.format(self)
|
|
|
fea5c0 |
@@ -381,12 +381,12 @@ class Device(Mapping):
|
|
|
fea5c0 |
The parent :class:`Device` or ``None``, if there is no parent
|
|
|
fea5c0 |
device.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- parent = libudev.udev_device_get_parent(self)
|
|
|
fea5c0 |
+ parent = self._libudev.udev_device_get_parent(self)
|
|
|
fea5c0 |
if not parent:
|
|
|
fea5c0 |
return None
|
|
|
fea5c0 |
# the parent device is not referenced, thus forcibly acquire a
|
|
|
fea5c0 |
# reference
|
|
|
fea5c0 |
- return Device(self.context, libudev.udev_device_ref(parent))
|
|
|
fea5c0 |
+ return Device(self.context, self._libudev.udev_device_ref(parent))
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@property
|
|
|
fea5c0 |
def children(self):
|
|
|
fea5c0 |
@@ -432,12 +432,12 @@ class Device(Mapping):
|
|
|
fea5c0 |
subsystem = ensure_byte_string(subsystem)
|
|
|
fea5c0 |
if device_type is not None:
|
|
|
fea5c0 |
device_type = ensure_byte_string(device_type)
|
|
|
fea5c0 |
- parent = libudev.udev_device_get_parent_with_subsystem_devtype(
|
|
|
fea5c0 |
+ parent = self._libudev.udev_device_get_parent_with_subsystem_devtype(
|
|
|
fea5c0 |
self, subsystem, device_type)
|
|
|
fea5c0 |
if not parent:
|
|
|
fea5c0 |
return None
|
|
|
fea5c0 |
# parent device is not referenced, thus forcibly acquire a reference
|
|
|
fea5c0 |
- return Device(self.context, libudev.udev_device_ref(parent))
|
|
|
fea5c0 |
+ return Device(self.context, self._libudev.udev_device_ref(parent))
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def traverse(self):
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
@@ -458,7 +458,8 @@ class Device(Mapping):
|
|
|
fea5c0 |
Absolute path of this device in ``sysfs`` including the ``sysfs``
|
|
|
fea5c0 |
mount point as unicode string.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- return ensure_unicode_string(libudev.udev_device_get_syspath(self))
|
|
|
fea5c0 |
+ return ensure_unicode_string(
|
|
|
fea5c0 |
+ self._libudev.udev_device_get_syspath(self))
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@property
|
|
|
fea5c0 |
def device_path(self):
|
|
|
fea5c0 |
@@ -470,21 +471,24 @@ class Device(Mapping):
|
|
|
fea5c0 |
mount point. However, the path is absolute and starts with a slash
|
|
|
fea5c0 |
``'/'``.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- return ensure_unicode_string(libudev.udev_device_get_devpath(self))
|
|
|
fea5c0 |
+ return ensure_unicode_string(
|
|
|
fea5c0 |
+ self._libudev.udev_device_get_devpath(self))
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@property
|
|
|
fea5c0 |
def subsystem(self):
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
Name of the subsystem this device is part of as unicode string.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- return ensure_unicode_string(libudev.udev_device_get_subsystem(self))
|
|
|
fea5c0 |
+ return ensure_unicode_string(
|
|
|
fea5c0 |
+ self._libudev.udev_device_get_subsystem(self))
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@property
|
|
|
fea5c0 |
def sys_name(self):
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
Device file name inside ``sysfs`` as unicode string.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- return ensure_unicode_string(libudev.udev_device_get_sysname(self))
|
|
|
fea5c0 |
+ return ensure_unicode_string(
|
|
|
fea5c0 |
+ self._libudev.udev_device_get_sysname(self))
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@property
|
|
|
fea5c0 |
def sys_number(self):
|
|
|
fea5c0 |
@@ -508,7 +512,7 @@ class Device(Mapping):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
.. versionadded:: 0.11
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- number = libudev.udev_device_get_sysnum(self)
|
|
|
fea5c0 |
+ number = self._libudev.udev_device_get_sysnum(self)
|
|
|
fea5c0 |
if number is not None:
|
|
|
fea5c0 |
return ensure_unicode_string(number)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@@ -529,7 +533,7 @@ class Device(Mapping):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
.. versionadded:: 0.10
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- device_type = libudev.udev_device_get_devtype(self)
|
|
|
fea5c0 |
+ device_type = self._libudev.udev_device_get_devtype(self)
|
|
|
fea5c0 |
if device_type is not None:
|
|
|
fea5c0 |
return ensure_unicode_string(device_type)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@@ -541,7 +545,7 @@ class Device(Mapping):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
.. versionadded:: 0.5
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- driver = libudev.udev_device_get_driver(self)
|
|
|
fea5c0 |
+ driver = self._libudev.udev_device_get_driver(self)
|
|
|
fea5c0 |
if driver:
|
|
|
fea5c0 |
return ensure_unicode_string(driver)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@@ -563,7 +567,7 @@ class Device(Mapping):
|
|
|
fea5c0 |
this property is not necessary equal to the ``filename`` given to
|
|
|
fea5c0 |
:meth:`from_device_file()`.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- node = libudev.udev_device_get_devnode(self)
|
|
|
fea5c0 |
+ node = self._libudev.udev_device_get_devnode(self)
|
|
|
fea5c0 |
if node:
|
|
|
fea5c0 |
return ensure_unicode_string(node)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@@ -591,7 +595,7 @@ class Device(Mapping):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
.. versionadded:: 0.11
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- return libudev.udev_device_get_devnum(self)
|
|
|
fea5c0 |
+ return self._libudev.udev_device_get_devnum(self)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@property
|
|
|
fea5c0 |
def is_initialized(self):
|
|
|
fea5c0 |
@@ -614,7 +618,7 @@ class Device(Mapping):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
.. versionadded:: 0.8
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- return bool(libudev.udev_device_get_is_initialized(self))
|
|
|
fea5c0 |
+ return bool(self._libudev.udev_device_get_is_initialized(self))
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@property
|
|
|
fea5c0 |
def time_since_initialized(self):
|
|
|
fea5c0 |
@@ -631,7 +635,8 @@ class Device(Mapping):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
.. versionadded:: 0.8
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- microseconds = libudev.udev_device_get_usec_since_initialized(self)
|
|
|
fea5c0 |
+ microseconds = self._libudev.udev_device_get_usec_since_initialized(
|
|
|
fea5c0 |
+ self)
|
|
|
fea5c0 |
return timedelta(microseconds=microseconds)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@property
|
|
|
fea5c0 |
@@ -650,8 +655,8 @@ class Device(Mapping):
|
|
|
fea5c0 |
The property provides access to all such symbolic links, which were
|
|
|
fea5c0 |
created by UDev for this device.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- devlinks = libudev.udev_device_get_devlinks_list_entry(self)
|
|
|
fea5c0 |
- for name, _ in udev_list_iterate(devlinks):
|
|
|
fea5c0 |
+ devlinks = self._libudev.udev_device_get_devlinks_list_entry(self)
|
|
|
fea5c0 |
+ for name, _ in udev_list_iterate(self._libudev, devlinks):
|
|
|
fea5c0 |
yield ensure_unicode_string(name)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@property
|
|
|
fea5c0 |
@@ -713,19 +718,16 @@ class Device(Mapping):
|
|
|
fea5c0 |
Return a generator yielding the names of all properties of this
|
|
|
fea5c0 |
device as unicode strings.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- properties = libudev.udev_device_get_properties_list_entry(self)
|
|
|
fea5c0 |
- for name, _ in udev_list_iterate(properties):
|
|
|
fea5c0 |
+ properties = self._libudev.udev_device_get_properties_list_entry(self)
|
|
|
fea5c0 |
+ for name, _ in udev_list_iterate(self._libudev, properties):
|
|
|
fea5c0 |
yield ensure_unicode_string(name)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def __len__(self):
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
Return the amount of properties defined for this device as integer.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- properties = libudev.udev_device_get_properties_list_entry(self)
|
|
|
fea5c0 |
- i = 0
|
|
|
fea5c0 |
- for i, _ in enumerate(udev_list_iterate(properties), start=1):
|
|
|
fea5c0 |
- pass
|
|
|
fea5c0 |
- return i
|
|
|
fea5c0 |
+ properties = self._libudev.udev_device_get_properties_list_entry(self)
|
|
|
fea5c0 |
+ return sum(1 for _ in udev_list_iterate(self._libudev, properties))
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def __getitem__(self, property):
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
@@ -738,7 +740,7 @@ class Device(Mapping):
|
|
|
fea5c0 |
:exc:`~exceptions.KeyError`, if the given property is not defined
|
|
|
fea5c0 |
for this device.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- value = libudev.udev_device_get_property_value(
|
|
|
fea5c0 |
+ value = self._libudev.udev_device_get_property_value(
|
|
|
fea5c0 |
self, ensure_byte_string(property))
|
|
|
fea5c0 |
if value is None:
|
|
|
fea5c0 |
raise KeyError(property)
|
|
|
fea5c0 |
@@ -814,14 +816,17 @@ class Tags(Iterable, Container):
|
|
|
fea5c0 |
def __init__(self, device):
|
|
|
fea5c0 |
self.device = device
|
|
|
fea5c0 |
|
|
|
fea5c0 |
- if hasattr(libudev, 'udev_device_has_tag'):
|
|
|
fea5c0 |
- def _has_tag(self, tag):
|
|
|
fea5c0 |
- return bool(libudev.udev_device_has_tag(
|
|
|
fea5c0 |
+ def _has_tag(self, tag):
|
|
|
fea5c0 |
+ if hasattr(self._libudev, 'udev_device_has_tag'):
|
|
|
fea5c0 |
+ return bool(self._libudev.udev_device_has_tag(
|
|
|
fea5c0 |
self.device, ensure_byte_string(tag)))
|
|
|
fea5c0 |
- else:
|
|
|
fea5c0 |
- def _has_tag(self, tag):
|
|
|
fea5c0 |
+ else:
|
|
|
fea5c0 |
return any(t == tag for t in self)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
+ @property
|
|
|
fea5c0 |
+ def _libudev(self):
|
|
|
fea5c0 |
+ return self.device._libudev
|
|
|
fea5c0 |
+
|
|
|
fea5c0 |
def __contains__(self, tag):
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
Check for existence of ``tag``.
|
|
|
fea5c0 |
@@ -839,8 +844,8 @@ class Tags(Iterable, Container):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
Yield each tag as unicode string.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- tags = libudev.udev_device_get_tags_list_entry(self.device)
|
|
|
fea5c0 |
- for tag, _ in udev_list_iterate(tags):
|
|
|
fea5c0 |
+ tags = self._libudev.udev_device_get_tags_list_entry(self.device)
|
|
|
fea5c0 |
+ for tag, _ in udev_list_iterate(self._libudev, tags):
|
|
|
fea5c0 |
yield ensure_unicode_string(tag)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@@ -876,29 +881,26 @@ class Attributes(Mapping):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def __init__(self, device):
|
|
|
fea5c0 |
self.device = device
|
|
|
fea5c0 |
+ self._libudev = device._libudev
|
|
|
fea5c0 |
|
|
|
fea5c0 |
- if hasattr(libudev, 'udev_device_get_sysattr_list_entry'):
|
|
|
fea5c0 |
- @property
|
|
|
fea5c0 |
- def _attributes(self):
|
|
|
fea5c0 |
- attrs = libudev.udev_device_get_sysattr_list_entry(self.device)
|
|
|
fea5c0 |
- for attribute, _ in udev_list_iterate(attrs):
|
|
|
fea5c0 |
+ def _get_attributes(self):
|
|
|
fea5c0 |
+ if hasattr(self._libudev, 'udev_device_get_sysattr_list_entry'):
|
|
|
fea5c0 |
+ attrs = self._libudev.udev_device_get_sysattr_list_entry(
|
|
|
fea5c0 |
+ self.device)
|
|
|
fea5c0 |
+ for attribute, _ in udev_list_iterate(self._libudev, attrs):
|
|
|
fea5c0 |
yield ensure_unicode_string(attribute)
|
|
|
fea5c0 |
- else:
|
|
|
fea5c0 |
- @property
|
|
|
fea5c0 |
- def _attributes(self):
|
|
|
fea5c0 |
+ else:
|
|
|
fea5c0 |
sys_path = self.device.sys_path
|
|
|
fea5c0 |
- return (fn for fn in os.listdir(sys_path) if
|
|
|
fea5c0 |
- _is_attribute_file(os.path.join(sys_path, fn)) and
|
|
|
fea5c0 |
- fn in self)
|
|
|
fea5c0 |
+ for filename in os.listdir(sys_path):
|
|
|
fea5c0 |
+ filepath = os.path.join(sys_path, filename)
|
|
|
fea5c0 |
+ if _is_attribute_file(filepath):
|
|
|
fea5c0 |
+ yield filename
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def __len__(self):
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
Return the amount of attributes defined.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- i = 0
|
|
|
fea5c0 |
- for i, _ in enumerate(self._attributes, start=1):
|
|
|
fea5c0 |
- pass
|
|
|
fea5c0 |
- return i
|
|
|
fea5c0 |
+ return sum(1 for _ in self._get_attributes())
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def __iter__(self):
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
@@ -906,10 +908,10 @@ class Attributes(Mapping):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
Yield each attribute name as unicode string.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- return self._attributes
|
|
|
fea5c0 |
+ return self._get_attributes()
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def __contains__(self, attribute):
|
|
|
fea5c0 |
- value = libudev.udev_device_get_sysattr_value(
|
|
|
fea5c0 |
+ value = self._libudev.udev_device_get_sysattr_value(
|
|
|
fea5c0 |
self.device, ensure_byte_string(attribute))
|
|
|
fea5c0 |
return value is not None
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@@ -924,7 +926,7 @@ class Attributes(Mapping):
|
|
|
fea5c0 |
:exc:`~exceptions.KeyError`, if the given attribute is not defined
|
|
|
fea5c0 |
for this device.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- value = libudev.udev_device_get_sysattr_value(
|
|
|
fea5c0 |
+ value = self._libudev.udev_device_get_sysattr_value(
|
|
|
fea5c0 |
self.device, ensure_byte_string(attribute))
|
|
|
fea5c0 |
if value is None:
|
|
|
fea5c0 |
raise KeyError(attribute)
|
|
|
fea5c0 |
diff --git a/pyudev/monitor.py b/pyudev/monitor.py
|
|
|
fea5c0 |
index 8153ecc..6a51564 100644
|
|
|
fea5c0 |
--- a/pyudev/monitor.py
|
|
|
fea5c0 |
+++ b/pyudev/monitor.py
|
|
|
fea5c0 |
@@ -36,7 +36,6 @@ import select
|
|
|
fea5c0 |
from threading import Thread
|
|
|
fea5c0 |
from contextlib import closing
|
|
|
fea5c0 |
|
|
|
fea5c0 |
-from pyudev._libudev import libudev
|
|
|
fea5c0 |
from pyudev._util import ensure_byte_string, ensure_unicode_string, reraise
|
|
|
fea5c0 |
|
|
|
fea5c0 |
from pyudev.core import Device
|
|
|
fea5c0 |
@@ -82,6 +81,7 @@ class Monitor(object):
|
|
|
fea5c0 |
self.context = context
|
|
|
fea5c0 |
self._as_parameter_ = monitor_p
|
|
|
fea5c0 |
self._socket_path = socket_path
|
|
|
fea5c0 |
+ self._libudev = context._libudev
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def _reraise_with_socket_path(self):
|
|
|
fea5c0 |
_, exc_value, traceback = sys.exc_info()
|
|
|
fea5c0 |
@@ -89,7 +89,7 @@ class Monitor(object):
|
|
|
fea5c0 |
reraise(exc_value, traceback)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def __del__(self):
|
|
|
fea5c0 |
- libudev.udev_monitor_unref(self)
|
|
|
fea5c0 |
+ self._libudev.udev_monitor_unref(self)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@classmethod
|
|
|
fea5c0 |
def from_netlink(cls, context, source='udev'):
|
|
|
fea5c0 |
@@ -117,7 +117,7 @@ class Monitor(object):
|
|
|
fea5c0 |
if source not in ('kernel', 'udev'):
|
|
|
fea5c0 |
raise ValueError('Invalid source: {0!r}. Must be one of "udev" '
|
|
|
fea5c0 |
'or "kernel"'.format(source))
|
|
|
fea5c0 |
- monitor = libudev.udev_monitor_new_from_netlink(
|
|
|
fea5c0 |
+ monitor = context._libudev.udev_monitor_new_from_netlink(
|
|
|
fea5c0 |
context, ensure_byte_string(source))
|
|
|
fea5c0 |
if not monitor:
|
|
|
fea5c0 |
raise EnvironmentError('Could not create udev monitor')
|
|
|
fea5c0 |
@@ -140,7 +140,7 @@ class Monitor(object):
|
|
|
fea5c0 |
socket. Raise :exc:`~exceptions.EnvironmentError`, if the creation of
|
|
|
fea5c0 |
the monitor failed.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- monitor = libudev.udev_monitor_new_from_socket(
|
|
|
fea5c0 |
+ monitor = context._libudev.udev_monitor_new_from_socket(
|
|
|
fea5c0 |
context, ensure_byte_string(socket_path))
|
|
|
fea5c0 |
if not monitor:
|
|
|
fea5c0 |
raise EnvironmentError('Could not create monitor for socket: '
|
|
|
fea5c0 |
@@ -154,7 +154,7 @@ class Monitor(object):
|
|
|
fea5c0 |
This is really a real file descriptor ;), which can be watched and
|
|
|
fea5c0 |
:func:`select.select`\ ed.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- return libudev.udev_monitor_get_fd(self)
|
|
|
fea5c0 |
+ return self._libudev.udev_monitor_get_fd(self)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def filter_by(self, subsystem, device_type=None):
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
@@ -179,9 +179,9 @@ class Monitor(object):
|
|
|
fea5c0 |
subsystem = ensure_byte_string(subsystem)
|
|
|
fea5c0 |
if device_type:
|
|
|
fea5c0 |
device_type = ensure_byte_string(device_type)
|
|
|
fea5c0 |
- libudev.udev_monitor_filter_add_match_subsystem_devtype(
|
|
|
fea5c0 |
+ self._libudev.udev_monitor_filter_add_match_subsystem_devtype(
|
|
|
fea5c0 |
self, subsystem, device_type)
|
|
|
fea5c0 |
- libudev.udev_monitor_filter_update(self)
|
|
|
fea5c0 |
+ self._libudev.udev_monitor_filter_update(self)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def filter_by_tag(self, tag):
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
@@ -202,9 +202,9 @@ class Monitor(object):
|
|
|
fea5c0 |
.. versionchanged:: 0.15
|
|
|
fea5c0 |
This method can also be after :meth:`enable_receiving()` now
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- libudev.udev_monitor_filter_add_match_tag(
|
|
|
fea5c0 |
+ self._libudev.udev_monitor_filter_add_match_tag(
|
|
|
fea5c0 |
self, ensure_byte_string(tag))
|
|
|
fea5c0 |
- libudev.udev_monitor_filter_update(self)
|
|
|
fea5c0 |
+ self._libudev.udev_monitor_filter_update(self)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def remove_filter(self):
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
@@ -223,8 +223,8 @@ class Monitor(object):
|
|
|
fea5c0 |
|
|
|
fea5c0 |
.. versionadded:: 0.15
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
- libudev.udev_monitor_filter_remove(self)
|
|
|
fea5c0 |
- libudev.udev_monitor_filter_update(self)
|
|
|
fea5c0 |
+ self._libudev.udev_monitor_filter_remove(self)
|
|
|
fea5c0 |
+ self._libudev.udev_monitor_filter_update(self)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def enable_receiving(self):
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
@@ -240,7 +240,7 @@ class Monitor(object):
|
|
|
fea5c0 |
monitor.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
try:
|
|
|
fea5c0 |
- libudev.udev_monitor_enable_receiving(self)
|
|
|
fea5c0 |
+ self._libudev.udev_monitor_enable_receiving(self)
|
|
|
fea5c0 |
except EnvironmentError:
|
|
|
fea5c0 |
self._reraise_with_socket_path()
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@@ -272,7 +272,7 @@ class Monitor(object):
|
|
|
fea5c0 |
.. _python-prctl: http://packages.python.org/python-prctl
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
try:
|
|
|
fea5c0 |
- libudev.udev_monitor_set_receive_buffer_size(self, size)
|
|
|
fea5c0 |
+ self._libudev.udev_monitor_set_receive_buffer_size(self, size)
|
|
|
fea5c0 |
except EnvironmentError:
|
|
|
fea5c0 |
self._reraise_with_socket_path()
|
|
|
fea5c0 |
|
|
|
fea5c0 |
@@ -301,13 +301,13 @@ class Monitor(object):
|
|
|
fea5c0 |
read.
|
|
|
fea5c0 |
"""
|
|
|
fea5c0 |
try:
|
|
|
fea5c0 |
- device_p = libudev.udev_monitor_receive_device(self)
|
|
|
fea5c0 |
+ device_p = self._libudev.udev_monitor_receive_device(self)
|
|
|
fea5c0 |
except EnvironmentError:
|
|
|
fea5c0 |
self._reraise_with_socket_path()
|
|
|
fea5c0 |
if not device_p:
|
|
|
fea5c0 |
raise EnvironmentError('Could not receive device')
|
|
|
fea5c0 |
action = ensure_unicode_string(
|
|
|
fea5c0 |
- libudev.udev_device_get_action(device_p))
|
|
|
fea5c0 |
+ self._libudev.udev_device_get_action(device_p))
|
|
|
fea5c0 |
return action, Device(self.context, device_p)
|
|
|
fea5c0 |
|
|
|
fea5c0 |
def __iter__(self):
|