ó
`ï}Nc           @   s‚   d  d l  Z  d  d l Z d  d l Z y d  d l m Z Wn! e k
 r[ d  d l m Z n Xd Z d d d „  ƒ  YZ d „  Z	 d S(   iÿÿÿÿN(   t   debtagss   /var/lib/debtags/package-tagst   Debtagsc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s[   t  d t j j t ƒ d t  d t d d ƒ g d t  d d d	 d
 d d d d d d ƒ g ƒ 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   sourcest   patht   descs   Debtags tag informationt   prefixest   idxt   XTt   qps   tag:t   typet   bools   Debtags tagt   ldescs   Debtags package categories(   t   dictt   osR   t   getmtimet	   DEBTAGSDB(   t   self(    (    s.   /usr/share/apt-xapian-index/plugins/debtags.pyt   info   s    c            s^   | j  d ƒ t j ƒ  |  _ t j d ƒ ‰  |  j j t t d ƒ ‡  f d †  ƒ | 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.
        s   Reading Debtags databases   ^special::.+$|^.+::TODO$t   rc            s   ˆ  j  |  ƒ S(   N(   t   match(   t   x(   t	   tagFilter(    s.   /usr/share/apt-xapian-index/plugins/debtags.pyt   <lambda>7   s    N(
   t   beginR    t   DBt   dbt   ret   compilet   readt   openR   t   end(   R   R   t   progress(    (   R   s.   /usr/share/apt-xapian-index/plugins/debtags.pyt   init(   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   nameR   t	   shortDescs   Debtags tag informationt   fullDocs   
            The Debtags data source indexes Debtags tags as terms with the
            ``XT`` prefix; for example: 'XTrole::program'.

            Using the ``XT`` terms, queries can be enhanced with semantic
            information.  Xapian's support for complex expressions in queries
            can be used to great effect: for example::

                XTrole::program AND XTuse::gameplaying AND (XTinterface::x11 OR XTinterface::3d)

            ``XT`` terms can also be used to improve the quality of search
            results.  For example, the ``gimp`` package would not usually show
            up when searching the terms ``image editor``.  This can be solved
            using the following technique:

             1. Perform a normal query
             2. Put the first 5 or so results in an Rset
             3. Call Enquire::get_eset using the Rset and an expand filter that
                only accepts ``XT`` terms.  This gives you the tags that are
                most relevant to the query.
             4. Add the resulting terms to the initial query, and search again.

            The Debtags data source is provided by the ``debtags`` package.
            (   R   (   R   (    (    s.   /usr/share/apt-xapian-index/plugins/debtags.pyt   doc:   s    	c         C   s5   x. |  j  j | j ƒ D] } | j d | ƒ 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
        R   N(   R   t   tags_of_packageR"   t   add_term(   R   t   documentt   pkgt   tag(    (    s.   /usr/share/apt-xapian-index/plugins/debtags.pyt   index`   s    c         C   s6   x/ |  j  j | d ƒ D] } | j d | ƒ 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
        t   PackageR   N(   R   R&   R'   (   R   R(   R)   R*   (    (    s.   /usr/share/apt-xapian-index/plugins/debtags.pyt   indexDeb822j   s    
(   t   __name__t
   __module__R   R!   R%   R+   R-   (    (    (    s.   /usr/share/apt-xapian-index/plugins/debtags.pyR      s
   			&	
c          K   s   t  j j t ƒ s d St ƒ  S(   s.   
    Create and return the plugin object.
    N(   R   R   t   existsR   t   NoneR   (   t   kw(    (    s.   /usr/share/apt-xapian-index/plugins/debtags.pyR!   w   s    (    (
   R   R   t   os.patht   debianR    t   ImportErrort   debian_bundleR   R   R!   (    (    (    s.   /usr/share/apt-xapian-index/plugins/debtags.pyt   <module>   s   $l