ݹYc@`sdZddlmZmZmZmZyddlmZWn!ek r_ddl mZnXddl m Z ddl m Z ddlmZmZmZmZddd gZd Zd efd YZd efdYZdS(u pyudev.core =========== Core types and functions of :mod:`pyudev`. .. moduleauthor:: Sebastian Wiesner i(tprint_functiontdivisiontunicode_literalstabsolute_import(t check_output(tDevice(tload_udev_library(tensure_unicode_stringtensure_byte_stringtudev_list_iteratetproperty_value_to_bytesu udev_versionuContextu EnumeratorcC`s(ttddg}t|jS(ul Get the version of the underlying udev library. udev doesn't use a standard major-minor versioning scheme, but instead labels releases with a single consecutive number. Consequently, the version number returned by this function is a single integer, and not a tuple (like for instance the interpreter version in :data:`sys.version_info`). As libudev itself does not provide a function to query the version number, this function calls the ``udevadm`` utilitiy, so be prepared to catch :exc:`~exceptions.EnvironmentError` and :exc:`~subprocess.CalledProcessError` if you call this function. Return the version number as single integer. Raise :exc:`~exceptions.ValueError`, if the version number retrieved from udev could not be converted to an integer. Raise :exc:`~exceptions.EnvironmentError`, if ``udevadm`` was not found, or could not be executed. Raise :exc:`subprocess.CalledProcessError`, if ``udevadm`` returned a non-zero exit code. On Python 2.7 or newer, the ``output`` attribute of this exception is correctly set. .. versionadded:: 0.8 uudevadmu --version(RRtinttstrip(toutput((s//usr/lib/python2.7/site-packages/pyudev/core.pyt udev_version.stContextcB`sweZdZdZdZedZedZedZedZ e j dZ dZ RS( u The udev context. This is *the* central object to access udev. An instance of this class must be created before anything else can be done. It holds the udev configuration and provides the interface to list devices (see :meth:`list_devices`). Instances of this class can directly be given as ``udev *`` to functions wrapped through :mod:`ctypes`. cC`s"t|_|jj|_dS(u' Create a new context. N(Rt_libudevtudev_newt_as_parameter_(tself((s//usr/lib/python2.7/site-packages/pyudev/core.pyt__init__Xs cC`s|jj|dS(N(Rt udev_unref(R((s//usr/lib/python2.7/site-packages/pyudev/core.pyt__del___scC`st|jj|S(u The ``sysfs`` mount point defaulting to ``/sys'`` as unicode string. The mount point can be overwritten using the environment variable :envvar:`SYSFS_PATH`. Use this for testing purposes. (RRtudev_get_sys_path(R((s//usr/lib/python2.7/site-packages/pyudev/core.pytsys_pathbscC`st|jj|S(u The device directory path defaulting to ``/dev`` as unicode string. This can be overridden in the udev configuration. (RRtudev_get_dev_path(R((s//usr/lib/python2.7/site-packages/pyudev/core.pyt device_pathlscC`st|jj|S(u The run runtime directory path defaulting to ``/run`` as unicode string. .. udevversion:: 167 .. versionadded:: 0.10 (RRtudev_get_run_path(R((s//usr/lib/python2.7/site-packages/pyudev/core.pytrun_pathus cC`s|jj|S(u  The logging priority of the interal logging facitility of udev as integer with a standard :mod:`syslog` priority. Assign to this property to change the logging priority. UDev uses the standard :mod:`syslog` priorities. Constants for these priorities are defined in the :mod:`syslog` module in the standard library: >>> import syslog >>> context = pyudev.Context() >>> context.log_priority = syslog.LOG_DEBUG .. versionadded:: 0.9 (Rtudev_get_log_priority(R((s//usr/lib/python2.7/site-packages/pyudev/core.pyt log_priorityscC`s|jj||dS(N(Rtudev_set_log_priority(Rtvalue((s//usr/lib/python2.7/site-packages/pyudev/core.pyRscK`st|j|S(u! List all available devices. The arguments of this method are the same as for :meth:`Enumerator.match()`. In fact, the arguments are simply passed straight to method :meth:`~Enumerator.match()`. This function creates and returns an :class:`Enumerator` object, that can be used to filter the list of devices, and eventually retrieve :class:`Device` objects representing matching devices. .. versionchanged:: 0.8 Accept keyword arguments now for easy matching (t Enumeratortmatch(Rtkwargs((s//usr/lib/python2.7/site-packages/pyudev/core.pyt list_devicess( t__name__t __module__t__doc__RRtpropertyRRRRtsetterR$(((s//usr/lib/python2.7/site-packages/pyudev/core.pyRKs      R!cB`sweZdZdZdZdZedZdZdZ edZ dZ d Z d Z d ZRS( u Enumerate all available devices. To retrieve devices, simply iterate over an instance of this class. This operation yields :class:`Device` objects representing the available devices. Before iteration the device list can be filtered by subsystem or by property values using :meth:`match_subsystem` and :meth:`match_property`. Multiple subsystem (property) filters are combined using a logical OR, filters of different types are combined using a logical AND. The following filter for instance:: devices.match_subsystem('block').match_property( 'ID_TYPE', 'disk').match_property('DEVTYPE', 'disk') means the following:: subsystem == 'block' and (ID_TYPE == 'disk' or DEVTYPE == 'disk') Once added, a filter cannot be removed anymore. Create a new object instead. Instances of this class can directly be given as given ``udev_enumerate *`` to functions wrapped through :mod:`ctypes`. cC`sLt|tstdn||_|jj||_|j|_dS(u Create a new enumerator with the given ``context`` (a :class:`Context` instance). While you can create objects of this class directly, this is not recommended. Call :method:`Context.list_devices()` instead. uInvalid context objectN(t isinstanceRt TypeErrortcontextRtudev_enumerate_newR(RR,((s//usr/lib/python2.7/site-packages/pyudev/core.pyRs  cC`s|jj|dS(N(Rtudev_enumerate_unref(R((s//usr/lib/python2.7/site-packages/pyudev/core.pyRscK`s|jdd}|dk r.|j|n|jdd}|dk r\|j|n|jdd}|dk r|j|n|jdd}|dk r|j|nx*|jD]\}}|j||qW|S(u3 Include devices according to the rules defined by the keyword arguments. These keyword arguments are interpreted as follows: - The value for the keyword argument ``subsystem`` is forwarded to :meth:`match_subsystem()`. - The value for the keyword argument ``sys_name`` is forwared to :meth:`match_sys_name()`. - The value for the keyword argument ``tag`` is forwared to :meth:`match_tag()`. - The value for the keyword argument ``parent`` is forwared to :meth:`match_parent()`. - All other keyword arguments are forwareded one by one to :meth:`match_property()`. The keyword argument itself is interpreted as property name, the value of the keyword argument as the property value. All keyword arguments are optional, calling this method without no arguments at all is simply a noop. Return the instance again. .. versionadded:: 0.8 .. versionchanged:: 0.13 Added ``parent`` keyword u subsystemusys_nameutaguparentN(tpoptNonetmatch_subsystemtmatch_sys_namet match_tagt match_parentt iteritemstmatch_property(RR#t subsystemtsys_namettagtparentR(R ((s//usr/lib/python2.7/site-packages/pyudev/core.pyR"s    cC`s5|s|jjn |jj}||t||S(u Include all devices, which are part of the given ``subsystem``. ``subsystem`` is either a unicode string or a byte string, containing the name of the subsystem. If ``nomatch`` is ``True`` (default is ``False``), the match is inverted: A device is only included if it is *not* part of the given ``subsystem``. Return the instance again. (Rt"udev_enumerate_add_match_subsystemt$udev_enumerate_add_nomatch_subsystemR(RR7tnomatchR"((s//usr/lib/python2.7/site-packages/pyudev/core.pyR1s  cC`s|jj|t||S(u Include all devices with the given name. ``sys_name`` is a byte or unicode string containing the device name. Return the instance again. .. versionadded:: 0.8 (Rt udev_enumerate_add_match_sysnameR(RR8((s//usr/lib/python2.7/site-packages/pyudev/core.pyR2s cC`s&|jj|t|t||S(u Include all devices, whose ``property`` has the given ``value``. ``property`` is either a unicode string or a byte string, containing the name of the property to match. ``value`` is a property value, being one of the following types: - :func:`int` - :func:`bool` - A byte string - Anything convertable to a unicode string (including a unicode string itself) Return the instance again. (Rt!udev_enumerate_add_match_propertyRR (RR(R ((s//usr/lib/python2.7/site-packages/pyudev/core.pyR6"s cC`s>|s|jjn |jj}||t|t||S(u Include all devices, whose ``attribute`` has the given ``value``. ``attribute`` is either a unicode string or a byte string, containing the name of a sys attribute to match. ``value`` is an attribute value, being one of the following types: - :func:`int`, - :func:`bool` - A byte string - Anything convertable to a unicode string (including a unicode string itself) If ``nomatch`` is ``True`` (default is ``False``), the match is inverted: A device is include if the ``attribute`` does *not* match the given ``value``. .. note:: If ``nomatch`` is ``True``, devices which do not have the given ``attribute`` at all are also included. In other words, with ``nomatch=True`` the given ``attribute`` is *not* guaranteed to exist on all returned devices. Return the instance again. (Rt udev_enumerate_add_match_sysattrt"udev_enumerate_add_nomatch_sysattrRR (Rt attributeR R=R"((s//usr/lib/python2.7/site-packages/pyudev/core.pytmatch_attribute6s   cC`s|jj|t||S(u Include all devices, which have the given ``tag`` attached. ``tag`` is a byte or unicode string containing the tag name. Return the instance again. .. udevversion:: 154 .. versionadded:: 0.6 (Rtudev_enumerate_add_match_tagR(RR9((s//usr/lib/python2.7/site-packages/pyudev/core.pyR3Xs cC`s|jj||S(u Include only devices, which are initialized. Initialized devices have properly set device node permissions and context, and are (in case of network devices) fully renamed. Currently this will not affect devices which do not have device nodes and are not network interfaces. Return the instance again. .. seealso:: :attr:`Device.is_initialized` .. udevversion:: 165 .. versionadded:: 0.8 (Rt'udev_enumerate_add_match_is_initialized(R((s//usr/lib/python2.7/site-packages/pyudev/core.pytmatch_is_initializedgscC`s|jj|||S(u  Include all devices on the subtree of the given ``parent`` device. The ``parent`` device itself is also included. ``parent`` is a :class:`~pyudev.Device`. Return the instance again. .. udevversion:: 172 .. versionadded:: 0.13 (Rtudev_enumerate_add_match_parent(RR:((s//usr/lib/python2.7/site-packages/pyudev/core.pyR4|scc`s]|jj||jj|}x4t|j|D] \}}tj|j|Vq5WdS(u\ Iterate over all matching devices. Yield :class:`Device` objects. N(Rtudev_enumerate_scan_devicestudev_enumerate_get_list_entryR Rt from_sys_pathR,(Rtentrytnamet_((s//usr/lib/python2.7/site-packages/pyudev/core.pyt__iter__s(R%R&R'RRR"tFalseR1R2R6RCR3RFR4RN(((s//usr/lib/python2.7/site-packages/pyudev/core.pyR!s   ,    "   N(R't __future__RRRRt subprocessRt ImportErrortpyudev._compatt pyudev.deviceRtpyudev._libudevRt pyudev._utilRRR R t__all__RtobjectRR!(((s//usr/lib/python2.7/site-packages/pyudev/core.pyts" " _