Generates a config parser from a configuration dictionary.

    The dictionary contains the merged informations of the schema and,
    optionally, of a source configuration file. Values of the source
    configuration file will be stored in the *value* field of an option.

def generate_config_parser(config, include_all=False):
    """
    Generates a config parser from a configuration dictionary.

    The dictionary contains the merged informations of the schema and,
    optionally, of a source configuration file. Values of the source
    configuration file will be stored in the *value* field of an option.
    """

    # The allow_no_value allows us to output commented lines.
    config_parser = SafeConfigParser(allow_no_value=True)
    for section_name, option_name in _get_included_schema_sections_options(config, include_all):

        if not config_parser.has_section(section_name):
            config_parser.add_section(section_name)

        option = config[section_name][option_name]

        if option.get('required'):
            config_parser.set(section_name, '# REQUIRED')

        config_parser.set(section_name, '# ' + option.get('description', 'No description provided.'))

        if option.get('deprecated'):
            config_parser.set(section_name, '# DEPRECATED')

        option_value = _get_value(option)
        config_parser.set(section_name, option_name, option_value)

        config_parser.set(section_name, '')

    return config_parser