ó
`ï}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 l	 Z d d d „  ƒ  YZ
 d „  Z d S(   iÿÿÿÿNt   Descriptionsc           B   sS   e  Z d  „  Z d „  Z d d „ Z d „  Z d „  Z e sH d „  Z n  d „  Z	 RS(   c         C   s´   t  d d d t  d d d d d d d d	 d
 d ƒ g ƒ } t sC | St t d ƒ sV | St j j d ƒ } t j j	 | ƒ s~ | St  d | d d ƒ g | d <t j j
 | ƒ | 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    t   prefixest   idxt   Zt   qpt   typet   descs   Stemmed forms of keywordst   ldescsd   This contains the stemmed forms of keywords as generated by TermGenerator and matched by QueryParsert   configs   Dir::Cache::pkgcachet   paths	   APT indext   sourcesN(   t   dictt   Nonet   HAS_APTt   hasattrt   apt_pkgR	   t	   find_filet   osR
   t   existst   getmtime(   t   selft   rest   fname(    (    s3   /usr/share/apt-xapian-index/plugins/descriptions.pyt   info   s       c         C   s8   t  j d ƒ |  _ t  j ƒ  |  _ |  j j |  j ƒ 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.
        t   englishN(   t   xapiant   Stemt   stemmert   TermGeneratort   indexert   set_stemmer(   R   R   t   progress(    (    s3   /usr/share/apt-xapian-index/plugins/descriptions.pyt   init/   s    c         K   s9   | d k	 r5 |  j j t j j ƒ |  j j | ƒ n  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
        N(   R   R   t	   set_flagsR   R   t   FLAG_SPELLINGt   set_database(   R   t   dbt   kw(    (    s3   /usr/share/apt-xapian-index/plugins/descriptions.pyt   send_extra_info>   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 descriptionst	   shortDescsJ   terms extracted from the package descriptions using Xapian's TermGeneratort   fullDocs   
            The Descriptions data source simply uses Xapian's TermGenerator to
            tokenise and index the package descriptions.

            Currently this creates normal terms as well as stemmed terms
            prefixed with ``Z``.
            (   R   (   R   (    (    s3   /usr/share/apt-xapian-index/plugins/descriptions.pyt   docJ   s    	c         C   sR   |  j  j | ƒ |  j  j | j ƒ | j } | d k	 rN |  j  j | j ƒ n  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   set_documentt   index_text_without_positionsR(   t	   candidateR   t   raw_description(   R   t   documentt   pkgt   version(    (    s3   /usr/share/apt-xapian-index/plugins/descriptions.pyt   index_   s
    	c         C   s   d  S(   N(    (   R   R0   R1   (    (    s3   /usr/share/apt-xapian-index/plugins/descriptions.pyR3   n   s    c         C   s‰   |  j  j | ƒ |  j  j | d ƒ d | k rG |  j  j | d ƒ n> x; | j ƒ  D]- } | j d ƒ rT |  j  j | | ƒ PqT qT 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
        t   Packaget   Descriptions   Description-N(   R   R,   R-   t   keyst
   startswith(   R   R0   R1   t   k(    (    s3   /usr/share/apt-xapian-index/plugins/descriptions.pyt   indexDeb822q   s    
N(
   t   __name__t
   __module__R   R!   R   R'   R+   R3   R   R9   (    (    (    s3   /usr/share/apt-xapian-index/plugins/descriptions.pyR       s   	#			c          K   s   t  ƒ  S(   s.   
    Create and return the plugin object.
    (   R    (   R&   (    (    s3   /usr/share/apt-xapian-index/plugins/descriptions.pyR!   ‰   s    (    (   t   aptR   t   TrueR   t   ImportErrort   FalseR   t   reR   t   os.pathR    R!   (    (    (    s3   /usr/share/apt-xapian-index/plugins/descriptions.pyt   <module>   s   

~