ó
fÛMc           @   sÀ   d  Z  d d l Z d d l Z d d l Z d d l m Z d d d g Z d „  Z d e f d	 „  ƒ  YZ	 d e j
 e	 f d
 „  ƒ  YZ
 d e j e	 f d „  ƒ  YZ d e j e	 f d „  ƒ  YZ d S(   s'   Progress reporting for text interfaces.iÿÿÿÿN(   t   baset   AcquireProgresst   CdromProgresst
   OpProgressc         C   s4   t  j |  ƒ } | |  k r0 t  j |  d ƒ } n  | S(   s>   Translate the message, also try apt if translation is missing.t   apt(   t   apt_pkgt   gettext(   t   msgt   res(    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyt   _   s    t   TextProgressc           B   s)   e  Z d  Z d d „ Z e e d „ Z RS(   s.   Internal Base class for text progress classes.c         C   s   | p t  j |  _ d |  _ d  S(   Ni    (   t   syst   stdoutt   _filet   _width(   t   selft   outfile(    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyt   __init__&   s    c         C   s§   |  j  j d ƒ |  j  j | ƒ |  j t | ƒ k rY |  j  j |  j t | ƒ d ƒ n$ | r} t |  j t | ƒ ƒ |  _ n  | r– |  j  j d ƒ n |  j  j ƒ  d S(   s8   Write the message on the terminal, fill remaining space.s   t    s   
N(   R   t   writeR   t   lent   maxt   flush(   R   R   t   newlinet   maximize(    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyt   _write*   s    $N(   t   __name__t
   __module__t   __doc__t   NoneR   t   Truet   FalseR   (    (    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyR
   #   s   c           B   s/   e  Z d  Z d d „ Z d d „ Z d „  Z RS(   s\   Operation progress reporting.

    This closely resembles OpTextProgress in libapt-pkg.
    c         C   s-   t  j |  | ƒ t j j |  ƒ d |  _ d  S(   Nt    (   R
   R   R    R   t   old_op(   R   R   (    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyR   A   s    c         C   sk   t  j j |  | ƒ |  j r8 |  j r8 |  j |  j ƒ n  |  j d |  j |  j f t t	 ƒ |  j |  _ d S(   s1   Called periodically to update the user interface.s   %s... %i%%N(
   R    R   t   updatet   major_changeR!   R   t   opt   percentR   R   (   R   R%   (    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyR"   F   s
    #c         C   sO   t  j j |  ƒ |  j rB |  j t d ƒ d |  j f t t ƒ n  d |  _ d S(   s,   Called once an operation has been completed.s   %c%s... Dones   R    N(   R    R   t   doneR!   R   R	   R   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyR&   N   s    	)N(   R   R   R   R   R   R"   R&   (    (    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyR   ;   s   c           B   sb   e  Z d  Z d
 d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z RS(   s'   AcquireProgress for the text interface.c         C   s?   t  j |  | ƒ t j j |  ƒ d  |  _ d |  _ d |  _ d  S(   NiP   i   (   R
   R   R    R   R   t   _signalR   t   _id(   R   R   (    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyR   Y   s
    		c         C   sN   t  j j |  ƒ d d l } | j | j |  j ƒ |  _ |  j ƒ  d |  _ d S(   s¬   Start an Acquire progress.

        In this case, the function sets up a signal handler for SIGWINCH, i.e.
        window resize signals. And it also sets id to 1.
        iÿÿÿÿNl    (   R    R   t   startt   signalt   SIGWINCHt   _winchR'   R(   (   R   R*   (    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyR)   `   s
    
c         G   s›   t  |  j d ƒ r— t j |  j j ƒ  ƒ r— d d l } d d l } d d l } | j |  j | j	 d ƒ } | j
 d | ƒ \ } } } } | d |  _ n  d S(	   s)   Signal handler for window resize signals.t   filenoiÿÿÿÿNi   R   t   hhhhi   s           (   t   hasattrR   t   ost   isattyR-   t   fcntlt   termiost   structt   ioctlt
   TIOCGWINSZt   unpackR   (   R   t   dummyR2   R3   R4   t   buft   col(    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyR,   m   s    *c         C   sc   t  j j |  | ƒ t d ƒ | j } | j j rR | d t j | j j ƒ 7} n  |  j	 | ƒ d S(   s@   Called when an item is update (e.g. not modified on the server).s   Hit s    [%sB]N(
   R    R   t   ims_hitR	   t   descriptiont   ownert   filesizeR   t   size_to_strR   (   R   t   itemt   line(    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyR;   w   s
     c         C   s}   t  j j |  | ƒ | j j | j j k rH |  j t d ƒ | j ƒ n1 |  j t d ƒ | j ƒ |  j d | j j	 ƒ d S(   s   Called when an item is failed.s   Ign s   Err s     %sN(
   R    R   t   failR=   t   statust	   STAT_DONER   R	   R<   t
   error_text(   R   R@   (    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyRB      s
    c         C   s¡   t  j j |  | ƒ | j j r# d S|  j | j _ |  j d 7_ t d ƒ d | j j | j f } | j j	 r | d t
 j | j j	 ƒ 7} n  |  j | ƒ d S(   s/   Called when some of the item's data is fetched.Ni   s   Get:s   %s %ss    [%sB](   R    R   t   fetchR=   t   completeR(   t   idR	   R<   R>   R   R?   R   (   R   R@   RA   (    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyRF   ˆ   s    # c   	      C   s£  t  j j |  | ƒ |  j |  j d t |  j |  j ƒ } t } d | } d } |  j	 r¥ t
 t |  j |  j ƒ |  j	 ƒ } d t j |  j	 ƒ t j | ƒ f } n  x™| j D]Ž} d } | j s | j r¯ d | j } t | ƒ t | ƒ t | ƒ |  j k rPn  | | 7} t } q¯ q¯ n  t } | j j j r[| d | j j j | j j f 7} n | d | j j 7} | j j j r˜| d | j j j 7} n  | d	 t j | j ƒ 7} | j rü| j j j rü| d
 t j | j ƒ | j d | j f 7} n  | d 7} t | ƒ t | ƒ t | ƒ |  j k r3Pq¯ | | 7} q¯ W| sZ| t d ƒ 7} n  |  j	 r| |  j t | ƒ t | ƒ d | 7} n  |  j | t ƒ t S(   sˆ   Periodically invoked while the Acquire process is underway.

        Return False if the user asked to cancel the whole Acquire process.g      Y@s   %i%%R    s	    %sB/s %ss    [%s]s    [%i %ss    [%ss    %ss    %sBs	   /%sB %i%%t   ]s
    [Working]R   (   R    R   t   pulset   current_bytest   current_itemst   floatt   total_bytest   total_itemsR   t   current_cpst   longR   R?   t   time_to_strt   workerst   current_itemRC   R   R   R   R=   RH   t	   shortdescR<   t   modet   current_sizet
   total_sizeRG   R	   R   (	   R   R=   R%   t   shownt   tvalt   endt   etat   workert   val(    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyRJ   –   sT    
			)
	
)	,c         C   s@   t  j j |  | | ƒ |  j t d ƒ | | f ƒ t ƒ  d k S(   s7   Prompt the user to change the inserted removable media.sU   Media change: please insert the disc labeled
 '%s'
in the drive '%s' and press enter
t   ct   C(   R_   R`   (   R    R   t   media_changeR   R	   t	   raw_input(   R   t   mediumt   drive(    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyRa   Ó   s    c         C   sƒ   t  j j |  ƒ |  j t d ƒ t j |  j ƒ t j |  j	 ƒ t j |  j
 ƒ f j d ƒ ƒ d d l } | j | j |  j ƒ d S(   s/   Invoked when the Acquire process stops running.s   Fetched %sB in %s (%sB/s)
s   
iÿÿÿÿN(   R    R   t   stopR   R	   R   R?   t   fetched_bytesRR   t   elapsed_timeRP   t   rstripR*   R+   R'   (   R   R*   (    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyRe   Û   s     N(   R   R   R   R   R   R)   R,   R;   RB   RF   RJ   Ra   Re   (    (    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyR   V   s   		
					=	c           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s   Text CD-ROM progress.c         C   sM   t  j j |  ƒ |  j t d ƒ t ƒ y t d ƒ SWn t k
 rH d SXd S(   s,   Ask the user to provide a name for the disc.sB   Please provide a name for this Disc, such as 'Debian 2.1r1 Disk 1't   :N(   R    R   t   ask_cdrom_nameR   R	   R   Rb   t   KeyboardInterrupt(   R   (    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyRj   ì   s    c         C   s3   t  j j |  | | ƒ | r/ |  j | t ƒ n  d S(   s   Set the current progress.N(   R    R   R"   R   R   (   R   t   textt   current(    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyR"   ö   s    c         C   sP   t  j j |  ƒ |  j t d ƒ t ƒ y t ƒ  d k SWn t k
 rK t SXd S(   s"   Ask the user to change the CD-ROM.s1   Please insert a Disc in the drive and press enterR    N(   R    R   t   change_cdromR   R	   R   Rb   Rk   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyRn   ü   s    (   R   R   R   Rj   R"   Rn   (    (    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyR   é   s   	
	(   R   R0   R   R   t   apt.progressR    t   __all__R	   t   objectR
   R   R   R   (    (    (    s5   /usr/lib/python2.7/dist-packages/apt/progress/text.pyt   <module>   s   	“