ó
N_c           @   s®   d  Z  d d l Z d d l m Z m Z m Z d Z d Z d Z d Z	 d Z
 i d	 e 6d
 e 6d e	 6d e
 6Z d d d „  ƒ  YZ d d d „  ƒ  YZ d e f d „  ƒ  YZ d S(   s'   Classes for handling various callbacks.iÿÿÿÿN(   t	   BaseMetert   format_timet   format_numberi
   i   i   i   i(   s   Downloading Packagess   Check Package Signaturess   Running Test Transactions   Running Transactiont   ProcessTransBaseCallbackc           B   s#   e  Z d  Z d „  Z d d „ Z RS(   sM   A class to handle callbacks from
    :func:`YumBase.processTransaction`.
    c         C   s   t  j d ƒ |  _ d  S(   Ns)   yum.verbose.ProcessTrasactionBaseCallback(   t   loggingt	   getLoggert   logger(   t   self(    (    s1   /usr/lib/python2.7/site-packages/yum/callbacks.pyt   __init__+   s    c         C   s-   | t  j ƒ  k r) |  j j t  | ƒ n  d S(   sž   Handle an event by logging it.

        :param state: a number indicating the type of callback
        :param data: data associated with the callback
        N(   t   PT_MESSAGESt   keysR   t   info(   R   t   statet   data(    (    s1   /usr/lib/python2.7/site-packages/yum/callbacks.pyt   event.   s    N(   t   __name__t
   __module__t   __doc__R   t   NoneR   (    (    (    s1   /usr/lib/python2.7/site-packages/yum/callbacks.pyR   '   s   	t   ProcessTransNoOutputCallbackc           B   s#   e  Z d  Z d „  Z d d „ Z RS(   sc   A class to handle callbacks from
    :func:`YumBase.processTransaction`, without logging them.
    c         C   s   d  S(   N(    (   R   (    (    s1   /usr/lib/python2.7/site-packages/yum/callbacks.pyR   ;   s    c         C   s   d S(   s   Handle an event.

        :param state: a number indicating the type of callback
        :param data: data associated with the callback
        N(    (   R   R   R   (    (    s1   /usr/lib/python2.7/site-packages/yum/callbacks.pyR   >   s    N(   R   R   R   R   R   R   (    (    (    s1   /usr/lib/python2.7/site-packages/yum/callbacks.pyR   7   s   	t   DownloadBaseCallbackc           B   sY   e  Z d  Z d „  Z d d „ Z d d „ Z d d „ Z d d „ Z d „  Z	 d „  Z
 RS(	   sô  This is a base class that can be extended to implement a custom
    download progress handler to be used with
    :func:`YumBase.repos.setProgressBar`.
    
    Example::
    
       from yum.callbacks import DownloadBaseCallback
       
       class MyDownloadCallback(  DownloadBaseCallback ):
   
           def updateProgress(self,name,frac,fread,ftime):
               '''
               Update the progressbar
               @param name: filename
               @param frac: Progress fracment (0 -> 1)
               @param fread: formated string containing BytesRead
               @param ftime : formated string containing remaining or elapsed time
               '''
               pct = int( frac*100 )
               print " %s : %s " % (name,pct)
   
   
       if __name__ == '__main__':
           my = YumBase()
           my.doConfigSetup()
           dnlcb = MyDownloadCallback()
           my.repos.setProgressBar( dnlcb )
           for pkg in my.pkgSack:
               print pkg.name
       c         C   s   t  j |  ƒ d |  _ d  S(   Nt    (   R    R   t   totSize(   R   (    (    s1   /usr/lib/python2.7/site-packages/yum/callbacks.pyR   e   s    c         C   s   t  j |  | | ƒ d S(   s  Update the status bar.

        :param amount_read: the amount of data, in bytes, that has been read
        :param now: the current time in seconds since the epoch.  If
           *now* is not given, the output of :func:`time.time()` will
           be used.
        N(   R    t   update(   R   t   amount_readt   now(    (    s1   /usr/lib/python2.7/site-packages/yum/callbacks.pyR   i   s    c         C   sJ   |  j  ƒ  } |  j | d d d ƒ |  j d  k	 rF t |  j ƒ |  _ n  d  S(   Ng        R   (   t   _getNamet   updateProgresst   sizeR   R   R   (   R   R   t   name(    (    s1   /usr/lib/python2.7/site-packages/yum/callbacks.pyt	   _do_starts   s    c   
      C   s¥   t  | ƒ } |  j ƒ  } |  j d  k ra |  j j ƒ  } t | ƒ } d } |  j | | | | ƒ n@ |  j j ƒ  } t | ƒ }	 |  j j	 ƒ  } |  j | | | |	 ƒ d  S(   Ng        (
   R   R   R   R   t   ret   elapsed_timeR   R   t   remaining_timet   fraction_read(
   R   R   R   t   freadR   t   etimet   fetimet   fract   rtimet   frtime(    (    s1   /usr/lib/python2.7/site-packages/yum/callbacks.pyt
   _do_updatey   s    c         C   sG   t  |  j j ƒ  ƒ } t | ƒ } |  j ƒ  } |  j | d | | ƒ d  S(   Ng      ð?(   R   R   R    R   R   R   (   R   R   R   t
   total_timet
   total_sizeR   (    (    s1   /usr/lib/python2.7/site-packages/yum/callbacks.pyt   _do_endŠ   s    c         C   s=   |  j  r0 t |  j  ƒ t d ƒ k r0 |  j  } n	 |  j } | S(   s>   
        Get the name of the package being downloaded
        R   (   t   textt   typet   basename(   R   R   (    (    s1   /usr/lib/python2.7/site-packages/yum/callbacks.pyR      s    $	c         C   s   d S(   sÇ  Update the progressbar.  This method should be overridden
        by subclasses to implement the handler.

        :param name: the name of the filed being downloaded
        :param frac: number between 0 and 1 representing the fraction
            fraction of the file that has been downloaded
        :param fread: formatted string containing the number of bytes read
        :param ftime: formatted string containing remaining or elapsed time

        N(    (   R   R   R&   R#   t   ftime(    (    s1   /usr/lib/python2.7/site-packages/yum/callbacks.pyR   š   s    N(   R   R   R   R   R   R   R   R)   R,   R   R   (    (    (    s1   /usr/lib/python2.7/site-packages/yum/callbacks.pyR   F   s   	
	
(    (    (   R   R   t   urlgrabber.progressR    R   R   t   PT_DOWNLOADt   PT_DOWNLOAD_PKGSt   PT_GPGCHECKt   PT_TEST_TRANSt   PT_TRANSACTIONR	   R   R   R   (    (    (    s1   /usr/lib/python2.7/site-packages/yum/callbacks.pyt   <module>   s   

