ó
N_c           @   sg   d  Z  d d l Z d d l Z d d l Z d d l Z d d l m Z d d l Td d d     YZ d S(   s=   
Progress display callback classes for the yum command line.
i˙˙˙˙N(   t   _(   t   *t   RPMInstallCallbackc           B   sS   e  Z d  Z d d  Z d   Z d   Z d   Z e d  Z d   Z	 d   Z
 RS(	   sC   Yum command line callback class for callbacks from the RPM library.i   c         C   s'  | |  _  i  |  _ d |  _ d |  _ g  |  _ d |  _ d |  _ d |  _ d  |  _	 t
 j d  |  _ t |  _ i t d  t 6t d  t 6t d  t 6t d  t 6t d  t 6t d  t 6|  _ i t d	  t 6t d
  t 6t d  t 6t d  t 6t d  t 6t d  t 6|  _ d  |  _ d  S(   Ni    t   #i   s"   yum.filelogging.RPMInstallCallbackt   Updatingt   Erasingt
   Installingt	   Obsoletedt   Updatedt   Erasedt	   Installed(   t   outputt   callbackfilehandlest   total_actionst   total_installedt   installed_pkg_namest   total_removedt   markt   markst   Nonet   lastmsgt   loggingt	   getLoggert   loggert   Falset   filelogR    t	   TS_UPDATEt   TS_ERASEt
   TS_INSTALLt   TS_TRUEINSTALLt   TS_OBSOLETEDt   TS_OBSOLETINGt	   myprocesst   mypostprocesst   tsInfo(   t   selfR   (    (    s   /usr/share/yum-cli/callback.pyt   __init__    s0    										c         C   sN   | d } | d  k r d } n t |  } | d | d | | d | d f S(   Nt   epocht   0t   namet   archt   versiont   release(   R   t   str(   R#   t   hdrt   tmpepochR%   (    (    s   /usr/share/yum-cli/callback.pyt	   _dopkgtup<   s
    
 	c         C   s1   d | d | d | d | d | d f } | S(   Ns   %s:%s.%s-%s-%sR%   R'   R)   R*   R(   (    (   R#   R,   t   handle(    (    s   /usr/share/yum-cli/callback.pyt   _makeHandleC   s    c         C   s   |  j  r | GHn  d  S(   N(   R   (   R#   t   msg(    (    s   /usr/share/yum-cli/callback.pyt   _localprintI   s    	c         C   sî   t  t |  j   } d | | f } d | d | d } | |  j |  j |  j f } |  j d | } d | | f } d | d }	 | rÄ |	 |  j t | | d  f }
 d	 |
 d
 | } n& |	 |  j | f }
 d |
 d
 | } | S(   Ns   %s.%ss   [%s   s/%s   s]i   s   %-t   sg      Y@s     %-10.10s: %-28.28s t    s     %-10.10s: %-28.28s (   t   lenR+   R   R   R   R   R   t   int(   R#   t   percentt   progresst   lt   sizet   fmt_donet   doneR   t   widtht   fmt_bart   bart   fmt(    (    s   /usr/share/yum-cli/callback.pyt   _makefmtM   s    "c         C   s`   |  j  |  \ } } } } } | d k rC d | | | | f } n d | | | | | f } | S(   s5   return nice representation of the package for the logR&   s   %s.%s %s-%ss   %s.%s %s:%s-%s(   R.   (   R#   R,   t   nt   at   et   vt   rt   pkg(    (    s   /usr/share/yum-cli/callback.pyt   _logPkgString^   s
    c         C   sn  | t  j k r* | d k rj| |  _ qjn@| t  j k r< n.| t  j k rN n| t  j k rň d |  _ d } | d k	 rÜ | \ } } |  j |  } t	 j
 | t	 j  }	 |	 |  j | <|  j d 7_ |  j j | d  |	 S|  j t d   nx| t  j k röd } | d k	 rj| \ } } |  j |  } t	 j |  j |  d }	 |  j |  }
 |  j j d |
  } x | D]y } y$ |  j | j } |  j | j } Wn t k
 r°n X|  j rs|  j |  } d | | f } |  j j |  qsqsWqjnt| t  j k r&| d k	 rjt  |  t  d  k rŕ| d k r>d } n | d	 | } |  j! r t" j# j$   r |  j% |  } | t d
  | f } | | k r˘| d } n  | |  j k rÝt" j# j& |  t" j# j'   | |  _ qÝq q#| \ } } | d k rd } n | d	 | } |  j |  }
 |  j j d |
  } xí | D]â } y |  j | j } Wn/ t k
 r} t d  | j | d f GHq:X|  j! r:t" j# j$   sŞ| | k r:|  j% |  } | | | d f } | |  j k rt" j# j& |  t" j# j'   | |  _ n  | | k rd GHqq:q:WqjnD| t  j( k r8n2| t  j) k rJn | t  j* k r4|  j+ d 7_+ |  j rŁ| |  j k rŁt d |  } |  j j |  n  |  j! rjt" j# j$   rj| |  j k rŮt d  } n t d  } d } |  j% | t,  } | | | f } t" j# j& | d  t" j# j'   qjn6 | t  j- k rFn$ | t  j. k rXn | t  j/ k rjn  d S(   sţ  Handle callbacks from the RPM library.

        :param what: number identifying the type of callback
        :param bytes: the number of bytes associated with the
           callback; the exact meaning depends on the type of 
           the callback.  For example, for a RPMCALLBACK_INST_PROGRESS
           callback, bytes will represent the current amount of work done
        :param total: the total amount of work associated with the
           callback; the exact meaning depends on the type of the
           callback. For example, *total* may represent the total
           number of transactions in a transaction set
        :param h: a package object or string identifying the package
           involved in the callback
        :param user: unused
        i   i   R'   s   No header - huh?i    t   pkgtups   %s: %st    l   d t	   Repackages   
s&   Error: invalid output state: %s for %sR4   s
   Erased: %st   Removingt   Cleanupid   N(0   t   rpmt   RPMCALLBACK_TRANS_STARTR   t   RPMCALLBACK_TRANS_PROGRESSt   RPMCALLBACK_TRANS_STOPt   RPMCALLBACK_INST_OPEN_FILER   R   R0   t   ost   opent   O_RDONLYR   R   R   t   appendR2   R    t   RPMCALLBACK_INST_CLOSE_FILEt   closeR.   R"   t
   getMembersR    t   output_stateR!   t   KeyErrorR   RH   R   t   infot   RPMCALLBACK_INST_PROGRESSt   typeR   t   syst   stdoutt   isattyRA   t   writet   flusht   RPMCALLBACK_UNINST_STARTt   RPMCALLBACK_UNINST_PROGRESSt   RPMCALLBACK_UNINST_STOPR   R   t   RPMCALLBACK_REPACKAGE_STARTt   RPMCALLBACK_REPACKAGE_STOPt   RPMCALLBACK_REPACKAGE_PROGRESS(   R#   t   whatt   bytest   totalt   ht   userR,   t   rpmlocR/   t   fdRI   t   txmbrst   txmbrt   processt	   processedt   pkgrepR1   R7   R@   RD   t   logmsg(    (    s   /usr/share/yum-cli/callback.pyt   callbackh   sÄ    					$(   t   __name__t
   __module__t   __doc__R$   R.   R0   R2   t   TrueRA   RH   Rw   (    (    (    s   /usr/share/yum-cli/callback.pyR      s   				
(    (	   Rz   RN   RS   R_   R   t   yumR    t   yum.constantsR   (    (    (    s   /usr/share/yum-cli/callback.pyt   <module>   s   
