<s> from UserDict import DictMixin <EOL> import os <EOL> import yaml <EOL> from compago . plugin import Plugin <EOL> class Config ( DictMixin ) : <EOL> @ staticmethod <EOL> def load ( path ) : <EOL> try : <EOL> attrs = yaml . load ( open ( path ) ) <EOL> except IOError : <EOL> return Config ( ) <EOL> else : <EOL> return Config ( ** attrs ) <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . attributes = kwargs or { } <EOL> def __getitem__ ( self , key ) : <EOL> try : <EOL> return self . attributes [ key ] <EOL> except KeyError : <EOL> raise Exception ( '<STR_LIT>' . format ( key ) ) <EOL> def keys ( self ) : <EOL> return self . attributes . keys ( ) <EOL> class ConfigPlugin ( Plugin ) : <EOL> def __init__ ( self , path = None ) : <EOL> self . path = path <EOL> def after_application_init ( self , application ) : <EOL> application . add_option ( '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> if application . args [ '<STR_LIT>' ] : <EOL> if not os . path . exists ( application . args [ '<STR_LIT>' ] ) : <EOL> raise IOError ( '<STR_LIT>' . format ( <EOL> application . args [ '<STR_LIT>' ] ) ) <EOL> self . path = application . args [ '<STR_LIT>' ] <EOL> if not self . path : <EOL> self . path = '<STR_LIT>' . format ( application . name ) <EOL> application . config = Config . load ( self . path ) </s>
