<s> import sys <EOL> import time <EOL> import timeit <EOL> import logging <EOL> import logging . config <EOL> import traceback <EOL> from . ModelProcessor import ModelProcessor <EOL> from . ControllerProcessor import ControllerProcessor <EOL> from . ValidatorProcessor import ValidatorProcessor <EOL> from . MigratorProcessor import MigratorProcessor <EOL> from . GeneratorProcessor import GeneratorProcessor <EOL> from . BuilderProcessor import BuilderProcessor <EOL> from . ExplainerProcessor import ExplainerProcessor <EOL> from . CheckpointerProcessor import CheckpointerProcessor <EOL> from . FinalizerProcessor import FinalizerProcessor <EOL> from . InputProcessor import InputProcessor <EOL> from . CleanUpStageProcessor import CleanUpStageProcessor <EOL> from . . model . Version import Version <EOL> from . . model . CPLogging import CPLogging as KenLog <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class ConfigurationProcessor ( KenLog ) : <EOL> def __init__ ( self , instructions ) : <EOL> super ( ConfigurationProcessor , self ) . __init__ ( instructions ) <EOL> self . _instructions = instructions <EOL> self . _models = None <EOL> self . _controllers = None <EOL> self . _config_files = None <EOL> self . _errors = [ ] <EOL> self . _warnings = [ ] <EOL> self . _banner = '<STR_LIT:#>' * <NUM_LIT:50> <EOL> dashes = '<STR_LIT:->' * <NUM_LIT:20> <EOL> LOG . info ( '<STR_LIT>' % ( dashes , time . strftime ( <EOL> "<STR_LIT>" ) , dashes ) ) <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> self . _establish_version ( ) <EOL> def _establish_version ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> try : <EOL> version = Version . get ( self . _instructions [ '<STR_LIT>' ] ) <EOL> version = Version . normalize ( version ) <EOL> self . _instructions [ '<STR_LIT>' ] = version <EOL> self . _establish_path ( '<STR_LIT>' , version ) <EOL> self . _establish_path ( '<STR_LIT>' , version ) <EOL> self . _establish_path ( '<STR_LIT>' , version ) <EOL> self . _establish_path ( '<STR_LIT>' , version ) <EOL> except Exception as e : <EOL> msg = '<STR_LIT>' % e <EOL> LOG . error ( msg + traceback . format_exc ( ) ) <EOL> sys . stderr . write ( traceback . format_exc ( ) ) <EOL> exit ( int ( - <NUM_LIT:1> ) ) <EOL> print ( '<STR_LIT>' % version ) <EOL> def _establish_path ( self , element , version ) : <EOL> val = self . _instructions [ element ] <EOL> val = val . replace ( '<STR_LIT>' , version ) <EOL> self . _instructions [ element ] = val <EOL> def process_input ( self ) : <EOL> LOG . error ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> print ( "<STR_LIT>" % ( <EOL> self . _banner , self . _banner ) ) <EOL> processor = InputProcessor ( self . _instructions ) <EOL> if not processor . is_required_for_cloud ( processor . version ( ) ) : <EOL> print ( '<STR_LIT>' ) <EOL> return True <EOL> try : <EOL> duration = timeit . timeit ( processor . process , number = <NUM_LIT:1> ) <EOL> self . add_warnings ( processor . warnings ) <EOL> if not processor . ok : <EOL> self . add_errors ( processor . errors ) <EOL> return False <EOL> self . _config_files = processor . config_files <EOL> print ( '<STR_LIT>' % duration ) <EOL> return True <EOL> except Exception as e : <EOL> print ( '<STR_LIT>' % e ) <EOL> return False <EOL> def validate ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> print ( "<STR_LIT>" % ( <EOL> self . _banner , self . _banner ) ) <EOL> processor = ValidatorProcessor ( self . _instructions , self . _config_files ) <EOL> try : <EOL> duration = timeit . timeit ( processor . process , number = <NUM_LIT:1> ) <EOL> self . add_warnings ( processor . warnings ) <EOL> if not processor . ok : <EOL> self . add_errors ( processor . errors ) <EOL> return False <EOL> print ( '<STR_LIT>' % duration ) <EOL> return True <EOL> except Exception as e : <EOL> print ( '<STR_LIT>' % e ) <EOL> return False <EOL> def create_models ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> print ( "<STR_LIT>" % ( <EOL> self . _banner , self . _banner ) ) <EOL> processor = ModelProcessor ( self . _instructions , self . _config_files ) <EOL> try : <EOL> duration = timeit . timeit ( processor . process , number = <NUM_LIT:1> ) <EOL> self . add_warnings ( processor . warnings ) <EOL> if not processor . ok : <EOL> self . add_errors ( processor . errors ) <EOL> return False <EOL> self . _models = processor . models <EOL> print ( '<STR_LIT>' % duration ) <EOL> return True <EOL> except Exception as e : <EOL> print ( '<STR_LIT>' % e ) <EOL> return False <EOL> def create_controllers ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> print ( "<STR_LIT>" % ( <EOL> self . _banner , self . _banner ) ) <EOL> processor = ControllerProcessor ( <EOL> self . _instructions , self . _models ) <EOL> try : <EOL> duration = timeit . timeit ( processor . process , number = <NUM_LIT:1> ) <EOL> self . add_warnings ( processor . warnings ) <EOL> if not processor . ok : <EOL> self . add_errors ( processor . errors ) <EOL> return False <EOL> self . _controllers = processor . controllers <EOL> print ( '<STR_LIT>' % <EOL> duration ) <EOL> return True <EOL> except Exception as e : <EOL> print ( '<STR_LIT>' % e ) <EOL> return False <EOL> def migrate ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> print ( "<STR_LIT>" % ( <EOL> self . _banner , self . _banner ) ) <EOL> processor = MigratorProcessor ( <EOL> self . _instructions , self . _models , self . _controllers ) <EOL> try : <EOL> duration = timeit . timeit ( processor . process , number = <NUM_LIT:1> ) <EOL> self . add_warnings ( processor . warnings ) <EOL> if not processor . ok : <EOL> self . add_errors ( processor . errors ) <EOL> return False <EOL> self . _models = processor . models <EOL> print ( '<STR_LIT>' % duration ) <EOL> return True <EOL> except Exception as e : <EOL> print ( '<STR_LIT>' % e ) <EOL> return False <EOL> def clean_up_stage ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> print ( "<STR_LIT>" % ( <EOL> self . _banner , self . _banner ) ) <EOL> processor = CleanUpStageProcessor ( self . _instructions , self . _models ) <EOL> try : <EOL> duration = timeit . timeit ( processor . process , number = <NUM_LIT:1> ) <EOL> self . add_warnings ( processor . warnings ) <EOL> if not processor . ok : <EOL> self . add_errors ( processor . errors ) <EOL> return False <EOL> print ( '<STR_LIT>' % duration ) <EOL> return True <EOL> except Exception as e : <EOL> print ( '<STR_LIT>' % e ) <EOL> return False <EOL> def generate ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> print ( "<STR_LIT>" % ( <EOL> self . _banner , self . _banner ) ) <EOL> processor = GeneratorProcessor ( <EOL> self . _instructions , self . _models , self . _controllers ) <EOL> try : <EOL> duration = timeit . timeit ( processor . process , number = <NUM_LIT:1> ) <EOL> self . add_warnings ( processor . warnings ) <EOL> if not processor . ok : <EOL> self . add_errors ( processor . errors ) <EOL> return False <EOL> print ( '<STR_LIT>' % duration ) <EOL> return True <EOL> except Exception as e : <EOL> print ( '<STR_LIT>' % e ) <EOL> return False <EOL> def build ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> print ( "<STR_LIT>" % ( <EOL> self . _banner , self . _banner ) ) <EOL> processor = BuilderProcessor ( <EOL> self . _instructions , self . _models , self . _controllers ) <EOL> try : <EOL> duration = timeit . timeit ( processor . process , number = <NUM_LIT:1> ) <EOL> self . add_warnings ( processor . warnings ) <EOL> if not processor . ok : <EOL> self . add_errors ( processor . errors ) <EOL> return False <EOL> print ( '<STR_LIT>' % duration ) <EOL> return True <EOL> except Exception as e : <EOL> print ( '<STR_LIT>' % e ) <EOL> return False <EOL> def explain ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> print ( "<STR_LIT>" % ( <EOL> self . _banner , self . _banner ) ) <EOL> processor = ExplainerProcessor ( <EOL> self . _instructions , self . _models , self . _controllers ) <EOL> try : <EOL> duration = timeit . timeit ( processor . process , number = <NUM_LIT:1> ) <EOL> self . add_warnings ( processor . warnings ) <EOL> if not processor . ok : <EOL> self . add_errors ( processor . errors ) <EOL> return False <EOL> print ( '<STR_LIT>' % duration ) <EOL> return True <EOL> except Exception as e : <EOL> print ( '<STR_LIT>' % e ) <EOL> return False <EOL> def checkpoint ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> print ( "<STR_LIT>" % ( <EOL> self . _banner , self . _banner ) ) <EOL> processor = CheckpointerProcessor ( <EOL> self . _instructions , self . _models , self . _controllers ) <EOL> try : <EOL> duration = timeit . timeit ( processor . process , number = <NUM_LIT:1> ) <EOL> self . add_warnings ( processor . warnings ) <EOL> if not processor . ok : <EOL> self . add_errors ( processor . errors ) <EOL> return False <EOL> print ( '<STR_LIT>' % duration ) <EOL> return True <EOL> except Exception as e : <EOL> print ( '<STR_LIT>' % e ) <EOL> return False <EOL> def finalize ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> print ( "<STR_LIT>" % ( <EOL> self . _banner , self . _banner ) ) <EOL> processor = FinalizerProcessor ( <EOL> self . _instructions , self . _models , self . _controllers , <EOL> self . _config_files ) <EOL> try : <EOL> duration = timeit . timeit ( processor . process , number = <NUM_LIT:1> ) <EOL> self . add_warnings ( processor . warnings ) <EOL> if not processor . ok : <EOL> self . add_errors ( processor . errors ) <EOL> return False <EOL> print ( '<STR_LIT>' % duration ) <EOL> return True <EOL> except Exception as e : <EOL> print ( '<STR_LIT>' % e ) <EOL> return False <EOL> @ property <EOL> def errors ( self ) : <EOL> return self . _errors <EOL> def add_error ( self , error ) : <EOL> self . _errors . append ( error ) <EOL> def add_errors ( self , errors ) : <EOL> for error in errors : <EOL> self . _errors . append ( error ) <EOL> def _print_errors ( self , action ) : <EOL> LOG . error ( action ) <EOL> for error in self . errors : <EOL> LOG . error ( '<STR_LIT>' % error ) <EOL> @ property <EOL> def warnings ( self ) : <EOL> return self . _warnings <EOL> def add_warning ( self , warning ) : <EOL> self . _warnings . append ( warning ) <EOL> def add_warnings ( self , warnings ) : <EOL> for warning in warnings : <EOL> self . _warnings . append ( warning ) <EOL> def _print_warnings ( self , action ) : <EOL> LOG . warning ( action ) <EOL> for warning in self . warnings : <EOL> LOG . warning ( '<STR_LIT>' % warning ) <EOL> def exit ( exit_code ) : <EOL> LOG . info ( '<STR_LIT>' % exit_code ) <EOL> sys . exit ( exit_code ) </s>
