ó
È”Mc           @   se   d  d l  m Z d  d l m Z d  d l Td  d l Z d  d l Z d „  Z d e f d „  ƒ  YZ	 d S(   iÿÿÿÿ(   t   globdistance(   t   Provides(   t   *Nc         C   s<   |  j  d ƒ r |  d  }  n |  j  d ƒ r8 |  d  }  n  |  S(   Nt   $iÿÿÿÿs   \Z(?ms)iùÿÿÿ(   t   endswith(   t   pattern(    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyt	   _stripeol   s
    t   Searcherc           B   sé   e  Z d  Z d „  Z d „  Z d d „ Z d d „ Z d „  Z d „  Z	 d „  Z
 d	 „  Z d d
 „ Z d „  Z d d „ Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d d „ Z d „  Z d „  Z d „  Z RS(   sê  
    The search mechanism is smart is accessed mainly by giving a
    Searcher instance to the cache.search() method.
    
    Internally, the searching may go through different paths depending
    on the kind of information being looked for. More specifically:

    - nameversion is matched in Package.search(), so that backends
      may implement their own details in the searching mechanism.

    - provides is matched in Provides.search(), for the same reason.

    - requires, upgrades, and conflicts don't have special searching
      methods. Instead, their usual match() method is given an instance
      of the Provides type.

    - group, path, url, and other information which is found by
      PackageInfo, is searched by the Loader.search() method and
      the overloaded methods in Loader's subclasses. This ensures
      that Loaders are able to speedup the searching process, since
      many times it's necessary to access huge sequential files for
      looking up information.
    c         C   sp   i  |  _  g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _	 g  |  _
 t |  _ d  S(   N(   t   _resultst   nameversiont   providest   requirest   upgradest	   conflictst   patht   urlt   groupt   summaryt   descriptiont   Truet
   ignorecase(   t   self(    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyt   __init__<   s    											c         C   sW   |  j  j ƒ  |  j 2|  j 2|  j 2|  j 2|  j 2|  j 2|  j 2|  j	 2|  j
 2|  j 2d  S(   N(   R   t   clearR	   R
   R   R   R   R   R   R   R   R   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyt   resetJ   s    g      ð?c         C   s6   |  j  } | | k s% | | | k r2 | | | <n  d  S(   N(   R   (   R   t   objt   ratiot   results(    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyt	   addResultW   s    	c         C   s   |  j  j | | ƒ S(   N(   R   t   get(   R   R   t   default(    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyt	   getResult\   s    c         C   sD   |  j  } g  | D] } | | | f ^ q } | j ƒ  | j ƒ  | S(   N(   R   t   sortt   reverse(   R   R   R   t   lst(    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyt
   getResults_   s
    	#

c         C   s„   |  j  } g  | D] } | | | f ^ q } | r€ | j ƒ  | j ƒ  | d d } g  | D] } | d | k r[ | ^ q[ } n  | S(   Ni    (   R   R    R!   (   R   R   R   R"   t   bestt   x(    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyt   getBestResultsf   s    	#

,c         C   s(   x! | j  ƒ  D] } | j |  ƒ q Wd  S(   N(   t
   getLoaderst   search(   R   t   cachet   loader(    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyt   searchCachep   s    c         C   s   | j  |  ƒ d  S(   N(   R(   (   R   t   pkg(    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyt   searchPackaget   s    c         C   sí  | s
 d  S| j  d ƒ r0 |  j | d | ƒ n¹| j  d ƒ rS |  j | d ƒ n–| j  d ƒ rv |  j | d ƒ ns| j  d ƒ r™ |  j | d ƒ nP| j  d ƒ r¿ |  j | d | ƒ n*| j  d	 ƒ rå |  j | d
 | ƒ n| j  d ƒ r|  j | d ƒ ná | j  d ƒ r+|  j | d ƒ n¾ | j  d ƒ rN|  j	 | d ƒ n› | j  d ƒ rq|  j	 | d ƒ nx | j  d ƒ r—|  j
 | d
 | ƒ nR | d d k rº|  j | | ƒ n/ d | k rÙ|  j | | ƒ n |  j
 | | ƒ d  S(   Ns	   provides:i	   s	   requires:s	   upgrades:s
   conflicts:i
   s   url:i   s   path:i   s   group:i   s   summary:i   s   descr:s   description:i   s   name:i    t   /s   :/(   t
   startswitht   addProvidest   addRequirest   addUpgradest   addConflictst   addURLt   addPatht   addGroupt
   addSummaryt   addDescriptiont   addNameVersion(   R   t   st   cutoff(    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyt   addAutow   s:     c         C   sÅ   | oÄ | j  d ƒ pÄ | j  d ƒ pÄ | j  d ƒ pÄ | j  d ƒ pÄ | j  d ƒ pÄ | j  d ƒ pÄ | j  d ƒ pÄ | j  d ƒ pÄ | j  d	 ƒ pÄ | j  d
 ƒ pÄ | j  d ƒ pÄ | d d k pÄ d | k S(   Ns	   provides:s	   requires:s	   upgrades:s
   conflicts:s   url:s   path:s   group:s   summary:s   descr:s   description:s   name:i    R.   s   :/(   R/   (   R   R:   (    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyt   hasAutoMeaning–   s    c         C   s   |  j  j | | f ƒ d  S(   N(   R	   t   append(   R   R:   R;   (    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyR9   ¦   s    c         C   s&   |  j  j | j d d ƒ | f ƒ d  S(   Nt   =t   -(   R
   R>   t   replace(   R   R:   R;   (    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyR0   ©   s    c         C   sk   | j  d ƒ } t | ƒ d k r0 t | Œ  } n7 t | ƒ d k rX t | d d  ƒ } n t t d ƒ ‚ | S(   NR?   i   i   i    s   Invalid string(   t   splitt   lenR   t   Nonet   Errort   _(   R   R:   t   tokenst   prv(    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyt   _buildProvides¬   s    c         C   s   |  j  j |  j | ƒ ƒ d  S(   N(   R   R>   RI   (   R   R:   (    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyR1   ¶   s    c         C   s   |  j  j |  j | ƒ ƒ d  S(   N(   R   R>   RI   (   R   R:   (    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyR2   ¹   s    c         C   s   |  j  j |  j | ƒ ƒ d  S(   N(   R   R>   RI   (   R   R:   (    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyR3   ¼   s    c         C   s1   t  |  j p- |  j p- |  j p- |  j p- |  j ƒ S(   N(   t   boolR   R   R   R   R   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyt   needsPackageInfo¿   s    c         C   s   |  j  j | | f ƒ d  S(   N(   R   R>   (   R   R:   R;   (    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyR5   Ã   s    c         C   s   |  j  j | | f ƒ d  S(   N(   R   R>   (   R   R:   R;   (    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyR4   Æ   s    c         C   sh   t  t j | ƒ ƒ j d d ƒ } t j d j | j ƒ  ƒ |  j rK t j	 pN d ƒ } |  j
 j | ƒ d  S(   Ns   \ t    s   \s+i    (   R   t   fnmatcht	   translateRA   t   ret   compilet   joinRB   R   t   IR   R>   (   R   R:   t   p(    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyR6   É   s    !3c         C   sh   t  t j | ƒ ƒ j d d ƒ } t j d j | j ƒ  ƒ |  j rK t j	 pN d ƒ } |  j
 j | ƒ d  S(   Ns   \ RL   s   \s+i    (   R   RM   RN   RA   RO   RP   RQ   RB   R   RR   R   R>   (   R   R:   RS   (    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyR7   Î   s    !3c         C   sh   t  t j | ƒ ƒ j d d ƒ } t j d j | j ƒ  ƒ |  j rK t j	 pN d ƒ } |  j
 j | ƒ d  S(   Ns   \ RL   s   \s+i    (   R   RM   RN   RA   RO   RP   RQ   RB   R   RR   R   R>   (   R   R:   RS   (    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyR8   Ó   s    !3N(   t   __name__t
   __module__t   __doc__R   R   R   RD   R   R#   R&   R+   R-   R<   R=   R9   R0   RI   R1   R2   R3   RK   R5   R4   R6   R7   R8   (    (    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyR   #   s.   				
				
						(
   t   smart.util.strtoolsR    t   smart.cacheR   t   smartRM   RO   R   t   objectR   (    (    (    s2   /usr/lib/python2.7/dist-packages/smart/searcher.pyt   <module>   s   
	