
    #wg                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlZ	 d dlZej                  dk\  reZ ej                  ej                  ej                          ej                  d      Zej#                  dddd	
       ej#                  dddddd       ej#                  ddddd
       ej%                         \  ZZ ee      dk7  rej-                  d       ned    Zd Zd Zd Zd Zd Ze j.                  j;                  e      s e	dez         ee      Z ee      Zej@                  s ee        eed   e       y# e$ r	  e	d      w xY w)    Nz6[ERROR] Please make sure whisper is installed properly)   r   z
%prog path)usagez--prettyF
store_truez4Show human-readable timestamps instead of unix times)defaultactionhelpz-tz--time-formatstorestringtime_formatz5Time format to use with --pretty; see time.strftime())r   typedestr   z-rz--rawzFDump value only in the same format for whisper-update (UTC timestamps)   zrequire one input file namec                     t        j                  | t         j                        }t        j                  |t        j                  |      j
                  t        j                        }t        j                  |       |S )N)prot)osopenO_RDONLYmmapfstatst_size	PROT_READclose)filenamefdmaps      ^/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/../../../bin/whisper-dump.py	mmap_filer   (   sJ    	wwx%"		"bhhrl**@#((2,	*    c                    	 t        j                  t        j                  | d t        j                         \  }}}}g }t        j                  }t        |      D ]  }	 t        j                  t        j                  | ||t        j                  z          \  }}	}
||	|
|	|
z  |
t        j                  z  d}|j                  |       |t        j                  z  } t        j                  j                  |d      |||d}|S # t         j
                  t        t        f$ r t        j                  d      w xY w# t         j
                  t        t        f$ r t        j                  d|z        w xY w)NzUnable to unpack headerz"Unable to read archive %d metadata)offsetsecondsPerPointpoints	retentionsizeaverage)aggregationMethodmaxRetentionxFilesFactorarchives)structunpackwhispermetadataFormatmetadataSizeerror
ValueError	TypeErrorCorruptWhisperFilexrangearchiveInfoFormatarchiveInfoSize	pointSizeappendaggregationTypeToMethodget)r   aggregationTyper'   r(   archiveCountr)   archiveOffsetir    r!   r"   archiveInfoheaders                r   read_headerr@   /   sp   @g,,c2G73G3G.HI @_lL,
 (&&-, -aQ*0--!!M-'*A*AAB+'v ("V+w(((K OOK W,,,M#-( !88<<_iX  	& 
-? ,,
I	. @

$
$%>
??@ LL*i0 Q&&'Ka'OPPQs   :D <D94D697E0c                     t        d       t        d| d   z         t        d| d   z         t        d| d   z         t        d       t        | d	          y )
Nz
Meta data:z  aggregation method: %sr&   z  max retention: %dr'   z  xFilesFactor: %gr(    r)   )printdump_archive_headers)r?   s    r   dump_headerrE   U   sX    "V,?%@@A~ 667vn556)vj)*r   c                    t        |       D ]s  \  }}t        d|z         t        d|d   z         t        d|d   z         t        d|d   z         t        d|d	   z         t        d
|d   z         t        d       u y )NzArchive %d info:z  offset: %dr    z  seconds per point: %dr!   z  points: %dr"   z  retention: %dr#   z
  size: %dr$   rB   )	enumeraterC   )r)   r=   archives      r   rD   rD   ^   s    h' ja	
q
 !	.78,
,-	
#g.?&@
@A	.78,
,-	
gk2
23	,
()	"Ir   c           	      |   t        |       D ]-  \  }}|j                  st        d|z         |d   }t        |d         D ]  }t	        j
                  t        j                  t        ||t        j                  z          \  }}|j                  rX|j                  r6t        j                  |      }t        j                  |j                  |      }n!t        j                  |      }nt!        |      }|j                  rt        d||fz         nt        d|||fz         |t        j                  z  } t         0 y )NzArchive %d data:r    r"   z%s:%.35gz%d: %s, %10.35g)rG   rawrC   r3   r*   r+   r,   pointFormatr   r6   prettyr   time	localtimestrftimectimestr)	r)   optionsr=   rH   r    point	timestampvaluetimestrs	            r   dump_archivesrW   i   s   h' 
ja;;"#XF)* "!==F6G---.y% 
NN9-'MM'"5"5w?'JJy)'i.	jIu--.5'5"99:!!!f#"$ 
-
r   z![ERROR] File "%s" does not exist!r)   )!r   r   rM   r*   signalsysoptparser,   ImportError
SystemExitversion_inforanger3   SIGPIPESIG_DFLOptionParseroption_parser
add_option
parse_argsrR   argslenr/   pathr   r@   rE   rD   rW   existsr   r?   rJ    r   r   <module>rj      s   
     
 M v& fnnfnn -%%%,<=   eL=  ?   h]>  @   |O  Q  **,$t9>34	a$#L+
4 
ww~~d6=>>o	S	{{f fZ ' *{  MKLLMs   E
 
E