
    \e"(                         d Z ddl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Zddl	m
Z
 g dZdedefdZ G d	 d
      Z G d de
j                  e      Z G d de
j                   e      Z G d de
j"                  e      Zy)z'Progress reporting for text interfaces.    N)Callable)base)AcquireProgressCdromProgress
OpProgressmsgreturnc                 f    t        j                  |       }|| k(  rt        j                  | d      }|S )z>Translate the message, also try apt if translation is missing.apt)apt_pkggettext)r   ress     3/usr/lib/python3/dist-packages/apt/progress/text.py_r       s,    
//#
C
czooc5)J    c            	       V    e Zd ZdZd
dej
                  dz  ddfdZddedededdfd	Z	y)TextProgressz.Internal Base class for text progress classes.Noutfiler	   c                 D    |xs t         j                  | _        d| _        y )Nr   )sysstdout_file_widthselfr   s     r   __init__zTextProgress.__init__+   s    *


r   r   newlinemaximizec                    | j                   j                  d       | j                   j                  |       | j                  t        |      kD  r5| j                   j                  | j                  t        |      z
  dz         n&|r$t	        | j                  t        |            | _        |r| j                   j                  d       y| j                   j                          y)z8Write the message on the terminal, fill remaining space. 
N)r   writer   lenmaxflush)r   r   r   r   s       r   _writezTextProgress._write/   s    



 ;;S!JJdkkCH4;<dkk3s84DKJJT" JJr   N)TF)
__name__
__module____qualname____doc__io
TextIOBaser   strboolr'    r   r   r   r   (   sC    8 4  #  t PT r   r   c                   \    e Zd ZdZd	dej
                  dz  ddfdZd	dedz  ddfdZd
dZ	y)r   z\Operation progress reporting.

    This closely resembles OpTextProgress in libapt-pkg.
    Nr   r	   c                 |    t         j                  | |       t        j                  j                  |        d| _        y )N )r   r   r   r   old_opr   s     r   r   zOpProgress.__init__F   s+    dG,  &r   percentc                 $   t         j                  j                  | |       | j                  r'| j                  r| j                  | j                         | j                  d| j                  | j                  fz  dd       | j                  | _        y)z1Called periodically to update the user interface.z%s... %i%%FTN)r   r   updatemajor_changer5   r'   opr6   )r   r6   s     r   r8   zOpProgress.updateK   sb    tW-KK$Ndggt||%<<eTJggr   c                     t         j                  j                  |        | j                  r+| j	                  t        d      d| j                  fz  dd       d| _        y)z,Called once an operation has been completed.z%c%s... Doner    Tr4   N)r   r   doner5   r'   r   r   s    r   r<   zOpProgress.doneS   sE    T";;KK.)T4;;,??tLr   r(   r	   N)
r)   r*   r+   r,   r-   r.   r   floatr8   r<   r1   r   r   r   r   @   s?    
 4  
edl d r   r   c                       e Zd ZdZddej
                  dz  ddfdZddZdeddfdZ	d	e
j                  ddfd
Zd	e
j                  ddfdZd	e
j                  ddfdZde
j                  defdZdededefdZddZy)r   z'AcquireProgress for the text interface.Nr   r	   c                     t         j                  | |       t        j                  j                  |        d | _        d| _        d| _        y )NP      )r   r   r   r   _signalr   _idr   s     r   r   zAcquireProgress.__init__^   sB    dG,%%d+  	 r   c                     t         j                  j                  |        t        j                  t        j                  | j
                        | _        | j                          d| _        y)zStart 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.
        rC   N)r   r   startsignalSIGWINCH_winchrD   rE   r=   s    r   rG   zAcquireProgress.startg   sB     	""4(}}V__dkkBr   dummyc                 6   t        | j                  d      rt        j                  | j                  j	                               rUddl}ddl}ddl}|j                  | j                  |j                  d      }|j                  d|      \  }}}}|dz
  | _        yyy)z)Signal handler for window resize signals.filenor   Ns           hhhhrC   )hasattrr   osisattyrM   fcntlstructtermiosioctl
TIOCGWINSZunpackr   )r   rK   rR   rS   rT   bufcols          r   rJ   zAcquireProgress._winchs   sz    4::x(RYYtzz7H7H7J-K++djj'*<*<hGC'-}}VS'A$E3u'DK .L(r   itemc                     t         j                  j                  | |       t        d      |j                  z   }|j
                  j                  r/|dt        j                  |j
                  j                        z  z  }| j                  |       y)z@Called when an item is update (e.g. not modified on the server).zHit  [%sB]N)
r   r   ims_hitr   descriptionownerfilesizer   size_to_strr'   r   rZ   lines      r   r]   zAcquireProgress.ims_hit~   si    $$T40y4+++::Hw224::3F3FGGGDDr   c                    t         j                  j                  | |       |j                  j                  |j                  j
                  k(  r(| j                  t        d      |j                  z          y| j                  t        d      |j                  z          | j                  d|j                  j                  z         y)zCalled when an item is failed.zIgn zErr z  %sN)
r   r   failr_   status	STAT_DONEr'   r   r^   
error_text)r   rZ   s     r   re   zAcquireProgress.fail   s    !!$-::

 4 44KK&	D$4$445KK&	D$4$445KK!6!667r   c                    t         j                  j                  | |       |j                  j                  ry| j
                  |j                  _        | xj
                  dz  c_        t        d      |j                  j                   d|j                   z   }|j                  j                  r/|dt        j                  |j                  j                        z  z  }| j                  |       y)z/Called when some of the item's data is fetched.NrC   zGet:r!   r\   )r   r   fetchr_   completerE   idr   r^   r`   r   ra   r'   rb   s      r   rj   zAcquireProgress.fetch   s    ""4.::

Aydjjmm_Ad.>.>-?@@::Hw224::3F3FGGGDDr   r_   c                 *   t         j                  j                  | |       t        | j                  d      r.t        j                  | j                  j                               sy| j                  | j                  z   dz  t        | j                  | j                  z         z  }d}d|z  }d}| j                  rzt        t        | j                  | j                  z
        | j                  z        }dj                  t!        j"                  | j                        t!        j$                  |            }|j&                  D ]  }d}|j(                  sV|j*                  rId|j*                  z  }t-        |      t-        |      z   t-        |      z   | j.                  k\  r n||z  }d}hd}|j(                  j0                  j2                  r=|d	|j(                  j0                  j2                  |j(                  j4                  fz  z  }n|d
|j(                  j6                  z  z  }|j(                  j0                  j8                  r&|d|j(                  j0                  j8                  z  z  }|dt!        j"                  |j:                        z  z  }|j<                  ra|j(                  j0                  j>                  sA|dt!        j"                  |j<                        |j:                  dz  |j<                  z  fz  z  }|dz  }t-        |      t-        |      z   t-        |      z   | j.                  k\  r n||z  } |s|tA        d      z  }| j                  r-|| j.                  t-        |      z
  t-        |      z
  dz  |z   z  }| jC                  |d       y)zPeriodically invoked while the Acquire process is underway.

        Return False if the user asked to cancel the whole Acquire process.rM   Tg      Y@Fz%i%%r4   z	 {}B/s {}z [%s]z [%i %sz [%sz %sz %sBz	/%sB %i%%]z
 [Working]r!   )"r   r   pulserO   r   rP   rQ   rM   current_bytescurrent_itemsr?   total_bytestotal_itemscurrent_cpsintformatr   ra   time_to_strworkerscurrent_itemrf   r$   r   r_   rl   	shortdescr^   active_subprocesscurrent_size
total_sizerk   r   r'   )	r   r_   r6   showntvalendetaworkervals	            r   ro   zAcquireProgress.pulse   s&    	""4/4::x(4::;L;L;N1O &&););;uDt///I
 
 eD,,t/A/AABTEUEUUVC$$##D$4$45##C(C
 mm %	FC&&==!FMM1C4y3s8+c#h6$++ECKD EE""((++y''--00''11$  
 v 3 3 ? ???""((::uv2288JJJJ6G//0C0CDDDC   )<)<)B)B)K)K{''(9(9:''%/&2C2CC&  
 3JC4y3s8#c#h.$++=K%	N AlO#DT[[3s8+c$i73>DDDD% r   mediumdrivec                     t         j                  j                  | ||       | j                  t	        d      ||fz         t               dvS )z7Prompt the user to change the inserted removable media.zUMedia change: please insert the disc labeled
 '%s'
in the drive '%s' and press enter
)cC)r   r   media_changer'   r   input)r   r   r   s      r   r   zAcquireProgress.media_change   sP    ))$>6
 uo	
 wj((r   c                    t         j                  j                  |        | j                  t	        d      t        j                  | j                        t        j                  | j                        t        j                  | j                        fz  j                  d             ddl} |j                  |j                  | j                         y)z/Invoked when the Acquire process stops running.zFetched %sB in %s (%sB/s)
r"   r   N)r   r   stopr'   r   r   ra   fetched_bytesrw   elapsed_timert   rstriprH   rI   rD   )r   rH   s     r   r   zAcquireProgress.stop   s    !!$'/0''(:(:;''(9(9:''(8(89 fTl		
 	foot||4r   r(   r>   )r)   r*   r+   r,   r-   r.   r   rG   objectrJ   r   AcquireItemDescr]   re   rj   Acquirer0   ro   r/   r   r   r1   r   r   r   r   [   s    1 4  
	"V 	" 	"G33  800 8T 8'11 d F7?? Ft FP)3 )s )t )5r   r   c                   B    e Zd ZdZdedz  fdZdededdfdZdefdZ	y)	r   zText CD-ROM progress.r	   Nc                     t         j                  j                  |        | j                  t	        d      d       	 t        t        d            S # t        $ r Y yw xY w)z,Ask the user to provide a name for the disc.zDPlease provide a name for this medium, such as 'Debian 2.1r1 Disk 1'F:N)r   r   ask_cdrom_namer'   r   r/   r   KeyboardInterruptr=   s    r   r   zCdromProgress.ask_cdrom_name
  sY    ))$/( 	
	uSz?"  		s   A 	AAtextcurrentc                 p    t         j                  j                  | ||       |r| j                  |d       yy)zSet the current progress.FN)r   r   r8   r'   )r   r   r   s      r   r8   zCdromProgress.update  s0    !!$g6KKe$ r   c                     t         j                  j                  |        | j                  t	        d      d       	 t        t               dk(        S # t        $ r Y yw xY w)z"Ask the user to change the CD-ROM.z4Please insert an installation medium and press enterFr4   )r   r   change_cdromr'   r   r0   r   r   r=   s    r   r   zCdromProgress.change_cdrom  sR    ''-ALMuU	2&&  		s   A 	AA)
r)   r*   r+   r,   r/   r   ru   r8   r0   r   r1   r   r   r   r     s;    d
 %3 % % %d r   r   )r,   r-   rP   rH   r   typescollections.abcr   r   apt.progressr   __all__r/   r   r   r   r   r   r1   r   r   <module>r      s   " . 	 	  
  $  
<3 3  0, 6i5d**L i5XD&& r   