<s> import sys , os , fnmatch <EOL> from subprocess import call <EOL> from optparse import OptionParser <EOL> option_parser = OptionParser ( <EOL> usage = '''<STR_LIT>''' , version = "<STR_LIT>" ) <EOL> option_parser . add_option ( <EOL> '<STR_LIT>' , default = False , action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" ) <EOL> option_parser . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , default = False , action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" ) <EOL> option_parser . add_option ( <EOL> '<STR_LIT>' , default = None , <EOL> type = '<STR_LIT:string>' , help = "<STR_LIT>" ) <EOL> option_parser . add_option ( <EOL> '<STR_LIT>' , default = None , <EOL> type = '<STR_LIT:string>' , help = "<STR_LIT>" ) <EOL> option_parser . add_option ( <EOL> '<STR_LIT>' , default = None , <EOL> type = '<STR_LIT:string>' , help = "<STR_LIT>" ) <EOL> option_parser . add_option ( <EOL> '<STR_LIT>' , default = False , action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" ) <EOL> option_parser . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , default = '<STR_LIT>' , <EOL> type = '<STR_LIT:string>' , help = "<STR_LIT>" ) <EOL> ( options , args ) = option_parser . parse_args ( ) <EOL> if len ( args ) < <NUM_LIT:2> : <EOL> option_parser . print_help ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> storagePath = args [ <NUM_LIT:0> ] <EOL> configPath = args [ <NUM_LIT:1> ] <EOL> if options . subdir is None : <EOL> processPath = args [ <NUM_LIT:0> ] <EOL> else : <EOL> processPath = options . subdir <EOL> if options . whisperlib is not None : <EOL> sys . path . insert ( <NUM_LIT:0> , options . whisperlib ) <EOL> try : <EOL> import whisper <EOL> except ImportError : <EOL> raise SystemExit ( '<STR_LIT>' ) <EOL> if options . carbonlib is not None : <EOL> sys . path . insert ( <NUM_LIT:0> , options . carbonlib ) <EOL> try : <EOL> from carbon import conf <EOL> from carbon . conf import settings <EOL> except ImportError : <EOL> raise SystemExit ( '<STR_LIT>' ) <EOL> settings . CONF_DIR = configPath <EOL> settings . LOCAL_DATA_DIR = storagePath <EOL> from carbon . storage import loadStorageSchemas , loadAggregationSchemas <EOL> schemas = loadStorageSchemas ( ) <EOL> agg_schemas = loadAggregationSchemas ( ) <EOL> def processMetric ( fullPath , schemas , agg_schemas ) : <EOL> """<STR_LIT>""" <EOL> schema_config_args = '<STR_LIT>' <EOL> schema_file_args = '<STR_LIT>' <EOL> rebuild = False <EOL> messages = '<STR_LIT>' <EOL> info = whisper . info ( fullpath ) <EOL> metric = getMetricFromPath ( fullpath ) <EOL> for schema in schemas : <EOL> if schema . matches ( metric ) : <EOL> archive_config = [ archive . getTuple ( ) for archive in schema . archives ] <EOL> break <EOL> for agg_schema in agg_schemas : <EOL> if agg_schema . matches ( metric ) : <EOL> xFilesFactor , aggregationMethod = agg_schema . archives <EOL> break <EOL> for retention in archive_config : <EOL> current_schema = '<STR_LIT>' % ( retention [ <NUM_LIT:0> ] , retention [ <NUM_LIT:1> ] ) <EOL> schema_config_args += current_schema <EOL> for fileRetention in info [ '<STR_LIT>' ] : <EOL> current_schema = '<STR_LIT>' % ( fileRetention [ '<STR_LIT>' ] , fileRetention [ '<STR_LIT>' ] ) <EOL> schema_file_args += current_schema <EOL> if ( schema_config_args != schema_file_args ) : <EOL> rebuild = True <EOL> messages += '<STR_LIT>' % ( schema_file_args , schema_config_args ) <EOL> info_xFilesFactor = "<STR_LIT>" . format ( info [ '<STR_LIT>' ] ) <EOL> str_xFilesFactor = "<STR_LIT>" . format ( xFilesFactor ) <EOL> if ( str_xFilesFactor != info_xFilesFactor ) : <EOL> rebuild = True <EOL> messages += '<STR_LIT>' % ( metric , info_xFilesFactor , str_xFilesFactor ) <EOL> if ( aggregationMethod != info [ '<STR_LIT>' ] ) : <EOL> rebuild = True <EOL> messages += '<STR_LIT>' % ( metric , info [ '<STR_LIT>' ] , aggregationMethod ) <EOL> if ( xFilesFactor != info [ '<STR_LIT>' ] ) : <EOL> rebuild = True <EOL> messages += '<STR_LIT>' % ( metric , info [ '<STR_LIT>' ] , xFilesFactor ) <EOL> if ( rebuild == True ) : <EOL> cmd = '<STR_LIT>' % ( fullPath , options . extra_args , xFilesFactor , aggregationMethod , schema_config_args ) <EOL> if ( options . quiet != True or options . confirm == True ) : <EOL> print ( messages ) <EOL> print ( cmd ) <EOL> if ( options . confirm == True ) : <EOL> options . doit = confirm ( "<STR_LIT>" ) <EOL> if ( options . doit == False ) : <EOL> print ( "<STR_LIT>" ) <EOL> if ( options . doit == True ) : <EOL> exitcode = call ( cmd , shell = True ) <EOL> if ( exitcode > <NUM_LIT:0> ) : <EOL> print ( '<STR_LIT>' % ( cmd ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def getMetricFromPath ( filePath ) : <EOL> """<STR_LIT>""" <EOL> data_dir = os . path . normpath ( settings . LOCAL_DATA_DIR ) + os . sep <EOL> metric_name = filePath . replace ( data_dir , '<STR_LIT>' ) <EOL> metric_name = metric_name . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> metric_name = metric_name . replace ( '<STR_LIT:/>' , '<STR_LIT:.>' ) <EOL> return metric_name <EOL> def confirm ( question , error_response = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> while True : <EOL> answer = raw_input ( question ) . lower ( ) <EOL> if answer in ( '<STR_LIT:y>' , '<STR_LIT:yes>' ) : <EOL> return True <EOL> if answer in ( '<STR_LIT:n>' , '<STR_LIT>' ) : <EOL> return False <EOL> print ( error_response ) <EOL> for root , _ , files in os . walk ( processPath ) : <EOL> for f in fnmatch . filter ( files , '<STR_LIT>' ) : <EOL> fullpath = os . path . join ( root , f ) <EOL> processMetric ( fullpath , schemas , agg_schemas ) </s>
