def _config_from_config_profile()

in ec2stack/__init__.py [0:0]


def _config_from_config_profile(config_file, profile, app):
    """
    Configures ec2stack app based on configuration profile.

    @param config_file: current config file configuration.
    @param profile: the profile to set the attribute in.
    """
    config = SafeConfigParser()
    config.read(config_file)

    if not config.has_section(profile):
        sys.exit('No profile matching ' + profile +
                 ' found in configuration, please run ec2stack-configure -p ' + profile)

    for attribute in config.options(profile):
        app.config[attribute.upper()] = config.get(profile, attribute)

    instance_type_map = {}
    instance_section = profile + "instancemap"
    if config.has_section(instance_section):
        for attribute in config.options(instance_section):
            instance_type_map[attribute] = config.get(
                instance_section, attribute)

    app.config['INSTANCE_TYPE_MAP'] = instance_type_map

    resource_type_map = {}
    resource_section = profile + "resourcemap"
    if config.has_section(resource_section):
        for attribute in config.options(resource_section):
            resource_type_map[attribute] = config.get(
                resource_section, attribute)

    app.config['RESOURCE_TYPE_MAP '] = resource_type_map