
    Dh*                        d dl m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mZm	Z	m
Z
 d dlZd
dZddZdddZ	 	 	 	 	 	 	 	 ddZed	k(  r e        yy)    )annotationsN)Path)IOBinaryIOTextIOc                   dddddd}d}| j                  d      r0t        j                  | dd	       j                         j                  S | d
   j                         |v r|| d
   j                            }| d	d
 } t        |       d|z  z  S )a  
    Convert a size string with suffixes 'k', 'm', etc., to bytes.

    Note: This function also supports '@' as a prefix to a file path to get the
    file size.

    >>> size_to_bytes('1024k')
    1048576
    >>> size_to_bytes('1024m')
    1073741824
    >>> size_to_bytes('1024g')
    1099511627776
    >>> size_to_bytes('1024')
    1024
    >>> size_to_bytes('1024p')
    1125899906842624
                   )kmgtpr   @N   )
startswithpathlibr   statst_sizelowerint)size_strsuffix_exponentexponents      v/var/www/fastuser/data/www/generator.snapmosaic.io/flask_app/venv/lib/python3.12/site-packages/progressbar/__main__.pysize_to_bytesr       s    * O H 3||HQRL)..0888 |."8B<#5#5#78CR= x=D(N++    c                 $   t        j                  d      } | j                  dddd       | j                  dd	dd
       | j                  dddd       | j                  dddd       | j                  dddd       | j                  dddd       | j                  dddd       | j                  dddd       | j                  dddd       | j                  d d!t        d"#       | j                  d$d%t        d&#       | j                  d'd(dd)       | j                  d*d+dd,       | j                  d-d.dd/       | j                  d0d1t
        d2#       | j                  d3d4t        d5#       | j                  d6d7dd8       | j                  d9d:dd;       | j                  d<d=t
        d>#       | j                  d?d@t        dA#       | j                  dBdCt        dD#       | j                  dEdFt        dG#       | j                  dHdIt        dJ#       | j                  dKdLddM       | j                  dNdOddP       | j                  dQdRt        dS#       | j                  dTdUt        dV#       | j                  dWdXddY       | j                  dZd[dd\       | j                  d]d^t        d_#       | j                  d`daddb       | j                  dcdddde       | j                  dfdgddh       | j                  didjddk       | j                  dldmt        dn#       | j                  dodpt        dq#       | j                  drdst        j                  dt#       | j                  dudvdwdxy       | j                  dzd{dwd|}       | S )~zC
    Create the argument parser for the `progressbar` command.
    z
        Monitor the progress of data through a pipe.

        Note that this is a Python implementation of the original `pv` command
        that is functional but not yet feature complete.
    )descriptionz-pz
--progress
store_truezTurn the progress bar on.)actionhelpz-tz--timerzTurn the timer on.z-ez--etazTurn the ETA timer on.z-Iz--finetaz)Display the ETA as local time of arrival.z-rz--ratezTurn the rate counter on.z-az--average-ratez!Turn the average rate counter on.z-bz--byteszTurn the total byte counter on.z-8z--bitsz$Display total bits instead of bytes.z-Tz--buffer-percentz/Turn on the transfer buffer percentage display.z-Az--last-writtenz Show the last NUM bytes written.)typer&   z-Fz--formatz/Use the format string FORMAT for output format.z-nz	--numericzNumeric output.z-qz--quietz
No output.z-Wz--waitz/Wait until the first byte has been transferred.z-Dz--delay-startzDelay start.z-sz--sizezAssume total data size is SIZE.z-lz--line-modezCount lines instead of bytes.z-0z--nullz(Count lines terminated with a zero byte.z-iz
--intervalzInterval between updates.z-mz--average-rate-windowz$Window for average rate calculation.z-wz--widthz)Assume terminal is WIDTH characters wide.z-Hz--heightz$Assume terminal is HEIGHT rows high.z-Nz--namez$Prefix output information with NAME.z-fz--forcezForce output.z-cz--cursorz(Use cursor positioning escape sequences.z-Lz--rate-limitz(Limit transfer to RATE bytes per second.z-Bz--buffer-sizez"Use transfer buffer size of BYTES.z-Cz--no-splicezNever use splice.z-Ez--skip-errorszIgnore read errors.z-Zz--error-skip-blockz%Skip block size when ignoring errors.z-Sz--stop-at-sizez#Stop transferring after SIZE bytes.z-Yz--syncz/Synchronise buffer caches to disk after writes.z-Kz--direct-ioz(Set O_DIRECT flag on all inputs/outputs.z-Xz	--discardz.Discard input data instead of transferring it.z-dz	--watchfdz!Watch file descriptor of process.z-Rz--remotez.Remote control another running instance of pv.z-Pz	--pidfilezSave process ID in FILE.inputz-Input file path. Uses stdin if not specified.-*)r&   defaultnargsz-oz--outputz/Output file path. Uses stdout if not specified.)r+   r&   )argparseArgumentParseradd_argumentr   strfloatr   r   )parsers    r   create_argument_parserr3   <   s   
 $$F (	   i3G   gl1I   8	   h|2M   0	   .	   3	   >	   /	   >	   k,5F   	   >	   oEO
hS'H   ,	   7	   l-H   3	   8	   js)O   hS'M   i?   7	   7	   1	   mL7J   ol9N   4	   2	   >	   7	   =	   k*M   =	   k3M   <	   >	   Mr!   c           	        t               }|j                  |       }t        j                         5 }t	        |j
                  |j                  |      }g }d}d}|j                  D ]  }|dk(  r:|j                  rt        j                  }	nt        j                  j                  }	d}nbt        j                  |      }	|	j                         s|j                  d|        |j                  s||	j!                         j"                  z  }|j%                  |	        |j                  rt'        |j                        }d}|rRt)        j*                         dt)        j,                         dt)        j.                         dt)        j0                         g}
n=t)        j2                         dt)        j4                         dt)        j.                         g}
|j6                  r4|
j%                  d       |
j%                  t)        j8                                t)        j:                  |xs dd      }|j<                  rt'        |j<                        nd	}d}|j?                          t        j@                  tB              5  |D ]  }	tE        |	t        j                        r/|jG                  |	jI                  |j                  rd
nd            }n|	}	 |j                  r|jK                  |      }n|jM                  |      }|s|jO                  |       |tQ        |      z  }|jS                  |       c 	 ddd       |jU                  d       ddd       y# 1 sw Y   $xY w# 1 sw Y   yxY w)z
    Main function for the `progressbar` command.

    Args:
        argv (list[str] | None): Command-line arguments passed to the script.

    Returns:
        None
    r   Tr)   FzFile not found:  N)	max_value	max_errorr   rrb)dirty)+r3   
parse_args
contextlib	ExitStack_get_output_streamoutput	line_moder(   sysstdinbufferr   r   existserrorsizer   r   appendr    progressbar
PercentageBarTimerFileTransferSpeedSimpleProgressDataSizeetaAdaptiveETAProgressBarbuffer_sizestartsuppressKeyboardInterrupt
isinstanceenter_contextopenreadlinereadwritelenupdatefinish)argvr2   argsstackoutput_streaminput_paths
total_sizefilesize_availablefilename
input_pathwidgetsbarrR   total_transferredinput_streamdatas                   r   mainrm     s    '=&>F%006D				 ]5/AKK0
 HJ
#'

 	+H3>>!$J!$!1!1J%*"$\\(3
!((*LL#3H:!>?yy*//"3";";;Jz*#	+( 99&tyy1J!% &&(!!!#--/G **,$$&!!#G 88NN3NN;2245 %% (D
 04/?/?M$**+T 	 		  !23 	2) 2
j',,7#(#6#6"t~~4H$L $.L~~+44[A+00=!''-%T2%JJ01 2	2. 	


{] ]L	2 	2M] ]s%   IM8B6M/MM	MM'c                    | r&| dk7  r!|rdnd}|j                  t        | |            S |rt        j                  S t        j                  j                  S )Nr)   wwb)rW   rX   rA   stdoutrC   )r?   r@   ra   modes       r   r>   r>     sK    
 &C-sT""4#566	zzzz   r!   __main__)r   r0   returnr   )rt   zargparse.ArgumentParser)N)r_   zlist[str] | Nonert   None)r?   z
str | Noner@   boolra   zcontextlib.ExitStackrt   ztyping.IO[typing.Any])
__future__r   r-   r<   r   rA   typingr   r   r   r   rH   r    r3   rm   r>   __name__ r!   r   <module>r{      st    "    
   ' ' +,\TnjZ!!!  ! 	! zF r!   