o 4f(@sdZddlmZddlZddlZddlZddlZddlZddlm Z m Z m Z ddl Z ddl mZgdZddZGd d d eZGd d d ejeZGd ddejeZGdddejeZdS)z'Progress reporting for text interfaces.)print_functionN)CallableOptionalUnion)base)AcquireProgress CdromProgress OpProgresscCs"t|}||krt|d}|S)z>Translate the message, also try apt if translation is missing.apt)apt_pkggettext)msgresr3/usr/lib/python3/dist-packages/apt/progress/text.py_$s  rc@s$eZdZdZd ddZd ddZdS) TextProgressz.Internal Base class for text progress classes.NcCs|ptj|_d|_dS)Nr)sysstdout_file_widthselfoutfilerrr__init__0s  zTextProgress.__init__TFcCsz|jd|j||jt|kr!|j|jt|dn |r,t|jt||_|r6|jddS|jdS)z8Write the message on the terminal, fill remaining space.   N)rwriterlenmaxflush)rr newlinemaximizerrr_write5s  zTextProgress._writeN)TF)__name__ __module__ __qualname____doc__rr$rrrrr-s rc@s,eZdZdZd ddZd ddZddZdS) r z\Operation progress reporting. This closely resembles OpTextProgress in libapt-pkg. NcCs"t||tj|d|_dS)N)rrrr old_oprrrrrMs   zOpProgress.__init__cCsLtj|||jr|jr||j|d|j|jfdd|j|_dS)z1Called periodically to update the user interface.z %s... %i%% FTN)rr update major_changer+r$oppercent)rr/rrrr,Ss    zOpProgress.updatecCs8tj||jr|tdd|jfddd|_dS)z,Called once an operation has been completed.z %c%s... DonerTr*N)rr doner+r$rrrrrr0\s  zOpProgress.doner%)r&r'r(r)rr,r0rrrrr Gs    r c@sZeZdZdZdddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ dS)rz'AcquireProgress for the text interface.NcCs.t||tj|d|_d|_d|_dS)NP)rrrr_signalr_idrrrrrhs   zAcquireProgress.__init__cCs0tj|ttj|j|_|d|_dS)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. r3N)rrstartsignalSIGWINCH_winchr4r5r1rrrr6ps  zAcquireProgress.startcGspt|jdr4t|jr6ddl}ddl}ddl}||j|j d}| d|\}}}}|d|_ dSdSdS)z)Signal handler for window resize signals.filenorNs hhhhr3) hasattrrosisattyr:fcntltermiosstructioctl TIOCGWINSZunpackr)rdummyr?r@rAbufcolrrrr9}szAcquireProgress._winchcCsHtj||td|j}|jjr|dt|jj7}| |dS)z@Called when an item is update (e.g. not modified on the server).zHit  [%sB]N) rrims_hitr descriptionownerfilesizer size_to_strr$ritemlinerrrrIs zAcquireProgress.ims_hitcCs`tj|||jj|jjkr|td|jdS|td|j|d|jj dS)zCalled when an item is failed.zIgn zErr z %sN) rrfailrKstatus STAT_DONEr$rrJ error_text)rrOrrrrQs zAcquireProgress.failcCsxtj|||jjr dS|j|j_|jd7_tdd|jj|jf}|jj r5|dt |jj 7}| |dS)z/Called when some of the item's data is fetched.Nr3zGet:z%s %srH) rrfetchrKcompleter5idrrJrLr rMr$rNrrrrUs zAcquireProgress.fetchc Cstj||t|jdrt|jsdS|j|j dt |j |j }d}d|}d}|j rLtt |j |j|j }dt|j t|f}|jD]}d}|jsv|jrud|j}t|t|t||jkronp||7}d}qOd}|jjjr|d |jjj|jjf7}n|d |jj7}|jjjr|d |jjj7}|d t|j7}|jr|jjjs|d t|j|jd|jf7}|d7}t|t|t||jkrn||7}qO|s|td7}|j r||jt|t|d|7}| |ddS)zPeriodically invoked while the Acquire process is underway. Return False if the user asked to cancel the whole Acquire process.r:TgY@Fz%i%%r*z %sB/s %sz [%s]z [%i %sz [%sz %sz %sBz /%sB %i%%]z [Working]r)!rrpulser<rr=r>r: current_bytes current_itemsfloat total_bytes total_items current_cpsintr rM time_to_strworkers current_itemrRrrrKrW shortdescrJactive_subprocess current_size total_sizerVrr$) rrKr/showntvalendetaworkervalrrrrYsh           " zAcquireProgress.pulsecCs0tj||||td||ftdvS)z7Prompt the user to change the inserted removable media.zUMedia change: please insert the disc labeled '%s' in the drive '%s' and press enter )cC)rr media_changer$rinput)rmediumdriverrrrps   zAcquireProgress.media_changecCs^tj||tdt|jt|j t|j f dddl }| |j |jdS)z/Invoked when the Acquire process stops running.zFetched %sB in %s (%sB/s) rrN)rrstopr$rr rM fetched_bytesra elapsed_timer_rstripr7r8r4)rr7rrrrts     zAcquireProgress.stopr%) r&r'r(r)rr6r9rIrQrUrYrprtrrrrres     E rc@s(eZdZdZddZddZddZdS) rzText CD-ROM progress.cCs@tj||tddzttdWStyYdSw)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)rrask_cdrom_namer$rstrrqKeyboardInterruptr1rrrry s   zCdromProgress.ask_cdrom_namecCs(tj||||r||ddSdS)zSet the current progress.FN)rrr,r$)rtextcurrentrrrr,szCdromProgress.updatecCsBtj||tddzttdkWSty YdSw)z"Ask the user to change the CD-ROM.z4Please insert an installation medium and press enterFr*)rr change_cdromr$rboolrqr{r1rrrr~s   zCdromProgress.change_cdromN)r&r'r(r)ryr,r~rrrrrs  r)r) __future__rior=r7rtypestypingrrrr apt.progressr__all__robjectrr rrrrrrs"   #