def rewrite(req):
    try:
        with open(req['name'], 'w') as outfile:
            outfile.seek(0)
            outfile.truncate()
            packages = collections.OrderedDict(
                sorted(req['packages'].items(), key=lambda t: str(t[0]))
            )
            for k, v in packages.items():
                outfile.write('{}\n'.format(lineout(str(k), str(v))))
    except __HOLE__:
        click.echo('File {} not found.'.format(req['name']))

    outfile.close()
    click.echo('Updated {} with packages \n\t{}'.format(
        req['name'], '\n\t'.join([str(_) for _ in req['updated']])))
    for item in req['removed']:
        click.echo(click.style('# Removed package {}'.format(item), fg='yellow'))
dataset/ETHPy150Open hactar-is/olaf/olaf/cli.py/rewrite