<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import Bcfg2 . Server <EOL> import Bcfg2 . Server . Plugin <EOL> from Bcfg2 . Utils import Executor <EOL> try : <EOL> from syck import load as yaml_load , error as yaml_error <EOL> except ImportError : <EOL> try : <EOL> from yaml import load as yaml_load , YAMLError as yaml_error <EOL> except ImportError : <EOL> raise ImportError ( "<STR_LIT>" ) <EOL> class PuppetENCFile ( Bcfg2 . Server . Plugin . FileBacked ) : <EOL> """<STR_LIT>""" <EOL> def HandleEvent ( self , event = None ) : <EOL> return <EOL> class PuppetENC ( Bcfg2 . Server . Plugin . Plugin , <EOL> Bcfg2 . Server . Plugin . Connector , <EOL> Bcfg2 . Server . Plugin . ClientRunHooks , <EOL> Bcfg2 . Server . Plugin . DirectoryBacked ) : <EOL> """<STR_LIT>""" <EOL> __child__ = PuppetENCFile <EOL> def __init__ ( self , core ) : <EOL> Bcfg2 . Server . Plugin . Plugin . __init__ ( self , core ) <EOL> Bcfg2 . Server . Plugin . Connector . __init__ ( self ) <EOL> Bcfg2 . Server . Plugin . ClientRunHooks . __init__ ( self ) <EOL> Bcfg2 . Server . Plugin . DirectoryBacked . __init__ ( self , self . data ) <EOL> self . cache = dict ( ) <EOL> self . cmd = Executor ( ) <EOL> def _run_encs ( self , metadata ) : <EOL> """<STR_LIT>""" <EOL> cache = dict ( groups = [ ] , params = dict ( ) ) <EOL> for enc in self . entries . keys ( ) : <EOL> epath = os . path . join ( self . data , enc ) <EOL> self . debug_log ( "<STR_LIT>" % <EOL> ( enc , metadata . hostname ) ) <EOL> result = self . cmd . run ( [ epath , metadata . hostname ] ) <EOL> if not result . success : <EOL> msg = "<STR_LIT>" % ( enc , metadata . hostname , result . error ) <EOL> self . logger . error ( msg ) <EOL> raise Bcfg2 . Server . Plugin . PluginExecutionError ( msg ) <EOL> if result . stderr : <EOL> self . debug_log ( "<STR_LIT>" % result . stderr ) <EOL> try : <EOL> yaml = yaml_load ( result . stdout ) <EOL> self . debug_log ( "<STR_LIT>" % <EOL> ( enc , metadata . hostname , yaml ) ) <EOL> except yaml_error : <EOL> err = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> msg = "<STR_LIT>" % ( enc , metadata . hostname , err ) <EOL> self . logger . error ( msg ) <EOL> raise Bcfg2 . Server . Plugin . PluginExecutionError ( msg ) <EOL> groups = yaml . get ( "<STR_LIT>" , yaml . get ( "<STR_LIT>" , dict ( ) ) ) <EOL> if groups : <EOL> if isinstance ( groups , list ) : <EOL> self . debug_log ( "<STR_LIT>" % <EOL> ( enc , metadata . hostname , groups ) ) <EOL> cache [ '<STR_LIT>' ] . extend ( groups ) <EOL> else : <EOL> self . debug_log ( "<STR_LIT>" % <EOL> ( enc , metadata . hostname , groups . keys ( ) ) ) <EOL> for group , params in groups . items ( ) : <EOL> cache [ '<STR_LIT>' ] . append ( group ) <EOL> if params : <EOL> cache [ '<STR_LIT>' ] . update ( params ) <EOL> if "<STR_LIT>" in yaml and yaml [ '<STR_LIT>' ] : <EOL> cache [ '<STR_LIT>' ] . update ( yaml [ '<STR_LIT>' ] ) <EOL> if "<STR_LIT>" in yaml : <EOL> self . logger . info ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( enc , metadata . hostname ) ) <EOL> self . cache [ metadata . hostname ] = cache <EOL> def get_additional_groups ( self , metadata ) : <EOL> if metadata . hostname not in self . cache : <EOL> self . _run_encs ( metadata ) <EOL> return self . cache [ metadata . hostname ] [ '<STR_LIT>' ] <EOL> def get_additional_data ( self , metadata ) : <EOL> if metadata . hostname not in self . cache : <EOL> self . _run_encs ( metadata ) <EOL> return self . cache [ metadata . hostname ] [ '<STR_LIT>' ] <EOL> def end_client_run ( self , metadata ) : <EOL> """<STR_LIT>""" <EOL> self . cache = dict ( ) <EOL> if self . core . metadata_cache_mode == '<STR_LIT>' : <EOL> self . logger . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . core . metadata_cache . expire ( ) <EOL> def end_statistics ( self , metadata ) : <EOL> self . end_client_run ( self , metadata ) </s>
