ó
`ï}Nc           @   sh   d  d l  Z  d  d l Z d  d l Z e j j d d ƒ Z d d „ Z d d d „  ƒ  YZ d d „ Z	 d S(	   iÿÿÿÿNt   AXI_ALIASESsC   /etc/apt-xapian-index/aliases/:/usr/share/apt-xapian-index/aliases/c         C   sž  g  } d } g  } x|t  j d ƒ D]k} t j j | ƒ s@ q" n  xJt j | ƒ D]9} | d d k rl qP n  t j j | | ƒ } t j j | ƒ } | | k r¨ | } n  |  rÂ |  j d | ƒ n  t	 d | ƒ } x˜ t
 t | ƒ ƒ D]„ \ }	 }
 |
 j ƒ  }
 |	 d k r2|
 d d k r2|
 d j ƒ  | d <qä n  |
 sä |
 d d k rOqä n  |
 j ƒ  }
 | j |
 ƒ qä W| j d d	 ƒ | j | ƒ qP Wq" W| | | f S(
   Ni    t   :t   .s   Reading aliases from %s...t   patht   #i   t   descs   synonyms for well-known terms(   R    t   splitt   osR   t   isdirt   listdirt   joint   getmtimet   verboset   dictt	   enumeratet   opent   stript   appendt
   setdefault(   t   progresst   aliasest   maxtst   filest   dt   ft   fnamet   tst   infot   idxt   line(    (    s.   /usr/share/apt-xapian-index/plugins/aliases.pyt   read_db   s8      	  t   Aliasesc           B   sJ   e  Z d  „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z	 RS(   c         C   s   | |  _  | |  _ | |  _ d  S(   N(   R   t   dbR   (   t   selfR   R    R   (    (    s.   /usr/share/apt-xapian-index/plugins/aliases.pyt   __init__#   s    		c         C   s   t  d |  j d |  j ƒ 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	   timestampt   sources(   R   R   R   (   R!   (    (    s.   /usr/share/apt-xapian-index/plugins/aliases.pyR   (   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   R   (    (    s.   /usr/share/apt-xapian-index/plugins/aliases.pyt   init<   s    c         K   sP   | d k	 rL x= |  j D]/ } x& | d D] } | j | d | ƒ q' Wq Wn  d S(   s²   
        Receive extra parameters from the indexer.

        This may be called more than once, but after init().

        We are using this to get the database instance
        i   i    N(   t   NoneR    t   add_synonym(   R!   R    t   kwt   rowt   a(    (    s.   /usr/share/apt-xapian-index/plugins/aliases.pyt   send_extra_infoI   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 aliasest	   shortDescs   aliases for well known programst   fullDocs"  
            The Aliases data source does not change documents in the index, but
            adds synonims to the database. Synonims allow to obtain good
            results while looking for well-know software names, even if such
            software does not exist in Debian.
            (   R   (   R!   (    (    s.   /usr/share/apt-xapian-index/plugins/aliases.pyt   docV   s    	c         C   s   d 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(    (   R!   t   documentt   pkg(    (    s.   /usr/share/apt-xapian-index/plugins/aliases.pyt   indexj   s    c         C   s   d 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!   R0   R1   (    (    s.   /usr/share/apt-xapian-index/plugins/aliases.pyt   indexDeb822s   s    
N(
   t   __name__t
   __module__R"   R   R%   R&   R+   R/   R2   R3   (    (    (    s.   /usr/share/apt-xapian-index/plugins/aliases.pyR   "   s   						c         K   s/   t  |  ƒ \ } } } | s d St | | | ƒ S(   s.   
    Create and return the plugin object.
    N(   R   R&   R   (   R   R(   R   R    R   (    (    s.   /usr/share/apt-xapian-index/plugins/aliases.pyR%      s     (    (
   t   xapianR   t   os.patht   environt   getR    R&   R   R   R%   (    (    (    s.   /usr/share/apt-xapian-index/plugins/aliases.pyt   <module>   s
   ]