
    8.g"(                        S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKrSSK	J
r
  / SQrS\S\4S jr " S	 S
5      r " S S\
R                  \5      r " S S\
R                   \5      r " S S\
R"                  \5      rg)z'Progress reporting for text interfaces.    N)Callable)base)AcquireProgressCdromProgress
OpProgressmsgreturnc                 j    [         R                  " U 5      nX:X  a  [         R                  " U S5      nU$ )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
zooc5)J    c            	       f    \ rS rSrSrSS\R                  S-  SS4S jjrSS\S\	S	\	SS4S
 jjr
Srg)TextProgress(   z.Internal Base class for text progress classes.Noutfiler	   c                 N    U=(       d    [         R                  U l        SU l        g )Nr   )sysstdout_file_widthselfr   s     r   __init__TextProgress.__init__+   s    *


r   r   newlinemaximizec                    U R                   R                  S5        U R                   R                  U5        U R                  [        U5      :  a5  U R                   R                  U R                  [        U5      -
  S-  5        O+U(       a$  [	        U R                  [        U5      5      U l        U(       a  U R                   R                  S5        gU R                   R                  5         g)z8Write the message on the terminal, fill remaining space. 
N)r   writer   lenmaxflush)r   r   r   r    s       r   _writeTextProgress._write/   s    



 ;;S!JJdkkCH4;<dkk3s84DKJJT" JJr   )r   r   N)TF)__name__
__module____qualname____firstlineno____doc__io
TextIOBaser   strboolr)   __static_attributes__ r   r   r   r   (   sH    8 4  #  t PT  r   r   c                   n    \ rS rSrSrSS\R                  S-  SS4S jjrSS\S-  SS4S jjr	SS	 jr
S
rg)r   @   zTOperation progress reporting.

This closely resembles OpTextProgress in libapt-pkg.
Nr   r	   c                 z    [         R                  X5        [        R                  R                  U 5        SU l        g )N )r   r   r   r   old_opr   s     r   r   OpProgress.__init__F   s)    d,  &r   percentc                 6   [         R                  R                  X5        U R                  (       a,  U R                  (       a  U R                  U R                  5        U R                  SU R                  U R                  4-  SS5        U R                  U l        g)z1Called periodically to update the user interface.z%s... %i%%FTN)r   r   updatemajor_changer;   r)   opr=   )r   r=   s     r   r?   OpProgress.updateK   s`    t-KK$Ndggt||%<<eTJggr   c                     [         R                  R                  U 5        U R                  (       a+  U R	                  [        S5      SU R                  4-  SS5        SU l        g)z,Called once an operation has been completed.z%c%s... Doner"   Tr:   N)r   r   doner;   r)   r   r   s    r   rD   OpProgress.doneS   sE    T";;KK.)T4;;,??tLr   )r;   r+   r	   N)r,   r-   r.   r/   r0   r1   r2   r   floatr?   rD   r5   r6   r   r   r   r   @   s?    
 4  
edl d r   r   c                      \ rS rSrSrSS\R                  S-  SS4S jjrSS jrS\	SS4S	 jr
S
\R                  SS4S jrS
\R                  SS4S jrS
\R                  SS4S jrS\R                   S\4S jrS\S\S\4S jrSS jrSrg)r   [   z'AcquireProgress for the text interface.Nr   r	   c                     [         R                  X5        [        R                  R                  U 5        S U l        SU l        SU l        g )NP      )r   r   r   r   _signalr   _idr   s     r   r   AcquireProgress.__init__^   s@    d,%%d+  	 r   c                     [         R                  R                  U 5        [        R                  " [        R                  U R
                  5      U l        U R                  5         SU l        g)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.
rM   N)r   r   startsignalSIGWINCH_winchrN   rO   rE   s    r   rR   AcquireProgress.startg   sB     	""4(}}V__dkkBr   dummyc                 J   [        U R                  S5      (       a  [        R                  " U R                  R	                  5       5      (       aT  SSKnSSKnSSKnUR                  U R                  UR                  S5      nUR                  SU5      u  p  nUS-
  U l        ggg)z)Signal handler for window resize signals.filenor   Ns           hhhhrM   )hasattrr   osisattyrY   fcntlstructtermiosioctl
TIOCGWINSZunpackr   )r   rW   r^   r_   r`   bufcols          r   rU   AcquireProgress._winchs   s~    4::x((RYYtzz7H7H7J-K-K++djj'*<*<hGC'-}}VS'A$Eu'DK .L(r   itemc                 *   [         R                  R                  X5        [        S5      UR                  -   nUR
                  R                  (       a0  US[        R                  " UR
                  R                  5      -  -  nU R                  U5        g)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   rg   lines      r   rj   AcquireProgress.ims_hit~   sg    $$T0y4+++::Hw224::3F3FGGGDDr   c                    [         R                  R                  X5        UR                  R                  UR                  R
                  :X  a(  U R                  [        S5      UR                  -   5        gU R                  [        S5      UR                  -   5        U R                  SUR                  R                  -  5        g)zCalled when an item is failed.zIgn zErr z  %sN)
r   r   failrl   status	STAT_DONEr)   r   rk   
error_text)r   rg   s     r   rs   AcquireProgress.fail   s    !!$-::

 4 44KK&	D$4$445KK&	D$4$445KK!6!667r   c                    [         R                  R                  X5        UR                  R                  (       a  gU R
                  UR                  l        U =R
                  S-  sl        [        S5      UR                  R                   SUR                   3-   nUR                  R                  (       a0  US[        R                  " UR                  R                  5      -  -  nU R                  U5        g)z/Called when some of the item's data is fetched.NrM   zGet:r#   ri   )r   r   fetchrl   completerO   idr   rk   rm   r   rn   r)   ro   s      r   ry   AcquireProgress.fetch   s    ""4.::

Aydjjmm_Ad.>.>-?@@::Hw224::3F3FGGGDDr   rl   c                    [         R                  R                  X5        [        U R                  S5      (       a4  [
        R                  " U R                  R                  5       5      (       d  gU R                  U R                  -   S-  [        U R                  U R                  -   5      -  nSnSU-  nSnU R                  (       a|  [        [        U R                  U R                  -
  5      U R                  -  5      nSR                  [         R"                  " U R                  5      [         R$                  " U5      5      nUR&                   GH  nSnUR(                  (       d\  UR*                  (       aI  SUR*                  -  n[-        U5      [-        U5      -   [-        U5      -   U R.                  :  a    GOXH-  nSnMs  SnUR(                  R0                  R2                  (       a=  US	UR(                  R0                  R2                  UR(                  R4                  4-  -  nOUS
UR(                  R6                  -  -  nUR(                  R0                  R8                  (       a&  USUR(                  R0                  R8                  -  -  nUS[         R"                  " UR:                  5      -  -  nUR<                  (       ag  UR(                  R0                  R>                  (       dB  US[         R"                  " UR<                  5      UR:                  S-  UR<                  -  4-  -  nUS-  n[-        U5      [-        U5      -   [-        U5      -   U R.                  :  a    O	XH-  nGM     U(       d  U[A        S5      -  nU R                  (       a,  X@R.                  [-        U5      -
  [-        U5      -
  S-  U-   -  nU RC                  US5        g)zPeriodically invoked while the Acquire process is underway.

Return False if the user asked to cancel the whole Acquire process.rY   Tg      Y@Fz%i%%r:   z	 {}B/s {}z [%s]z [%i %sz [%sz %sz %sBz	/%sB %i%%]z
 [Working]r#   )"r   r   pulser[   r   r\   r]   rY   current_bytescurrent_itemsrH   total_bytestotal_itemscurrent_cpsintformatr   rn   time_to_strworkerscurrent_itemrt   r&   r   rl   r{   	shortdescrk   active_subprocesscurrent_size
total_sizerz   r   r)   )	r   rl   r=   showntvalendetaworkervals	            r   r   AcquireProgress.pulse   s    	""4/4::x((4::;L;L;N1O1O &&););;uDt///I
 
 eD,,t/A/AABTEUEUUVC$$##D$4$45##C(C
 mmFC&&==!FMM1C4y3s8+c#h6$++EKD 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[[3s8+c$i73>DDDD% r   mediumdrivec                     [         R                  R                  XU5        U R                  [	        S5      X4-  5        [        5       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   AcquireProgress.media_change   sL    ))$>6
 o	
 wj((r   c                    [         R                  R                  U 5        U R                  [	        S5      [
        R                  " U R                  5      [
        R                  " U R                  5      [
        R                  " U R                  5      4-  R                  S5      5        SSKnUR                  " UR                  U R                  5        g)z/Invoked when the Acquire process stops running.zFetched %sB in %s (%sB/s)
r$   r   N)r   r   stopr)   r   r   rn   fetched_bytesr   elapsed_timer   rstriprS   rT   rN   )r   rS   s     r   r   AcquireProgress.stop   s    !!$'/0''(:(:;''(9(9:''(8(89 fTl		
 	foot||4r   )rO   rN   r   r+   rG   )r,   r-   r.   r/   r0   r1   r2   r   rR   objectrU   r   AcquireItemDescrj   rs   ry   Acquirer4   r   r3   r   r   r5   r6   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                   P    \ rS rSrSrS\S-  4S jrS\S\SS4S jrS\	4S	 jr
S
rg)r   i  zText CD-ROM progress.r	   Nc                     [         R                  R                  U 5        U R                  [	        S5      S5         [        [        S5      5      $ ! [         a     gf = f)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   r3   r   KeyboardInterruptrE   s    r   r   CdromProgress.ask_cdrom_name
  sY    ))$/( 	
	uSz?"  		s   A 
AAtextcurrentc                 x    [         R                  R                  XU5        U(       a  U R                  US5        gg)zSet the current progress.FN)r   r   r?   r)   )r   r   r   s      r   r?   CdromProgress.update  s.    !!$g6KKe$ r   c                     [         R                  R                  U 5        U R                  [	        S5      S5         [        [        5       S:H  5      $ ! [         a     gf = f)z"Ask the user to change the CD-ROM.z4Please insert an installation medium and press enterFr:   )r   r   change_cdromr)   r   r4   r   r   rE   s    r   r   CdromProgress.change_cdrom  sR    ''-ALMuU	2&&  		s   A 
AAr6   )r,   r-   r.   r/   r0   r3   r   r   r?   r4   r   r5   r6   r   r   r   r     s;    d
 %3 % % %d r   r   )r0   r1   r\   rS   r   typescollections.abcr   r   apt.progressr   __all__r3   r   r   r   r   r   r6   r   r   <module>r      s   " . 	 	  
  $  
<3 3  0, 6i5d**L i5XD&& r   