U
    Tg                     @   sh  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zd dlZW n ek
r`   e	dY nX ej
dkrpeZeejej ejddZejdddd	d
 ejddddddd ejdddddd
 e \ZZeedkred ned  Zdd Zdd Zdd Zdd Zdd  Ze jes6e	d!e eeZeeZej sVee eed" e dS )#    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                 C   s6   t | t j}tj|t |jtjd}t | |S )N)Zprot)osopenO_RDONLYmmapfstatst_size	PROT_READclose)filenamefdmap r   \/home/ankuromar296_gmail_com/.local/lib/python3.8/site-packages/../../../bin/whisper-dump.py	mmap_file(   s    
r   c                 C   s   z$t tj| d tj \}}}}W n& t jttfk
rJ   tdY nX g }tj}t	|D ]}z&t tj
| ||tj  \}}	}
W n* t jttfk
r   td| Y nX ||	|
|	|
 |
tj d}|| |tj7 }q^tj|d|||d}|S )NzUnable to unpack headerz"Unable to read archive %d metadata)offsetsecondsPerPointpoints	retentionsizeZaverage)aggregationMethodmaxRetentionxFilesFactorarchives)structunpackwhisperZmetadataFormatZmetadataSizeerror
ValueError	TypeErrorZCorruptWhisperFilexrangeZarchiveInfoFormatZarchiveInfoSize	pointSizeappendZaggregationTypeToMethodget)r   ZaggregationTyper"   r#   ZarchiveCountr$   ZarchiveOffsetir   r   r   ZarchiveInfoheaderr   r   r   read_header/   s:    
r1   c                 C   sP   t d t d| d   t d| d   t d| d   t d t| d	  d S )
Nz
Meta data:z  aggregation method: %sr!   z  max retention: %dr"   z  xFilesFactor: %gr#    r$   )printdump_archive_headers)r0   r   r   r   dump_headerU   s    r5   c                 C   sz   t | D ]l\}}td|  td|d   td|d   td|d   td|d	   td
|d   td qd S )NzArchive %d info:z  offset: %dr   z  seconds per point: %dr   z  points: %dr   z  retention: %dr   z
  size: %dr    r2   )	enumerater3   )r$   r/   archiver   r   r   r4   ^   s    r4   c           	   	   C   s   t | D ]\}}|js"td|  |d }t|d D ]}ttjt||tj	  \}}|j
r|jrt|}t|j|}qt|}nt|}|jrtd||f  ntd|||f  |tj	7 }q6t qd S )NzArchive %d data:r   r   z%s:%.35gz%d: %s, %10.35g)r6   rawr3   r+   r%   r&   r'   ZpointFormatr   r,   prettyr
   time	localtimestrftimectimestr)	r$   optionsr/   r7   r   point	timestampvalueZtimestrr   r   r   dump_archivesi   s(    
rC   z![ERROR] File "%s" does not exist!r$   )!r   r   r:   r%   signalsysoptparser'   ImportError
SystemExitversion_inforanger+   SIGPIPESIG_DFLOptionParserZoption_parser
add_option
parse_argsr?   argslenr(   pathr   r1   r5   r4   rC   existsr   r0   r8   r   r   r   r   <module>   sf   
         &	