
    yf&                         S SK r S SKrS SKrS SKrS SKJr  SSKJr  \" 5       rSSKJ	r	  S r
 " S S	5      r " S
 S\5      r " S S\5      r " S S5      rg)    N)get_terminal_size   )create_logger   )ellipsis_truncatec                 L    [        SS9S   nUS:w  a  U R                  U5      $ U $ )Nr
   fallbackr   r
   )r   ljust)messageterminal_spaces     7/usr/lib/python3/dist-packages/borg/helpers/progress.pyjustify_to_terminal_sizer      s-    &9!<N}}^,,N    c                   X    \ rS rSrSrSrSrSr\S 5       r	SS jr
S rSS	.S
 jrS rSrg)ProgressIndicatorBase   zborg.output.progressNFr   c                 D    U =R                   S-  sl         U R                   $ )zYUnique number, can be used by receiving applications to distinguish different operations.r   )operation_id_counter)clss    r   operation_id"ProgressIndicatorBase.operation_id   s!     	  A% '''r   c                    S U l         [        R                  " U R                  5      U l        U R                  5       U l        Xl        U R                  R                  (       GdK  [        R                  " [        R                  S9U l         U R                   R                  [        R                  5        [        R                  " S5      n UR                  nUR                  (       a  SOSnUR                  U l        U R                   R!                  U5        X@R                   l        U R                  R'                  U R                   5        U R                  R(                  [        R*                  :X  a)  U R                  R                  [        R,                  5        SU R                  l        U R                  R1                  5       [        R                  :H  U l        g ! ["         a    Sn Nf = f)N)streamborg
F)handlerlogging	getLoggerLOGGERloggerr   idmsgidhandlersStreamHandlersysstderrsetLevelINFO	formatterjsonsetFormatterAttributeError
terminator
addHandlerlevelNOTSETWARN	propagategetEffectiveLevelemit)selfr&   r$   r-   r1   s        r   __init__ProgressIndicatorBase.__init__"   sK   ''4##%

 {{###"00

CDLLL!!',,/&&v.F5",,	%+[[Td
"KK	 )))4&0LL#KK""4<<0{{  GNN2$$W\\2$)DKK! KK113w||C	% " "!
"s   2G   G/.G/c                     U R                   b@  U R                  R                  U R                   5        U R                   R                  5         g g N)r    r$   removeHandlercloser9   s    r   __del__ProgressIndicatorBase.__del__I   s7    <<#KK%%dll3LL  $r   finishedc          
      B   U R                   (       d   eU R                  (       d  g UR                  [        U R                  U R
                  U R                  U[        R                  " 5       S95        [        [         R                  " U5      [        R                  SS9  g )N)	operationr&   typerD   timeT)fileflush)r.   r8   updatedictr%   r&   	JSON_TYPErH   printdumpsr)   r*   )r9   rD   kwargss      r   output_json!ProgressIndicatorBase.output_jsonN   sg    yyyyydgg**
 	 	djj szz>r   c                 h    U R                   (       a  U R                  SS9  g U R                  S5        g )NTrC    )r.   rQ   outputr@   s    r   finishProgressIndicatorBase.finish[   s%    99d+KKOr   )r8   r    r%   r.   r$   r&   r=   )__name__
__module____qualname____firstlineno__r#   rM   r.   r   classmethodr   r:   rA   rQ   rV   __static_attributes__ r   r   r   r      sD    #FID( (
%DN!
 ', ?r   r   c                       \ rS rSrSrS rSrg)ProgressIndicatorMessageb   progress_messagec                     U R                   (       a  U R                  US9  g U R                  R                  [	        U5      5        g )N)r   )r.   rQ   r$   infor   )r9   msgs     r   rU   ProgressIndicatorMessage.outpute   s2    99S)KK5c:;r   r^   N)rX   rY   rZ   r[   rM   rU   r]   r^   r   r   r`   r`   b   s    "I<r   r`   c                   N   ^  \ rS rSrSrSU 4S jjrS	S jrS
S jrSS jrSr	U =r
$ )ProgressIndicatorPercentl   progress_percentc                 ^   > SU l         Xl        X0l        X l        X@l        [
        TU ]  US9  g)z
Percentage-based progress indicator

:param total: total amount of items
:param step: step size in percent
:param start: at which percent value to start
:param msg: output message, must contain one %f placeholder for the percentage
r   )r&   N)countertotal
trigger_atstepre   superr:   )r9   rm   ro   startre   r&   	__class__s         r   r:   !ProgressIndicatorPercent.__init__o   s0     
	u%r   c                     Ub  Xl         U R                   S-  U R                  -  nU =R                   U-  sl         X0R                  :  a!  U =R                  U R                  -  sl        U$ g )Nd   )rl   rm   rn   ro   )r9   currentincreasepcts       r   progress!ProgressIndicatorPercent.progress   sX    "LllS 4::- //!OOtyy(OJ "r   c           
         U R                  X5      nUb  Ub  U R                  (       dU  SSKJn  [	        SS9S   nUS:w  a=  Xe" U R
                  [        U/USS -   S/-   5      -  5      -
  n[        US   U5      US'   U R                  U R
                  [        U/U-   5      -  S	US
9$ U R                  U R
                  U-  5      $ g)z
Show and output the progress message

:param current: set the current percentage [None]
:param increase: increase the current percentage [None]
:param info: array of strings to be formatted with msg [None]
Nr   )swidthr	   r   r   r
   rT   F)justifyrd   )	ry   r.   platformr|   r   re   tupler   rU   )r9   rv   rw   rd   rx   r|   r   spaces           r   showProgressIndicatorPercent.show   s     mmG.?yy1 &7%I!%LN%+ .5#QUVYWYQZIZ^`]aIaCb8b1c c#4T"Xu#ER{{488eSEDL.A#A5W[{\\;;txx#~.. r   c                     U R                   (       a&  U R                  XR                  U R                  US9  g U(       a  [	        U5      nU R
                  R                  U5        g )N)r   rv   rm   rd   )r.   rQ   rl   rm   r   r$   rd   )r9   r   r}   rd   s       r   rU   ProgressIndicatorPercent.output   sF    99Wll$**[_`27;KKW%r   )rl   re   ro   rm   rn   )r      r   z%3.0f%%N)Nr   )Nr   N)TN)rX   rY   rZ   r[   rM   r:   ry   r   rU   r]   __classcell__)rr   s   @r   rh   rh   l   s!    "I&"/0& &r   rh   c                   6    \ rS rSrS	S jrS rS rS rS rSr	g)
ProgressIndicatorEndless   Nc                 ^    SU l         SU l        Xl        Uc  [        R                  nX l        g)z
Progress indicator (long row of dots)

:param step: every Nth call, call the func
:param file: output file, default: sys.stderr
r   N)rl   	triggeredro   r)   r*   rI   )r9   ro   rI   s      r   r:   !ProgressIndicatorEndless.__init__   s*     	<::D	r   c                     U =R                   S-  sl         U R                   U R                  -  S:H  nU(       a  U =R                  S-  sl        U$ )Nr   r   )rl   ro   r   r9   triggers     r   ry   !ProgressIndicatorEndless.progress   s=    ,,*a/NNaNr   c                 h    U R                  5       nU(       a  U R                  U R                  5      $ g r=   )ry   rU   r   r   s     r   r   ProgressIndicatorEndless.show   s(    --/;;t~~.. r   c                 0    [        SSU R                  SS9  g )N.rT   T)endrI   rJ   rN   rI   )r9   r   s     r   rU   ProgressIndicatorEndless.output   s    cr		6r   c                 *    [        U R                  S9  g )N)rI   r   r@   s    r   rV   ProgressIndicatorEndless.finish   s    499r   )rl   rI   ro   r   )
   N)
rX   rY   rZ   r[   r:   ry   r   rU   rV   r]   r^   r   r   r   r      s    /
7r   r   )r!   r.   r)   rH   shutilr   r$   r   parseformatr   r   r   r`   rh   r   r^   r   r   <module>r      sX      
  $ "	 *J JZ<4 <;&4 ;&| r   