
    W|ha                        S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKJrJ	r	  S SK
Jr   S SKJr  \R                  " 5       r\R#                  \R$                  5        0 r\R(                  " S5      SS.rS	rS	rS
rS rS rS rS rS rS rS r\ S:X  GaB  \" 5       r!\RD                  " S5      S:w  a  \#" S5        \ RH                  " S5        \!RJ                  (       a  \R#                  \R,                  5        \RL                  " \ RN                  5      r(\RS                  \(5        \!RT                  r\!RJ                  r\!RV                  r\!RX                  r-\!R\                  r/\-S-   r0\-S-   r1\0/r2\!Rf                  (       a  \2Ri                  S5        \!Rj                  (       a  \2Ri                  S5        \" \!Rl                  5        \" \!Rn                  5        gg! \ a
    S SKJr   GNf = f)    N)Pool	cpu_count)	ConfigObj)scandir)listdir.*z1m:7d)match
retentionsF c                     [        U 5      nUR                  5        HV  nUS   S   nUS:X  a  US   S   [        S'   M"  US   S:X  a  USS  nUS   S   [        R                  " U5      S.[
        U'   MX     g )N   patternr   r
   r   ^)r
   r	   )r   itemsDEFAULT_SCHEMArecompileSCHEMA_LIST)cfgschema_confschemaitems       [/home/james-whalen/.local/lib/python3.13/site-packages/../../../bin/update-storage-times.pyconfig_schemasr   #   s    C.K##%ay#4<+1!9\+BN<(Aw#~ABx/5ay/F*,**T*:!<K &    c                     SSSSSSSS.nU R                   " S5      u  p [        R                  U S	   5      (       a  [        U S S	 5      XS	      -  n U $ )
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ZZ_NV
{{4849~"X 66Kr   c                 j   [        U 5       Vs/ s H  n[        U5      PM     nn[        U/n[        R                  " U[        R
                  S9nUR                  5       S   R                  S5      nU Vs/ s H(  nSU;   d  M  [        UR                  S5      S   5      PM*     nnXs:H  $ s  snf s  snf )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+MHX&K##K
HL++-a066t<L9E -#t+ -SC+,M -)) I-s   B+6
B0!B0c              #   $  #    [        U 5       H}  nUR                  SS9(       a"  [        UR                  5       H  nUv   M	     M9  UR	                  SS9(       a   UR
                  R                  S5      (       d  Mo  UR                  v   M     g 7f)NF)follow_symlinksz.wsp)r   is_dir_find_metricspathis_filenameendswith)rE   fsfs      r   rD   rD   E   sh     T]88E8*#AFF+ , 99U93&&//&))&&L s   BBc                    [         (       d  [        R                  S5        / $ [        (       a  [        R	                  SU -  5        [        [        R                  S5      n[        [        5      U /-   n[        S   nU [        [        5      S  R                  SS5      n[         R                  5        H%  u  pVUS   R                  U5      (       d  M   US   n  O   UR!                  [        U5      5        [        (       a  [        R	                  SU-  5        [#        X05      (       a  [        R%                  S	U -  5        S
U 4/$ [&        (       a  SnO[        R%                  SU-  5        [        R(                  " U 5      n[        (       a  [*        R,                  " U5      nO[*        R,                  " UUS9n[        R.                  " XR0                  5        [        R2                  " XR4                  UR6                  5        UR9                  5         [:        R<                  " [>        5         US:w  aM  [        R                  SU -  5        [        R                  SU-  5        [        R                  SU-  5        S
U 4/$ SU 4/$ )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   ;		./	u.782::s#G,'6(2N|,Ic)no&..sC8H#--/=))\*I 0 $y/*u&78),,		86AB  w		(945WWV_5''7C''/68C
$
BII.MMOJJu
 ax		3f<=		+i78		0>AB  vr   c                 f   [         (       d  [        R                  S5        g [        R                  R                  [        U 5      n[        [        5       5      n[        R                  SU-  5        UR                  [        [        U5      S5      nUR                  5         UR                  5         U$ )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      sw    ;		./GGLLF+E	DHHDuLMhhz=#7=GJJLIIKNr   c            	         [         R                  " S5      n U R                  SSSSSS9  U R                  SSS	S
SS9  U R                  SSSSSS9  U R                  SSSSSS9  U R                  SSSSSS9  U R                  SSSSSS9  U R                  SSSSSS9  U R                  SSSS S!S9  U R                  S"S[        S#S$S%S&9  U R	                  5       $ )'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    	    	  + &  W\\ ::d+ ')
	<*	4 n @ zZF	yyF"12||W]]#





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