<s> import importlib <EOL> import logging <EOL> import os <EOL> from toscaparser . common . exception import ToscaExtAttributeError <EOL> from toscaparser . common . exception import ToscaExtImportError <EOL> log = logging . getLogger ( "<STR_LIT>" ) <EOL> REQUIRED_ATTRIBUTES = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> class ExtTools ( object ) : <EOL> def __init__ ( self ) : <EOL> self . EXTENSION_INFO = self . _load_extensions ( ) <EOL> def _load_extensions ( self ) : <EOL> '''<STR_LIT>''' <EOL> extensions = { } <EOL> abs_path = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> extdirs = [ e for e in os . listdir ( abs_path ) if <EOL> not e . startswith ( '<STR_LIT>' ) and <EOL> not e . endswith ( '<STR_LIT>' ) and not e . endswith ( '<STR_LIT>' ) ] <EOL> for e in extdirs : <EOL> log . info ( e ) <EOL> extpath = abs_path + '<STR_LIT:/>' + e <EOL> ext_files = [ f for f in os . listdir ( extpath ) if f . endswith ( '<STR_LIT>' ) <EOL> and not f . startswith ( '<STR_LIT>' ) ] <EOL> for f in ext_files : <EOL> log . info ( f ) <EOL> ext_name = '<STR_LIT>' + e + '<STR_LIT:/>' + f . strip ( '<STR_LIT>' ) <EOL> ext_name = ext_name . replace ( '<STR_LIT:/>' , '<STR_LIT:.>' ) <EOL> try : <EOL> extinfo = importlib . import_module ( ext_name ) <EOL> version = getattr ( extinfo , '<STR_LIT>' ) <EOL> defs_file = extpath + '<STR_LIT:/>' + getattr ( extinfo , '<STR_LIT>' ) <EOL> sections = getattr ( extinfo , '<STR_LIT>' , ( ) ) <EOL> extensions [ version ] = { '<STR_LIT>' : sections , <EOL> '<STR_LIT>' : defs_file } <EOL> except ImportError : <EOL> raise ToscaExtImportError ( ext_name = ext_name ) <EOL> except AttributeError : <EOL> attrs = '<STR_LIT:U+002CU+0020>' . join ( REQUIRED_ATTRIBUTES ) <EOL> raise ToscaExtAttributeError ( ext_name = ext_name , <EOL> attrs = attrs ) <EOL> return extensions <EOL> def get_versions ( self ) : <EOL> return self . EXTENSION_INFO . keys ( ) <EOL> def get_sections ( self ) : <EOL> sections = { } <EOL> for version in self . EXTENSION_INFO . keys ( ) : <EOL> sections [ version ] = self . EXTENSION_INFO [ version ] [ '<STR_LIT>' ] <EOL> return sections <EOL> def get_defs_file ( self , version ) : <EOL> versiondata = self . EXTENSION_INFO . get ( version ) <EOL> if versiondata : <EOL> return versiondata . get ( '<STR_LIT>' ) <EOL> else : <EOL> return None </s>
