ó
`ď}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   Sizesc           B   s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c      
   K   sČ   t  d d d t  d d d d  t  d d d d	  g  } | j d
 t  r t sU | 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    t   valuest   namet   installedsizet   descs   installed sizet   packagesizes   package sizet   systems   Dir::Cache::pkgcaches   (stdin)t   paths	   APT indext   sources(   t   dictt   gett   Truet   HAS_APTt   apt_pkgt   configt	   find_filet   osR   t   existst   getmtime(   t   selft   kwt   rest   filet   ts(    (    s,   /usr/share/apt-xapian-index/plugins/sizes.pyt   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
        R   R    t	   shortDescs   package sizes indexed as valuest   fullDocs§   
            The Sizes data source indexes the package size and the installed
            size as the ``packagesize`` and ``installedsize`` Xapian values.
            (   R
   (   R   (    (    s,   /usr/share/apt-xapian-index/plugins/sizes.pyt   doc0   s    	c         C   s8   | d } | j  d d  |  _ | j  d d  |  _ 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.
        R   R   i˙˙˙˙R   N(   R   t   val_inst_sizet   val_pkg_size(   R   R   t   progressR   (    (    s,   /usr/share/apt-xapian-index/plugins/sizes.pyt   initB   s    
c         C   s   | j  } | d k r d Sy | j } | j } Wn d SX|  j d k rh | j |  j t j |   n  |  j d k r | j |  j t 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
        Ni˙˙˙˙(	   t	   candidatet   Nonet   installed_sizet   sizeR   t	   add_valuet   xapiant   sortable_serialiseR   (   R   t   documentt   pkgt   vert   instSizet   pkgSize(    (    s,   /usr/share/apt-xapian-index/plugins/sizes.pyt   indexR   s    	 	c         C   s   y$ t  | d  } t  | d  } Wn d SX|  j d k r] | j |  j t j |   n  |  j d k r | j |  j t j |   n  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
        s   Installed-Sizet   SizeNi˙˙˙˙(   t   intR   R%   R&   R'   R   (   R   R(   R)   R+   R,   (    (    s,   /usr/share/apt-xapian-index/plugins/sizes.pyt   indexDeb822f   s    
(   t   __name__t
   __module__R   R   R    R-   R0   (    (    (    s,   /usr/share/apt-xapian-index/plugins/sizes.pyR    
   s
   	%			c           C   s   t    S(   s.   
    Create and return the plugin object.
    (   R    (    (    (    s,   /usr/share/apt-xapian-index/plugins/sizes.pyR    {   s    (    (   t   aptR   R   R   t   ImportErrort   FalseR&   R   t   os.pathR    R    (    (    (    s,   /usr/share/apt-xapian-index/plugins/sizes.pyt   <module>   s   

q