<s> """<STR_LIT>""" <EOL> import logging <EOL> import re <EOL> from compass . db . api import database <EOL> from compass . db . api import utils <EOL> from compass . db import exception <EOL> from compass . db import models <EOL> from compass . utils import setting_wrapper as setting <EOL> from compass . utils import util <EOL> OSES = None <EOL> OS_INSTALLERS = None <EOL> PACKAGE_INSTALLERS = None <EOL> ADAPTERS = None <EOL> ADAPTERS_FLAVORS = None <EOL> ADAPTERS_ROLES = None <EOL> def _get_oses_from_configuration ( ) : <EOL> """<STR_LIT>""" <EOL> configs = util . load_configs ( setting . OS_DIR ) <EOL> systems = { } <EOL> for config in configs : <EOL> logging . info ( '<STR_LIT>' , config ) <EOL> system_name = config [ '<STR_LIT>' ] <EOL> parent_name = config . get ( '<STR_LIT>' , None ) <EOL> system = { <EOL> '<STR_LIT:name>' : system_name , <EOL> '<STR_LIT:id>' : system_name , <EOL> '<STR_LIT>' : system_name , <EOL> '<STR_LIT>' : parent_name , <EOL> '<STR_LIT>' : parent_name , <EOL> '<STR_LIT>' : config . get ( '<STR_LIT>' , False ) <EOL> } <EOL> systems [ system_name ] = system <EOL> parents = { } <EOL> for name , system in systems . items ( ) : <EOL> parent = system . get ( '<STR_LIT>' , None ) <EOL> parents [ name ] = parent <EOL> for name , system in systems . items ( ) : <EOL> util . recursive_merge_dict ( name , systems , parents ) <EOL> return systems <EOL> def _get_installers_from_configuration ( configs ) : <EOL> """<STR_LIT>""" <EOL> installers = { } <EOL> for config in configs : <EOL> name = config [ '<STR_LIT>' ] <EOL> instance_name = config . get ( '<STR_LIT>' , name ) <EOL> installers [ instance_name ] = { <EOL> '<STR_LIT>' : instance_name , <EOL> '<STR_LIT:id>' : instance_name , <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : config . get ( '<STR_LIT>' , { } ) <EOL> } <EOL> return installers <EOL> def _get_os_installers_from_configuration ( ) : <EOL> """<STR_LIT>""" <EOL> configs = util . load_configs ( setting . OS_INSTALLER_DIR ) <EOL> return _get_installers_from_configuration ( configs ) <EOL> def _get_package_installers_from_configuration ( ) : <EOL> """<STR_LIT>""" <EOL> configs = util . load_configs ( setting . PACKAGE_INSTALLER_DIR ) <EOL> return _get_installers_from_configuration ( configs ) <EOL> def _get_adapters_from_configuration ( ) : <EOL> """<STR_LIT>""" <EOL> configs = util . load_configs ( setting . ADAPTER_DIR ) <EOL> adapters = { } <EOL> for config in configs : <EOL> logging . info ( '<STR_LIT>' , config ) <EOL> if '<STR_LIT>' in config : <EOL> os_installer = OS_INSTALLERS [ config [ '<STR_LIT>' ] ] <EOL> else : <EOL> os_installer = None <EOL> if '<STR_LIT>' in config : <EOL> package_installer = PACKAGE_INSTALLERS [ <EOL> config [ '<STR_LIT>' ] <EOL> ] <EOL> else : <EOL> package_installer = None <EOL> adapter_name = config [ '<STR_LIT>' ] <EOL> parent_name = config . get ( '<STR_LIT>' , None ) <EOL> adapter = { <EOL> '<STR_LIT:name>' : adapter_name , <EOL> '<STR_LIT:id>' : adapter_name , <EOL> '<STR_LIT>' : parent_name , <EOL> '<STR_LIT>' : parent_name , <EOL> '<STR_LIT>' : config . get ( '<STR_LIT>' , adapter_name ) , <EOL> '<STR_LIT>' : os_installer , <EOL> '<STR_LIT>' : package_installer , <EOL> '<STR_LIT>' : config . get ( '<STR_LIT>' , False ) , <EOL> '<STR_LIT>' : config . get ( '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] <EOL> } <EOL> supported_os_patterns = [ <EOL> re . compile ( supported_os_pattern ) <EOL> for supported_os_pattern in config . get ( '<STR_LIT>' , [ ] ) <EOL> ] <EOL> for os_name , os in OSES . items ( ) : <EOL> if not os . get ( '<STR_LIT>' , False ) : <EOL> continue <EOL> for supported_os_pattern in supported_os_patterns : <EOL> if supported_os_pattern . match ( os_name ) : <EOL> adapter [ '<STR_LIT>' ] . append ( os ) <EOL> break <EOL> adapters [ adapter_name ] = adapter <EOL> parents = { } <EOL> for name , adapter in adapters . items ( ) : <EOL> parent = adapter . get ( '<STR_LIT>' , None ) <EOL> parents [ name ] = parent <EOL> for name , adapter in adapters . items ( ) : <EOL> util . recursive_merge_dict ( name , adapters , parents ) <EOL> return adapters <EOL> def _add_roles_from_configuration ( ) : <EOL> """<STR_LIT>""" <EOL> configs = util . load_configs ( setting . ADAPTER_ROLE_DIR ) <EOL> for config in configs : <EOL> logging . info ( <EOL> '<STR_LIT>' , config <EOL> ) <EOL> adapter_name = config [ '<STR_LIT>' ] <EOL> adapter = ADAPTERS [ adapter_name ] <EOL> adapter_roles = ADAPTERS_ROLES . setdefault ( adapter_name , { } ) <EOL> for role_dict in config [ '<STR_LIT>' ] : <EOL> role_name = role_dict [ '<STR_LIT>' ] <EOL> display_name = role_dict . get ( '<STR_LIT>' , role_name ) <EOL> adapter_roles [ role_name ] = { <EOL> '<STR_LIT:name>' : role_name , <EOL> '<STR_LIT:id>' : '<STR_LIT>' % ( adapter_name , role_name ) , <EOL> '<STR_LIT>' : adapter_name , <EOL> '<STR_LIT>' : adapter_name , <EOL> '<STR_LIT>' : display_name , <EOL> '<STR_LIT:description>' : role_dict . get ( '<STR_LIT:description>' , display_name ) , <EOL> '<STR_LIT>' : role_dict . get ( '<STR_LIT>' , False ) <EOL> } <EOL> parents = { } <EOL> for name , adapter in ADAPTERS . items ( ) : <EOL> parent = adapter . get ( '<STR_LIT>' , None ) <EOL> parents [ name ] = parent <EOL> for adapter_name , adapter_roles in ADAPTERS_ROLES . items ( ) : <EOL> util . recursive_merge_dict ( adapter_name , ADAPTERS_ROLES , parents ) <EOL> for adapter_name , adapter_roles in ADAPTERS_ROLES . items ( ) : <EOL> adapter = ADAPTERS [ adapter_name ] <EOL> adapter [ '<STR_LIT>' ] = adapter_roles . values ( ) <EOL> def _add_flavors_from_configuration ( ) : <EOL> """<STR_LIT>""" <EOL> configs = util . load_configs ( setting . ADAPTER_FLAVOR_DIR ) <EOL> for config in configs : <EOL> logging . info ( '<STR_LIT>' , config ) <EOL> adapter_name = config [ '<STR_LIT>' ] <EOL> adapter = ADAPTERS [ adapter_name ] <EOL> adapter_flavors = ADAPTERS_FLAVORS . setdefault ( adapter_name , { } ) <EOL> adapter_roles = ADAPTERS_ROLES [ adapter_name ] <EOL> for flavor_dict in config [ '<STR_LIT>' ] : <EOL> flavor_name = flavor_dict [ '<STR_LIT>' ] <EOL> flavor_id = '<STR_LIT>' % ( adapter_name , flavor_name ) <EOL> flavor = { <EOL> '<STR_LIT:name>' : flavor_name , <EOL> '<STR_LIT:id>' : flavor_id , <EOL> '<STR_LIT>' : adapter_name , <EOL> '<STR_LIT>' : adapter_name , <EOL> '<STR_LIT>' : flavor_dict . get ( '<STR_LIT>' , flavor_name ) , <EOL> '<STR_LIT>' : flavor_dict . get ( '<STR_LIT>' , None ) <EOL> } <EOL> flavor_roles = flavor_dict . get ( '<STR_LIT>' , [ ] ) <EOL> roles_in_flavor = [ ] <EOL> for flavor_role in flavor_roles : <EOL> if isinstance ( flavor_role , basestring ) : <EOL> role_name = flavor_role <EOL> role_in_flavor = { <EOL> '<STR_LIT:name>' : role_name , <EOL> '<STR_LIT>' : flavor_id <EOL> } <EOL> else : <EOL> role_in_flavor = flavor_role <EOL> role_in_flavor [ '<STR_LIT>' ] = flavor_id <EOL> if '<STR_LIT>' in role_in_flavor : <EOL> role_in_flavor [ '<STR_LIT:name>' ] = role_in_flavor [ '<STR_LIT>' ] <EOL> del role_in_flavor [ '<STR_LIT>' ] <EOL> role_name = role_in_flavor [ '<STR_LIT:name>' ] <EOL> role = adapter_roles [ role_name ] <EOL> util . merge_dict ( role_in_flavor , role , override = False ) <EOL> roles_in_flavor . append ( role_in_flavor ) <EOL> flavor [ '<STR_LIT>' ] = roles_in_flavor <EOL> adapter_flavors [ flavor_name ] = flavor <EOL> parents = { } <EOL> for name , adapter in ADAPTERS . items ( ) : <EOL> parent = adapter . get ( '<STR_LIT>' , None ) <EOL> parents [ name ] = parent <EOL> for adapter_name , adapter_roles in ADAPTERS_FLAVORS . items ( ) : <EOL> util . recursive_merge_dict ( adapter_name , ADAPTERS_FLAVORS , parents ) <EOL> for adapter_name , adapter_flavors in ADAPTERS_FLAVORS . items ( ) : <EOL> adapter = ADAPTERS [ adapter_name ] <EOL> adapter [ '<STR_LIT>' ] = adapter_flavors . values ( ) <EOL> def load_adapters_internal ( force_reload = False ) : <EOL> """<STR_LIT>""" <EOL> global OSES <EOL> if force_reload or OSES is None : <EOL> OSES = _get_oses_from_configuration ( ) <EOL> global OS_INSTALLERS <EOL> if force_reload or OS_INSTALLERS is None : <EOL> OS_INSTALLERS = _get_os_installers_from_configuration ( ) <EOL> global PACKAGE_INSTALLERS <EOL> if force_reload or PACKAGE_INSTALLERS is None : <EOL> PACKAGE_INSTALLERS = _get_package_installers_from_configuration ( ) <EOL> global ADAPTERS <EOL> if force_reload or ADAPTERS is None : <EOL> ADAPTERS = _get_adapters_from_configuration ( ) <EOL> global ADAPTERS_ROLES <EOL> if force_reload or ADAPTERS_ROLES is None : <EOL> ADAPTERS_ROLES = { } <EOL> _add_roles_from_configuration ( ) <EOL> global ADAPTERS_FLAVORS <EOL> if force_reload or ADAPTERS_FLAVORS is None : <EOL> ADAPTERS_FLAVORS = { } <EOL> _add_flavors_from_configuration ( ) <EOL> def get_adapters_internal ( force_reload = False ) : <EOL> """<STR_LIT>""" <EOL> load_adapters_internal ( force_reload = force_reload ) <EOL> adapter_mapping = { } <EOL> for adapter_name , adapter in ADAPTERS . items ( ) : <EOL> if adapter . get ( '<STR_LIT>' ) : <EOL> adapter_mapping [ adapter_name ] = adapter <EOL> else : <EOL> logging . info ( <EOL> '<STR_LIT>' , <EOL> adapter_name <EOL> ) <EOL> return adapter_mapping <EOL> def get_flavors_internal ( force_reload = False ) : <EOL> """<STR_LIT>""" <EOL> load_adapters_internal ( force_reload = force_reload ) <EOL> adapter_flavor_mapping = { } <EOL> for adapter_name , adapter_flavors in ADAPTERS_FLAVORS . items ( ) : <EOL> adapter = ADAPTERS . get ( adapter_name , { } ) <EOL> for flavor_name , flavor in adapter_flavors . items ( ) : <EOL> if adapter . get ( '<STR_LIT>' ) : <EOL> adapter_flavor_mapping . setdefault ( <EOL> adapter_name , { } <EOL> ) [ flavor_name ] = flavor <EOL> else : <EOL> logging . info ( <EOL> '<STR_LIT>' , <EOL> adapter_name <EOL> ) <EOL> return adapter_flavor_mapping </s>
