
    #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mZm	Z	 d dl
mZ 	 d dlmZ  ej                         Zej#                  ej$                         i Z ej(                  d      ddZd	Zd	Zd
Zd Zd Zd Zd Zd Zd Zd Ze dk(  r2 e       Z! ejD                  d      dk7  r e#d        e jH                  d       e!jJ                  rej#                  ej,                          ejL                  e jN                        Z(ejS                  e(       e!jT                  Ze!jJ                  Ze!jV                  Ze!jX                  Z-e!j\                  Z/e-dz   Z0e-dz   Z1e0gZ2e!jf                  re2ji                  d       e!jj                  re2ji                  d        ee!jl                          ee!jn                         yy# e$ r
 d dlmZ Y w xY w)    N)Pool	cpu_count)	ConfigObj)scandir)listdir.*z1m:7d)match
retentionsF c                     t        |       }|j                         D ]Q  }|d   d   }|dk(  r|d   d   t        d<    |d   dk(  r|dd  }|d   d   t        j                  |      dt
        |<   S y )N   patternr   r
   r   ^)r
   r	   )r   itemsDEFAULT_SCHEMArecompileSCHEMA_LIST)cfgschema_confschemaitems       f/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/../../../bin/update-storage-times.pyconfig_schemasr   #   s    C.K##% <ay#4<+1!9\+BN<(Aw#~ABx/5ay/F*,**T*:!<K<    c                     dddddddd} | j                   d      \  }} t        j                  | d	         rt        | d d	       || d	      z  } | S )
Nr   <   i  iQ i:	 i3)smhmindwy:)splitstrisalphaint)timeseconds_dictpointss      r   _convert_secondsr.   1   s^    $rV(<LTZZ_NVT
{{4849~T"X 66Kr   c                 \   t        |       D cg c]  }t        |       }}t        |g}t        j                  |t        j
                        }|j                         d   j                  d      }|D cg c]#  }d|v rt        |j                  d      d         % }}||k(  S c c}w c c}w )Nstdoutr   
	retentionr%   r   )	listr.   INFO_BIN
subprocessPopenPIPEcommunicater'   r*   )r3   tmp_pathr   new_retentioninfo_stringcur_ret_listlinecur_retentions           r   _compare_retentionr@   :   s    8<YH%d+HMHX&K##K
HL++-a066t<L9E -#t+ C+, -M -M)) I-s   B$5(B)c              #     K   t        |       D ]o  }|j                  d      rt        |j                        D ]  }|  4|j	                  d      r|j
                  j                  d      sb|j                   q y w)NF)follow_symlinksz.wsp)r   is_dir_find_metricspathis_filenameendswith)rE   fsfs      r   rD   rD   E   sp     T] 88E8*#AFF+  99U93&&//&)&&Ls   A?Bc                    t         st        j                  d       g S t        rt        j	                  d| z         t        t        j                  d      }t        t              | gz   }t        d   }| t        t              d  j                  dd      }t         j                         D ]   \  }}|d   j                  |      s|d   } n |j!                  t        |             t        rt        j	                  d|z         t#        ||       rt        j%                  d	| z         d
| fgS t&        rd}nt        j%                  d|z         t        j(                  |       }t        rt+        j,                  |      }nt+        j,                  ||      }t        j.                  | |j0                         t        j2                  | |j4                  |j6                         |j9                          t;        j<                  t>               	 |dk7  rMt        j                  d| z         t        j                  d|z         t        j                  d|z         d
| fgS d| fgS )NDidn't initialize schemas!zTesting %s for modificationr#   r
   /.r	   zCreated command: %sz$%s has the same retention as before!Fr   zRetention will be %sr0   zFailed to update schemas for %szAttempted retention: %szAttempted command string: %sT) r   LOGerrorDEBUGinfoopenosdevnullr4   BASE_COMMANDr   len	ROOT_PATHreplace	iteritemssearchextendr@   debugDRY_RUNstatr6   
check_callchmodst_modechownst_uidst_gidcloser+   sleepSLEEP)	metricrU   command_stringr3   matchingr   rR   ressts	            r   
fix_metricrn   Q   s   		./	.782::s#G,'6(2N|,Ic)no&..sC8H#--/ =)\*I $y/*&78)V,		86AB  		(945WWV_''7C''/68C
$
BII.MMOJJu
 ax		3f<=		+i78		0>AB  vr   c                 \   t         st        j                  d       y t        j                  j                  t        |       }t        t                     }t        j                  d|z         |j                  t        t        |      d      }|j                          |j                          |S )NrL   z5Creating new storage schemas for metrics under %s ...d   )r   rO   rP   rT   rE   joinrX   r   r   rR   maprn   rD   rf   )subdirfpathpoolresultss       r   search_and_fixrw      su    		./GGLLF+E	DHHDuLMhhz=#7=GJJLIIKNr   c                     t        j                  d      } | j                  ddddd       | j                  ddd	d
d       | j                  ddddd       | j                  ddddd       | j                  ddddd       | j                  ddddd       | j                  ddddd       | j                  dddd d!       | j                  d"dt        d#d$d%&       | j	                         S )'Nz2Correct storage settings on multiple whisper filesz--cfgstorer   z"The storage-schemas.conf file pathT)actiondesthelprequiredz--pathrE   z The root path to find metrics inz--debug
store_truer]   zDisplay debug informationF)rz   r{   r|   defaultz	--dry-rundry_runzDon't actually do anythingz--subdirrs   z/If you only want to process a particular subdirr   
--nobackupnobackupz:Passed through to whisper-resize.py, don't create a backup--aggregate	aggregatez3Passed through to whisper-resize.py, roll up valuesz--bindirbindirz6The root path to whisper-resize.py and whisper-info.pyz/opt/graphite/binz--sleeprg   z?Sleep this amount of time in seconds between metric comparisonsg333333?)rz   typer{   r|   r   )argparseArgumentParseradd_argumentfloat
parse_args)parsers    r   cli_optsr      sM   $$%YZF
eA!%  ' v?!%  ' 	,W8 %  ' Ly9 %  ' 
7N "  $ \
Y %  ' lR %  ' 
7U 3  5 	'G^ #  % r   __main__USERrootz!You must run this script as root!r   z/whisper-resize.pyz/whisper-info.pyr   r   )8sysrT   loggingr6   r   r   r+   multiprocessingr   r   	configobjr   r   ImportErrorr   	getLoggerrO   setLevelINFOr   r   r   rQ   r^   rX   r   r.   r@   rD   rn   rw   r   __name__i_argsgetenvprintexitr]   StreamHandlerr1   soh
addHandlerrE   r   r   BINDIRrg   rh   
RESIZE_BINr5   rV   r   appendr   r   rs    r   r   <module>r      s    	    	  + & g W\\ %2::d+ ')
	<*	4 n @ zZFryyF"12||W]]#
'




+CNN3ILLEnnG]]FLLE..J**H<LL)M*6::6==!5 G  &%%&s   G	 	GG