<s> import logging <EOL> import os <EOL> import seria <EOL> import yaml <EOL> from figgypy . decrypt import ( <EOL> gpg_decrypt , <EOL> kms_decrypt <EOL> ) <EOL> from figgypy . exceptions import FiggypyError <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> if len ( log . handlers ) == <NUM_LIT:0> : <EOL> log . addHandler ( logging . NullHandler ( ) ) <EOL> class Config ( object ) : <EOL> """<STR_LIT>""" <EOL> _dirs = [ <EOL> os . curdir , <EOL> os . path . join ( os . path . expanduser ( "<STR_LIT>" ) , '<STR_LIT>' ) , <EOL> "<STR_LIT>" <EOL> ] <EOL> def __init__ ( self , f , aws_config = None , gpg_config = None ) : <EOL> self . _aws_config = aws_config or { } <EOL> self . _gpg_config = gpg_config or { } <EOL> self . _f = self . _get_file ( f ) <EOL> self . _cfg = self . _get_cfg ( self . _f ) <EOL> def _get_cfg ( self , f ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> with open ( f , '<STR_LIT:r>' ) as _fo : <EOL> _seria_in = seria . load ( _fo ) <EOL> _y = _seria_in . dump ( '<STR_LIT>' ) <EOL> except IOError : <EOL> raise FiggypyError ( "<STR_LIT>" ) <EOL> _cfg = yaml . load ( _y ) <EOL> self . _post_load_process ( _cfg , self . _gpg_config ) <EOL> for k , v in _cfg . items ( ) : <EOL> setattr ( self , k , v ) <EOL> def _post_load_process ( self , cfg , gpg_config = None ) : <EOL> gpg_decrypt ( cfg , self . _gpg_config ) <EOL> kms_decrypt ( cfg , self . _aws_config ) <EOL> return cfg <EOL> def _get_file ( self , f ) : <EOL> """<STR_LIT>""" <EOL> if os . path . isabs ( f ) : <EOL> return f <EOL> else : <EOL> for d in Config . _dirs : <EOL> _f = os . path . join ( d , f ) <EOL> if os . path . isfile ( _f ) : <EOL> return _f <EOL> raise FiggypyError ( "<STR_LIT>" <EOL> . format ( f , Config . _dirs ) ) </s>
