def make_rc(base_cfg, target_filename,
            additions=None, replacements=None):
    """Combines a base rc and additions into single file.

    Args:
        base_cfg (ConfigParser.ConfigParser): The configuration we are
            merging into.
        target_filename (str): The filename where the new configuration
            will be saved.
        additions (dict): (Optional) The values added to the configuration.
        replacements (dict): (Optional) The wholesale replacements for
            the new configuration.

    Raises:
        KeyError: if one of the additions or replacements does not
            already exist in the current config.
    """
    # Set-up the mutable default values.
    if additions is None:
        additions = {}
    if replacements is None:
        replacements = {}

    # Create fresh config, which must extend the base one.
    new_cfg = six.moves.configparser.ConfigParser()
    # pylint: disable=protected-access
    new_cfg._sections = copy.deepcopy(base_cfg._sections)
    new_sections = new_cfg._sections
    # pylint: enable=protected-access

    for section, opts in additions.items():
        curr_section = new_sections.setdefault(
            section, collections.OrderedDict())
        for opt, opt_val in opts.items():
            curr_val = curr_section.get(opt)
            if curr_val is None:
                msg = _MISSING_OPTION_ADDITION.format(opt)
                raise KeyError(msg)
            curr_val = curr_val.rstrip(',')
            opt_val = _transform_opt(opt_val)
            curr_section[opt] = '%s, %s' % (curr_val, opt_val)

    for section, opts in replacements.items():
        curr_section = new_sections.setdefault(
            section, collections.OrderedDict())
        for opt, opt_val in opts.items():
            curr_val = curr_section.get(opt)
            if curr_val is None:
                # NOTE: This doesn't need to fail, because some options
                #       are present in one version of pylint and not present
                #       in another. For example ``[BASIC].method-rgx`` is
                #       ``(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$`` in
                #       ``1.7.5`` but in ``1.8.0`` the default config has
                #       ``#method-rgx=`` (i.e. it is commented out in the
                #       ``[BASIC]`` section).
                msg = _MISSING_OPTION_REPLACE.format(opt)
                print(msg, file=sys.stderr)
            opt_val = _transform_opt(opt_val)
            curr_section[opt] = '%s' % (opt_val,)

    with open(target_filename, 'w') as file_obj:
        new_cfg.write(file_obj)
def make_rc ( base_cfg , target_filename , additions = None , replacements = None ) : if additions is None : additions = { } if replacements is None : replacements = { } new_cfg = six . moves . configparser . ConfigParser ( ) new_cfg . _sections = copy . deepcopy ( base_cfg . _sections ) new_sections = new_cfg . _sections for section , opts in additions . items ( ) : curr_section = new_sections . setdefault ( section , collections . OrderedDict ( ) ) for opt , opt_val in opts . items ( ) : curr_val = curr_section . get ( opt ) if curr_val is None : msg = _MISSING_OPTION_ADDITION . format ( opt ) raise KeyError ( msg ) curr_val = curr_val . rstrip ( ',' ) opt_val = _transform_opt ( opt_val ) curr_section [ opt ] = '%s, %s' % ( curr_val , opt_val ) for section , opts in replacements . items ( ) : curr_section = new_sections . setdefault ( section , collections . OrderedDict ( ) ) for opt , opt_val in opts . items ( ) : curr_val = curr_section . get ( opt ) if curr_val is None : msg = _MISSING_OPTION_REPLACE . format ( opt ) print ( msg , file = sys . stderr ) opt_val = _transform_opt ( opt_val ) curr_section [ opt ] = '%s' % ( opt_val , ) with open ( target_filename , 'w' ) as file_obj : new_cfg . write ( file_obj )
Combines a base rc and additions into single file.

    Args:
        base_cfg (ConfigParser.ConfigParser): The configuration we are
            merging into.
        target_filename (str): The filename where the new configuration
            will be saved.
        additions (dict): (Optional) The values added to the configuration.
        replacements (dict): (Optional) The wholesale replacements for
            the new configuration.

    Raises:
        KeyError: if one of the additions or replacements does not
            already exist in the current config.