<s> import os <EOL> import six <EOL> import logging <EOL> from . . controller . CloudConfigController import CloudConfigController <EOL> from . . model . CPProcessor import CPProcessor <EOL> from . . model . JsonConfigFile import JsonConfigFile <EOL> from . . model . YamlConfigFile import YamlConfigFile <EOL> from . . model . CPLogging import CPLogging as KenLog <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class ControllerProcessor ( CPProcessor ) : <EOL> def __init__ ( self , instructions , models ) : <EOL> super ( ControllerProcessor , self ) . __init__ ( instructions , "<STR_LIT>" ) <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> self . _models = models <EOL> self . _controllers = dict ( ) <EOL> self . _site_path = instructions [ '<STR_LIT>' ] <EOL> def process ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> if not self . _create_controllers ( ) : <EOL> return False <EOL> if not self . _update_controllers ( ) : <EOL> return False <EOL> return True <EOL> def _create_controllers ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> instructions = self . _instructions <EOL> self . _controllers [ '<STR_LIT>' ] = CloudConfigController ( <EOL> instructions , self . _models [ '<STR_LIT>' ] ) <EOL> return True <EOL> def _update_controllers ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> return_value = True <EOL> for controller , elem_c in six . iteritems ( self . _controllers ) : <EOL> self . _controllers [ controller ] . update ( self . _models , <EOL> self . _controllers ) <EOL> return return_value <EOL> def _get_ca_topic_properties ( self , file_name , topic ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> if file_name . endswith ( '<STR_LIT>' ) : <EOL> cf = JsonConfigFile ( topic , file_name ) <EOL> cf . load ( ) <EOL> elif file_name . endswith ( '<STR_LIT>' ) or file_name . endswith ( '<STR_LIT>' ) : <EOL> cf = YamlConfigFile ( topic , file_name ) <EOL> cf . load ( ) <EOL> else : <EOL> LOG . warning ( '<STR_LIT>' % file_name ) <EOL> return <EOL> element = cf . contents <EOL> if '<STR_LIT>' not in element : <EOL> return dict ( ) <EOL> return element [ '<STR_LIT>' ] <EOL> def _get_ca_properties ( self , file_base , topic ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> for suffix in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> file_name = '<STR_LIT>' % ( file_base , suffix ) <EOL> s_path = os . path . join ( self . _site_path , file_name ) <EOL> if os . path . exists ( s_path ) and os . path . isfile ( s_path ) : <EOL> return self . _get_ca_topic_properties ( s_path , topic ) <EOL> @ property <EOL> def models ( self ) : <EOL> return self . _models <EOL> @ models . setter <EOL> def models ( self , models ) : <EOL> self . _models = models <EOL> @ property <EOL> def controllers ( self ) : <EOL> return self . _controllers </s>
