
    W|h"              
       J   S SK r S SKrS SKrS SKrS SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr  \	" S5      r\c  \	" S5      r\c  Sr\" S	S
S9r\R!                  SSSSS9  \R!                  SSSSSS9  \R!                  SSSSS9  \R!                  SSSSS9  \R!                  SSSSS9  \R!                  SSSSS9  \R!                  SSS SS!\" \5      -  S9  \R#                  5       u  rr\" \5      S":  a"  \R+                  5         \ R,                  " S#5        \S    r\S#   r\R2                  c  \S    rO\R2                  r\R6                  b&  \ R8                  R;                  S \R6                  5         S SKr\RB                  b&  \ R8                  R;                  S \RB                  5         S S%K"J#r#  \\#l$        \\#l%        S S'K&J'r'J(r(  \'" 5       r)\(" 5       r*S( r+S) r,S-S* jr-\R8                  R]                  \5      (       a!  \R_                  S+5      (       a  \+" \\)\*5        g\R`                  " \5       HG  u  r1r2r3\Rh                  " \3S,5       H)  r5\R8                  Rm                  \1\55      r7\+" \7\)\*5        M+     MI     g! \ a	    \ " S$5      ef = f! \ a	    \ " S&5      ef = f).    N)call)OptionParser)find_executable)basename)inputzwhisper-resize.pyzwhisper-resizez%prog storagePath configPath

storagePath   the Path to the directory containing whisper files (CAN NOT BE A
              SUBDIR, use --subdir for that)
configPath    the path to your carbon config files
z	%prog 0.1)usageversionz--doitF
store_truezThis is not a drill, lets do it)defaultactionhelpz-qz--quietzDisplay extra debugging infoz--subdirstringz&only process a subdir of whisper files)r   typer   z--carbonlibzEfolder where the carbon lib files are if its not in your path alreadyz--whisperlibzFfolder where the whisper lib files are if its not in your path alreadyz	--confirmz5ask for comfirmation prior to resizing a whisper filez-xz--extra_args z.pass any additional arguments to the %s script      z\[ERROR] Can't find the whisper module, try using --whisperlib to explicitly include the path)settingszZ[ERROR] Can't find the carbon module, try using --carbonlib to explicitly include the path)loadStorageSchemasloadAggregationSchemasc                    SnSnSnSn[         R                  " U 5      n[        U 5      nU HD  n	U	R                  U5      (       d  M  U	R                   V
s/ s H  oR                  5       PM     nn
  O   U H)  nUR                  U5      (       d  M  UR                  u  p  O   Wc  SnWc  SnW H  nUS   < SUS   < S	3nUU-  nM     US
    H  nUS   < SUS   < S	3nUU-  nM     X4:w  a  SnUSU< SU< S3-  nSR                  US   5      nSR                  U5      nUU:w  a  SnUU< SU< SU< S3-  nXS   :w  a  SnUU< SUS   < SU< S3-  nUSL Gax  [        U /n[        R                  " [        R                  5       H  nUR                  U5        M     UR                  S[        U5      -   5        UR                  S[        U5      -   5        [        R                  " U5       H  nUR                  U5        M     [        R                  SLd  [        R                  SL a  [!        U5        [!        U5        [        R                  SL a2  [        S5      [        l        [        R"                  SL a  [!        S5        [        R"                  SL a7  [%        U5      nUS:  a%  [!        SU-  5        [&        R(                  " S5        ggggs  sn
f )a  
method to process a given metric, and resize it if necessary

Parameters:
    fullPath    - full path to the metric whisper file
    schemas     - carbon storage schemas loaded from config
    agg_schemas - carbon storage aggregation schemas load from confg

r   FNg      ?averager   :r    archivessecondsPerPointpointsTzupdating Retentions from: z to: z 
z{0:.2f}xFilesFactorz xFilesFactor differs real: z should be: aggregationMethodz" aggregation schema differs real: z--xFilesFactor=z--aggregationMethod=z+Would you like to run this command? [y/n]: zSkipping command 
zError running: %s)whisperinfogetMetricFromPathmatchesr   getTupleformatwhisperResizeExecutableshlexsplitoptions
extra_argsappendstrquietconfirmprintdoitr   sysexit)fullPathschemasagg_schemasschema_config_argsschema_file_argsrebuildmessagesr    metricschemaarchivearchive_config
agg_schemar   r   	retentioncurrent_schemafileRetentioninfo_xFilesFactorstr_xFilesFactorcmdxexitcodes                          Z/home/james-whalen/.local/lib/python3.13/site-packages/../../../bin/whisper-auto-resize.pyprocessMetricrG   f   s    GH <<!D x(F >>&!!@FPW..0NP	  "
f%%.8.A.A+L "
  % $	%.q\9Q<@n, $ j)%23D%E}U]G^_N* *
 	.%'9; 	;
 "((n)=> ''5 	--.0@B 	B 	"566T"568IK 	K $&1W//0AJJqM 1

$s<'889

)C0A,BBC/0AJJqM 1 ==$4(?(O#J??d""#PQGL||u$+,<<4CyH1)S12   % a Qs   Kc                     [         R                  R                  [        R                  5      [         R
                  -   nU R                  US5      nUR                  SS5      nUR                  SS5      nU$ )z
this method takes the full file path of a whisper file an converts it
to a gaphite metric name

Parameters:
    filePath - full file path to a whisper file

Returns a string representing the metric name
r   .wsp/.)ospathnormpathr   LOCAL_DATA_DIRsepreplace)filePathdata_dirmetric_names      rF   r!   r!      se     ww 7 78266AH ""8R0K%%fb1K%%c3/K    c                 l     [        U 5      R                  5       nUS;   a  gUS;   a  g[        U5        M4  )z
ask the user if they would like to perform the action

Parameters:
    question       - the question you would like to ask the user to confirm.
    error_response - the message to display if an invalid option is given.
T)yyes)nnoF)r   lowerr.   )questionerror_responseanswers      rF   r-   r-      s<     x&&(\![ n rU   rI   z*.wsp)zValid options : yes or no)8r0   rL   fnmatchr&   
subprocessr   optparser   distutils.spawnr   os.pathr   	six.movesr   r%   option_parser
add_option
parse_argsr(   argslen
print_helpr1   storagePath
configPathsubdirprocessPath
whisperlibrM   insertr   ImportError
SystemExit	carbonlibcarbon.confr   CONF_DIRrO   carbon.storager   r   r3   r4   rG   r!   r-   isfileendswithwalkroot_filesfilterfjoinfullpath rU   rF   <module>r      s    
 	    ! +   **=> "-.>?&"5
    eL	*  ,   )U<	'  )   	@  B   4	_  a   D	`  b   |	@  B   ."8	9	)	*
+  ,
  **,$t9q=HHQK1g!W
 >>q'K..K !HHOOAw))*D  HHOOAw(()C$  %  F 
$&`F*" 77>>+;#7#7#?#?+w4''+.aw/Aww||D!,H(G[9 0 /O  D
 C D DD  C
 B C CCs   5J -J JJ"