PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB` 3 u1W,@sdZddlmZddlmZddlmZddlmZddlZddlZddlZddl Z ddl Z ddl m Z ddl m Z d d Ze jejGd d d eZGd ddeZGdddeZGdddeZGdddeZGdddeZdS)z pyudev.discover =============== Tools to discover a device given limited information. .. moduleauthor:: mulhern )absolute_import)division)print_function)unicode_literalsN)Devices)DeviceNotFoundErrorcstjfdd}|S)z\ Allow Device discovery methods to return None instead of raising an exception. c s$y ||Stk rdSXdS)z Returns result of calling ``func`` on ``args``, ``kwargs``. Returns None if ``func`` raises :exc:`DeviceNotFoundError`. N)r)argskwargs)func/usr/lib/python3.6/discover.pythe_func1s z wrap_exception..the_func) functoolswraps)r r r )r r wrap_exception+s rc@sLeZdZdZeejddZeejddZeddZ edd Z d S) HypothesiszM Represents a hypothesis about the meaning of the device identifier. cCs tdS)a Match the given string according to the hypothesis. The purpose of this method is to obtain a value corresponding to ``value`` if that is possible. It may use a regular expression, but in general it should just return ``value`` and let the lookup method sort out the rest. :param str value: the string to inspect :returns: the matched thing or None if unmatched :rtype: the type of lookup's key parameter or NoneType N)NotImplementedError)clsvaluer r r matchDszHypothesis.matchcCs tdS)aN Lookup the given string according to the hypothesis. :param Context context: the pyudev context :param key: a key with which to lookup the device :type key: the type of match's return value if not None :returns: a list of Devices obtained :rtype: frozenset of :class:`Device` N)r)rcontextkeyr r r lookupUs zHypothesis.lookupcCsdS)z A potentially expensive method that may allow an :class:`Hypothesis` to find devices more rapidly or to find a device that it would otherwise miss. :param Context context: the pyudev context Nr )rrr r r setupcs zHypothesis.setupcCs$|j|}|dk r|j||StS)a Get any devices that may correspond to the given string. :param Context context: the pyudev context :param str value: the value to look for :returns: a list of devices obtained :rtype: set of :class:`Device` N)rr frozenset)rrrrr r r get_devicesns zHypothesis.get_devicesN) __name__ __module__ __qualname____doc__ classmethodabcabstractmethodrrrrr r r r r>s rc@sLeZdZdZeddZeddZeddZedd Zed d Z d S) DeviceNumberHypothesisz Represents the hypothesis that the device is a device number. The device may be separated into major/minor number or a composite number. cCs8tjd}|j|}|o6tjt|jdt|jdS)z Match the number under the assumption that it is a major,minor pair. :param str value: value to match :returns: the device number or None :rtype: int or NoneType z#^(?P\d+)(\D+)(?P\d+)$majorminor)recompilerosmakedevintgroup)rrZmajor_minor_rerr r r _match_major_minors   z)DeviceNumberHypothesis._match_major_minorcCs&tjd}|j|}|o$t|jdS)z Match the number under the assumption that it is a single number. :param str value: value to match :returns: the device number or None :rtype: int or NoneType z^(?P\d+)$Znumber)r&r'rr*r+)rrZ number_rerr r r _match_numbers  z$DeviceNumberHypothesis._match_numbercCs|j|p|j|S)z Match the number under the assumption that it is a device number. :returns: the device number or None :rtype: int or NoneType )r,r-)rrr r r rszDeviceNumberHypothesis.matchcCs|j}tjtjj|dS)z Find subsystems in /sys/dev. :param Context context: the context :returns: a lis of available subsystems :rtype: list of str Zdev)sys_pathr(listdirpathjoin)rrr.r r r find_subsystemss z&DeviceNumberHypothesis.find_subsystemscs8ttjfdd|jD}tdd|DS)z Lookup by the device number. :param Context context: the context :param int key: the device number :returns: a list of matching devices :rtype: frozenset of :class:`Device` c3s|]}|VqdS)Nr ).0s)rr rr r sz0DeviceNumberHypothesis.lookup..css|]}|dk r|VqdS)Nr )r3rr r r r5s)rrZfrom_device_numberr2r)rrrresr )rr rr rs zDeviceNumberHypothesis.lookupN) rrrrr r,r-rr2rr r r r r#|s   r#c@s(eZdZdZeddZeddZdS)DevicePathHypothesiszG Discover the device assuming the identifier is a device path. cCs|S)z Match ``value`` under the assumption that it is a device path. :returns: the device path or None :rtype: str or NoneType r )rrr r r rszDevicePathHypothesis.matchcCs(ttj||}|dk r"t|fStS)z Lookup by the path. :param Context context: the context :param str key: the device path :returns: a list of matching devices :rtype: frozenset of :class:`Device` N)rrZ from_pathr)rrrr7r r r rs zDevicePathHypothesis.lookupN)rrrrr rrr r r r r8s r8c@s4eZdZdZeddZeddZeddZdS) DeviceNameHypothesiszf Discover the device assuming the input is a device name. Try every available subsystem. cs<|jd}fdd|D}dd|D}tdd|DS) z Find all subsystems in sysfs. :param Context context: the context :rtype: frozenset :returns: subsystems in sysfs busclass subsystemc3s|]}tjj|VqdS)N)r(r0r1)r3name)r.r r r5sz7DeviceNameHypothesis.find_subsystems..css|]}tjj|r|VqdS)N)r(r0isdir)r3dr r r r5scss"|]}tj|D] }|VqqdS)N)r(r/)r3r?nr r r r5s)r:r;r<)r.r)rrZdirnamesZabsnamesZ realnamesr )r.r r2s z$DeviceNameHypothesis.find_subsystemscCs|S)z Match ``value`` under the assumption that it is a device name. :returns: the device path or None :rtype: str or NoneType r )rrr r r rszDeviceNameHypothesis.matchcs8ttjfdd|jD}tdd|DS)z Lookup by the path. :param Context context: the context :param str key: the device path :returns: a list of matching devices :rtype: frozenset of :class:`Device` c3s|]}|VqdS)Nr )r3r4)rr rr r r5sz.DeviceNameHypothesis.lookup..css|]}|dk r|VqdS)Nr )r3r6r r r r5s)rr from_namer2r)rrrr7r )rr rr rs zDeviceNameHypothesis.lookupN)rrrrr r2rrr r r r r9s  r9c @sZeZdZdZdddddddd d d d g Zed dZeddZeddZeddZ dS)DeviceFileHypothesisz Discover the device assuming the value is some portion of a device file. The device file may be a link to a device node. z/devz/dev/disk/by-idz/dev/disk/by-labelz/dev/disk/by-partlabelz/dev/disk/by-partuuidz/dev/disk/by-pathz/dev/disk/by-uuidz/dev/input/by-pathz /dev/mapperz/dev/mdz/dev/vgcCs:|j}dd|D}dd|D}ttdd|DS)a7 Get all directories that may contain links to device nodes. This method checks the device links of every device, so it is very expensive. :param Context context: the context :returns: a sorted list of directories that contain device links :rtype: list css|]}t|jr|VqdS)N)list device_links)r3r?r r r r55sz5DeviceFileHypothesis.get_link_dirs..css|]}|jD] }|Vq qdS)N)rD)r3r?lr r r r56scss|]}tjj|VqdS)N)r(r0dirname)r3rEr r r r57s)Z list_devicessortedset)rrdevicesZdevices_with_linksZlinksr r r get_link_dirs(s z"DeviceFileHypothesis.get_link_dirscCs|j||_dS)z Set the link directories to be used when discovering by file. Uses `get_link_dirs`, so is as expensive as it is. :param Context context: the context N)rJ _LINK_DIRS)rrr r r r9s zDeviceFileHypothesis.setupcCs|S)Nr )rrr r r rDszDeviceFileHypothesis.matchcsrttjdkr4}|dk r.t|fStSfdd|jD}fdd|D}tdd|DSdS)a Lookup the device under the assumption that the key is part of the name of a device file. :param Context context: the context :param str key: a portion of the device file name It is assumed that either it is the whole name of the device file or it is the basename. A device file may be a device node or a device link. /Nc3s|]}tjj|VqdS)N)r(r0r1)r3Zld)rr r r5[sz.DeviceFileHypothesis.lookup..c3s|]}|VqdS)Nr )r3f)rr r r r5\scss|]}|dk r|VqdS)Nr )r3r?r r r r5]s)rrZfrom_device_filerrK)rrrZdevicefilesrIr )rr rr rHs  zDeviceFileHypothesis.lookupN) rrrrrKr rJrrrr r r r rBs   rBc@s4eZdZdZeeeegZddZ ddZ ddZ dS) Discoveryz1 Provides discovery methods for devices. cCs |j|_dS)N) _HYPOTHESES _hypotheses)selfr r r __init__mszDiscovery.__init__cCsx|jD]}|j|qWdS)z Set up individual hypotheses. May be an expensive call. :param Context context: the context N)rQr)rRrZhypr r r rps zDiscovery.setupcstfdd|jDS)z Get the devices corresponding to value. :param Context context: the context :param str value: some identifier of the device :returns: a list of corresponding devices :rtype: frozenset of :class:`Device` c3s$|]}|jD] }|VqqdS)N)r)r3hr?)rrr r r5sz(Discovery.get_devices..)rrQ)rRrrr )rrr r{s zDiscovery.get_devicesN) rrrrrBr9r#r8rPrSrrr r r r rO`s rO)rZ __future__rrrrr!rr(r&ZsixZ pyudev.devicerrrZ add_metaclassABCMetaobjectrr#r8r9rBrOr r r r s&      =K/M