+
    h7  c                   s    ^ RI t ^ RIt^ RIt^ RIt^ RItRR ltRsRsRR lt ! R R4      t	 ! R R4      t
R tR	 t ! R
 R]
4      t ! R R4      tRR ltR tR# )    Nc                s     Rp\         P                  ! V \        P                  V4      p\        P
                  ! RV4      ^,          pT;'       g    ^P#   \         d     ^P# i ; i)zGet the real terminal widthZabcdefghZhhhh)fcntlZioctltermiosZ
TIOCGWINSZstructZunpackZIOError)fdZbufZrets   &  1/usr/share/virt-manager/virtinst/_progresspriv.pyterminal_widthr      sW    kk"g00#6mmFC(+yyb s   AA A A#"A#c                s    \         P                   ! 4       p\        e   V\        ,
          V8  d   \        V 4      sVs\        # )z4Get the real terminal width, but cache it for a bit.)time_term_width_val_term_width_lastr   )r   cache_timeoutnow   && r   terminal_width_cachedr   $   s8    
 ))+C3)9#9]"J(,    c                   sN   a  ] tR t^0t o RtR	R ltR tR
R ltRR ltR t	Rt
V tR# )TerminalLinez@Help create dynamic progress bars, uses terminal_width_cached().Nc                s`    Vf   TpWn         \        \        W44      V4      V n        RV n        R # )NF)_min_lenmaxr   llen_fin)selfZmin_restZbeg_lenr   r
   s   &&&&&r   __init__ZTerminalLine.__init__3   s,    ?G -b@'J		r   c                <    V P                   V P                  ,
          # )zUsable length for elements.)r   r   r      &r   __len__ZTerminalLine.__len__:   s    yy4==((r   c                sJ    \        V P                  V,
          ^ 4      V,          # )ziAfter a fixed length, split the rest of the line length among
a number of different elements (default=2).)r   r   )r   ZfixedZelements   &&&r   
rest_splitZTerminalLine.rest_split>   s     499u$a(H44r   c                s    Vf   \        V4      p\        V 4      V8  d   RV n        V P                  '       d   R# V ;P                  \        V4      ,          un        V# )z}If there is room left in the line, above min_len, add element.
Note that as soon as one add fails all the rest will fail too.T )lenr   r   )r   ZelementZfull_lenr   r   addZTerminalLine.addC   sI     7|Ht9xDI999		S\!	r   c                    V P                   # )z?Current rest of line, same as .rest_split(fixed=0, elements=1).)r   r   r   r   restZTerminalLine.restQ   s    yyr   )r   r   r   )r    N         ?)i   N)__name__
__module____qualname____firstlineno__Z__doc__r   r   r   r   r    __static_attributes____classdictcell__Z__classdict__   @r   r   r   0   s&     J)5
 r   r   c                   sD   a  ] tR t^Vt o R tR tR tR tR tR t	Rt
V tR# )		BaseMeterc                sx    R V n         RV n        RV n        RV n        ^ V n        RV n        \        4       V n        R# )g333333?N)update_periodtextsize
start_timelast_amount_readlast_update_timeRateEstimatorrer   r   r   r   ZBaseMeter.__init__W   s8     		 ! $/r   c                s   Wn         W n        \        V4      \        \        R 4      39   g   Q hV P                   f   Q h\        P                  ! 4       pW0n        V P                  P                  W#4       ^ V n        W0n	        R # r#   )
r.   r/   typeintr   r0   r4   startr1   r2   )r   r.   r/   r   s   &&& r   r7   ZBaseMeter.starta   se    		Dzc4:....yy$$$iikd  ! #r   c                s4   \        V4      \        J g   Q h\        P                  ! 4       pWn        V P                  P                  W4       V P                  '       d"   W P                  V P                  ,           8  d   W n        V P                  V4       R # R # r#   )	r5   r6   r   r1   r4   updater2   r-   
_do_update)r   amount_readr   r   r   r8   ZBaseMeter.updatem   sr     K C'''iik +{($$$0E0EHZHZ0Z)Z$'!OOK( *[r   c                    R # r#    )r   r:      &&r   r9   ZBaseMeter._do_updatey       r   c                s&    V P                  4        R # r#   )_do_endr   r   r   endZBaseMeter.end|   s    r   c                r;   r#   r<   r   r   r   r?   ZBaseMeter._do_end   r>   r   )r1   r2   r4   r/   r0   r.   r-   N)r$   r%   r&   r'   r   r7   r8   r9   r@   r?   r(   r)   r*   r+   r   r,   r,   V   s(     "
$
) r   r,   c                 s    W,          p\        V4      pR V,          pW4,
          R8  d
   VR,          pV P                  RWV3,          4      # )Z=g      ?Z-z	 [%-*.*s])r6   r   )tlZbar_max_lengthZpcZbar_lenZibar_lenZprogressbars   &&&   r   _term_add_barrB      sJ    !G7|H.Ks"s66+ MMNNr   c                 s    V'       d3   W!8  d   V P                  R 4      R3# W!8w  d   V P                  R4      R3# V P                  R4      R3# )z !!! Tz ... F     )r   )rA   Zosizer/   r   r   _term_add_endrD      sH    <66'?D((]66'?D((66'?E!!r   c                   sL   a  ] tR t^t o ]P
                  3R ltR tR tRt	V t
R# )	TextMeterc                s<    \         P                  V 4       Wn        R # r#   )r,   r   output)r   rF   r=   r   r   ZTextMeter.__init__   s    4 r   c           
     s   V P                   P                  4       p\        V4      p\        V P                   P                  4       4      p\	        ^^4      p\        VP                  ^P8  4      pVP                  RV,          4      pV P                  f   VP                  R\        W&4      ,          4      pVP                  R	4      p	VP                  RV,          4      p
RVP                  4       VP                  4       V P                  V
VVV	3,          pMV P                   P                  4       p\        W4      pV P                   P                  4       pVP                  RV,          4      pVP                  R4      p	VP                  RV^d,          ,          4      pVP                  RV,          4      p
^VP                  ^4      ,           p\        VVV4      pRVP                  4       VP                  4       V P                  VVV
VVV	3	,          pV P                   P#                  V4       V P                   P%                  4        R# )
    | %5sBN  %sz %5sB/sz%-*.*s%s%s%s%sz ETA z %2i%%z%-*.*s%s%s%s%s%s%srC   )r4   elapsed_timeformat_numberaverage_rater   boolr   r   r/   format_timer    r.   remaining_timefraction_readr   rB   rF   writeflush)r   r:   ZetimeZfreadZave_dlrA   	use_hoursui_sizeui_timeui_endZui_rateoutZrtimeZfrtimeZfracZui_pcZblenZui_bars   &&                r   r9   ZTextMeter._do_update   s   $$&k*tww3356 !Y'2&	&&U*+99ffVk%&CCDGVVG_FffY/0G$				( C GG**,E 2F77((*DffVf_-GVVG_FFF8tcz23EffY/0Gr}}Y//D"2tT2F*				
. 
C 	#r   c                sp   V P                   p\        V4      p\        ^4      p\        VP                  ^P8  4      pVP                  R\        V P                  P                  4       V4      ,          4      p\        W0P                  V4      w  rgV'       g!   V^ 8X  d   VP                  RR,          4      pMVP                  RV,          4      pRVP                  4       VP                  4       V P                  WV3,          p	V P                  P                  V	4       V P                  P                  4        R# )rG   rI   z | %5s  rH   z%-*.*s%s%s%s
N)r1   rK   r   rM   r   r   rN   r4   rJ   rD   r/   r    r.   rF   rQ   rR   )
r   r:   Z
total_sizerA   rS   rU   rV   Znot_donerT   rW   s
   &         r   r?   ZTextMeter._do_end   s    ++";/
!_2&	&&+dgg.B.B.Di"PPQ(YYDK1,ffY_-GffY34G BGGIrwwy$))WW]#^^#r   )rF   N)r$   r%   r&   r'   sysZstderrr   r9   r?   r(   r)   r*   r+   r   rE   rE      s!     !jj 2h r   rE   c                   sZ   a  ] tR tRt o RR ltR tR tR tR tR t	R t
R	 tR
 tRtV tR# )r3   i  c                sX    Wn         R V n        R V n        R V n        ^ V n        R V n        R # r#   )	timescaletotalr0   r2   r1   ave_rate)r   rZ   r=   r   r   ZRateEstimator.__init__  s,    "
 $ !r   c                sF    Wn         W n        W n        ^ V n        RV n        R# r    N)r[   r0   r2   r1   r\   )r   r[   r   r   r   r7   ZRateEstimator.start  s!    
 # !r   c                s:   V^ 8X  g   WP                   8  d   W n        Wn         RV n        R# W P                  ,
          pWP                   ,
          pV P                   '       d3   W n        V P                  W4V P                  V P                  4      V n        Wn         R# r]   )r1   r2   r\   _temporal_rolling_averZ   )r   r:   r   	time_diff	read_diffs   &&&  r   r8   ZRateEstimator.update&  s    !{-B-BB$'!$/! DM///	"7"77	   $'! 66dmmT^^DM !,r   c                r   )z/get the average transfer rate (in bytes/second))r\   r   r   r   rL   ZRateEstimator.average_rate:  s    }}r   c                r   )zEthe time between the start of the transfer and the most recent update)r2   r0   r   r   r   rJ   ZRateEstimator.elapsed_time>  s    $$t66r   c                s    V P                   '       d   V P                  '       g   R# V P                  V P                  ,
          V P                   ,          # )zestimated time remainingN)r\   r[   r1   r   r   r   rO   ZRateEstimator.remaining_timeB  s4    }}}DJJJ

T222dmmCCr   c                s    V P                   f   R# V P                   ^ 8X  d   R# \        V P                  4      V P                   ,          # )zSthe fraction of the data that has been read
(can be None for unknown transfer size)Nr"   )r[   floatr1   r   r   r   rP   ZRateEstimator.fraction_readH  s9     ::::?T**+djj88r   c                sJ    \        W,          R4      pV P                  WW54      # )aI  a temporal rolling average performs smooth averaging even when
updates come at irregular intervals.  This is performed by scaling
the "epsilon" according to the time since the last update.
Specifically, epsilon = time_diff / timescale

As a general rule, the average will take on a completely new value
after 'timescale' seconds.r"   )Zmin_rolling_ave)r   r_   r`   last_averZ   epsilon   &&&&& r   r^   Z#RateEstimator._temporal_rolling_aveS  s&     i+S1  xIIr   c                s     W!,          pVf   V# Vf   V# WE,          ^V,
          V,          ,           #   \          d    Rp L8i ; i)a+  perform a "rolling average" iteration
a rolling average "folds" new data into an existing average with
some weight, epsilon.  epsilon must be between 0.0 and 1.0 (inclusive)
a value of 0.0 means only the old value (initial value) counts,
and a value of 1.0 means only the newest value is considered.N)ZZeroDivisionError)r   r_   r`   rc   rd   Zrecent_ratere   r   rb   ZRateEstimator._rolling_ave^  sW    	#/K O $Gx'??? ! 	K	s   3 AA)r\   r1   r2   r0   rZ   r[   N)g      @)r$   r%   r&   r'   r   r7   r8   rL   rJ   rO   rP   r^   rb   r(   r)   r*   r+   r   r3   r3     s;     ,(7D9	J@ @r   r3   c                 s    V e   V ^ 8  d   V'       d   R# R# V \        R4      8X  d   R# \        V 4      p V ^<,          pV ^<,          p V'       d   V^<,          pV^<,          pRW2V 3,          # RW 3,          # )Nz--:--:--z--:--ZinfZInfinitez%02i:%02i:%02iz	%02i:%02i)ra   r6   )ZsecondsrS   ZminutesZhourss   &&  r   rN   rN   r  ss    'A+	E%L	 g,R-B,rMElG#uw&???'!333r   c                s$   . ROpRpRp^ p\        V4      ^,
          pT ;'       g    ^ p W8  d   WE8  d   V^,           pW,          p K  \        V \        4      '       d   RpMV R8  d   RpMRpT\        T ;'       g    ^ 4      RW,          3,          # )	z4Turn numbers into human-readable metric-like numbersg      @i  z%i%s%sgfffff#@z%.1f%s%sz%.0f%s%srX   )	r   ZkZMZGZTZPZEZZZY)r   Z
isinstancer6   ra   )ZnumberZsymbolsZstepZthreshZdepthZ	max_depthZfmts   &      r   rK   rK     s    
G DFEGq I[[qF
 /e/	&# 	$ %!$c7>:::r   )r!   )r!   r"   )r    )r   r   rY   r   r   r   r   r	   r   r   r,   rB   rD   rE   r3   rN   rK   r<   r   r   <module>rf      sv      
    	# #L* *zO"J	 JbY@ Y@x4(&;r   