def update_pypirc(username, password, index_url, server_name, verbose=False, dry_run=False):

    if verbose:
        print('Updating pypirc file')
        print('\tsearching for pypirc file...')

    f_path = os.path.join(os.path.expanduser('~'), '.pypirc')
    if os.path.exists(f_path):
        if verbose:
            print('\tpypirc file found.')
    else:
        if verbose:
            print('\tNo pypirc file found, creating a new one')

        seed_parser = configparser.ConfigParser()
        seed_parser.add_section('distutils')
        seed_parser.set(section='distutils', option='index-servers', value='')

        if not dry_run:
            with open(f_path, 'w') as f:
                seed_parser.write(f)

    parser = configparser.ConfigParser()
    parser.read(f_path)
    if parser.has_section(server_name):
        if verbose:
            print('\tserver name already exists')
        if username is not None:
            if username != parser.get(section=server_name, option='username'):
                if verbose:
                    print('\tupdating username')
                parser.set(section=server_name, option='username', value=username)
        if password is not None:
            if password != parser.get(section=server_name, option='password'):
                if verbose:
                    print('\tupdating password')
                parser.set(section=server_name, option='password', value=password)
        if index_url is not None:
            if index_url != parser.get(section=server_name, option='repository'):
                if verbose:
                    print('\tupdating index url')
                parser.set(section=server_name, option='repository', value=index_url)
    else:
        if verbose:
            print('\tserver name not there, adding it...')
        parser.add_section(server_name)
        index_servers = parser.get(section='distutils', option='index-servers') + '\n%s' % (server_name, )
        parser.set(section='distutils', option='index-servers', value=index_servers)
        parser.set(section=server_name, option='repository', value=index_url)
        parser.set(section=server_name, option='username', value=username)
        parser.set(section=server_name, option='password', value=password)

    if not dry_run:
        with open(f_path, 'w') as f:
            parser.write(f)

    return True
Upserts into the pypirc file with new information from the command line.
dataset/ETHPy150Open wdm0006/pypi-publisher/ppp/ppp.py/update_pypirc