ó
`ï}Nc           @   s€   y" d  d l  Z  d  d l Z e Z Wn e k
 r; e Z n Xd  d l Z d  d l Z d  d l Z d d d „  ƒ  YZ	 d „  Z
 d S(   iÿÿÿÿNt	   Relationsc           B   sG   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sY  t  d d d d d d d d d	 d
 ƒ t  d d d d d d d d d	 d ƒ t  d d d d d d d d d	 d ƒ t  d d d d d d d d d	 d ƒ t  d d d d d d d d d	 d ƒ t  d d d d d d d d d	 d ƒ t  d d d d  d d d d! d	 d" ƒ g |  _ g  |  j D]+ } | d | d	 | d	 j d# ƒ  f ^ q|  _ t j d$ ƒ |  _ d  S(%   Nt   idxt   XRDt   qps   reldep:t   typet   boolt   descs   Relation: dependst   ldescs)   Depends: relationship, package names onlyt   XRRs   relrec:s   Relation: recommendss,   Recommends: relationship, package names onlyt   XRSs   relsug:s   Relation: suggestss*   Suggests: relationship, package names onlyt   XREs   relenh:s   Relation: ehnancess*   Enhances: relationship, package names onlyt   XRPs   relpre:s   Relation: pre-dependss-   Pre-Depends: relationship, package names onlyt   XRBs   relbre:s   Relation: breakss(   Breaks: relationship, package names onlyt   XRCs   relcon:s   Relation: conflictss+   Conflicts: relationship, package names onlyt   :s
   \s*[|,]\s*(   t   dictt   prefix_desct   findt   prefixest   ret   compilet   re_split(   t   selft   d(    (    s0   /usr/share/apt-xapian-index/plugins/relations.pyt   __init__   s.    >c         K   s§   t  d d d |  j ƒ } | j d t ƒ rq t s4 | St j j d ƒ } t j	 j
 | ƒ s\ | St j	 j | ƒ } n d } d } t  d | d d	 ƒ g | d
 <| | d <| S(   sû  
        Return general information about the plugin.

        The information returned is a dict with various keywords:

         timestamp (required)
           the last modified timestamp of this data source.  This will be used
           to see if we need to update the database or not.  A timestamp of 0
           means that this data source is either missing or always up to date.
         values (optional)
           an array of dicts { name: name, desc: description }, one for every
           numeric value indexed by this data source.

        Note that this method can be called before init.  The idea is that, if
        the timestamp shows that this plugin is currently not needed, then the
        long initialisation can just be skipped.
        t	   timestampi    R   t   systems   Dir::Cache::pkgcaches   (stdin)t   pathR   s	   APT indext   sources(   R   R   t   gett   Truet   HAS_APTt   apt_pkgt   configt	   find_filet   osR   t   existst   getmtime(   R   t   kwt   rest   filet   ts(    (    s0   /usr/share/apt-xapian-index/plugins/relations.pyt   info&   s     
c         C   s   d S(   s5  
        If needed, perform long initialisation tasks here.

        info is a dictionary with useful information.  Currently it contains
        the following values:

          "values": a dict mapping index mnemonics to index numbers

        The progress indicator can be used to report progress.
        N(    (   R   R*   t   progress(    (    s0   /usr/share/apt-xapian-index/plugins/relations.pyt   initI   s    c         C   s   t  d d d d d d ƒ S(   s+  
        Return documentation information for this data source.

        The documentation information is a dictionary with these keys:
          name: the name for this data source
          shortDesc: a short description
          fullDoc: the full description as a chapter in ReST format
        t   names   Package relationshipst	   shortDescs   Debian package relationshipst   fullDocsj  
            Indexes one term per relationship declared with other packages. All
            relationship terms have prefixes starting with XR plus an extra
            prefix letter per relationship type.

            Terms are built using only the package names in the relationship
            fields: versioning and boolean operators are ignored.
            (   R   (   R   (    (    s0   /usr/share/apt-xapian-index/plugins/relations.pyt   docV   s    	c         C   sB   x; |  j  j | ƒ D]' } | j | | j d d ƒ d ƒ q Wd S(   sf   
        Extract all package names from @val and index them as terms with prefix
        @pfx
        i   i    N(   R   t   splitt   add_termt   None(   R   t   pfxt   valR0   R-   (    (    s0   /usr/share/apt-xapian-index/plugins/relations.pyt
   _index_rell   s    c         C   s‡   | j  } | d k r d S| j } | d k r2 d SxN |  j D]C \ } } | j | d ƒ } | d k rl q< n  |  j | | | ƒ q< Wd S(   sÂ   
        Update the document with the information from this data source.

        document  is the document to update
        pkg       is the python-apt Package object for this package
        N(   t	   candidateR3   t   recordR   R   R6   (   R   t   documentt   pkgt   vert   recR4   t   fieldR5   (    (    s0   /usr/share/apt-xapian-index/plugins/relations.pyt   indext   s    	 	  c         C   sU   xN |  j  D]C \ } } | j | d ƒ } | d k r: q
 n  |  j | | | ƒ q
 Wd S(   s7  
        Update the document with the information from this data source.

        This is alternative to index, and it is used when indexing with package
        data taken from a custom Packages file.

        document  is the document to update
        pkg       is the Deb822 object for this package
        N(   R   R   R3   R6   (   R   R9   R:   R4   R=   R5   (    (    s0   /usr/share/apt-xapian-index/plugins/relations.pyt   indexDeb822„   s
    
 (	   t   __name__t
   __module__R   R*   R,   R0   R6   R>   R?   (    (    (    s0   /usr/share/apt-xapian-index/plugins/relations.pyR    
   s   		#				c          K   s   t  ƒ  S(   s.   
    Create and return the plugin object.
    (   R    (   R&   (    (    s0   /usr/share/apt-xapian-index/plugins/relations.pyR,   “   s    (    (   t   aptR    R   R   t   ImportErrort   FalseR#   t   os.pathR   R    R,   (    (    (    s0   /usr/share/apt-xapian-index/plugins/relations.pyt   <module>   s   

‰