#!/usr/bin/env python
""" Refresh README.rst file from long description

Should be run from nibabel root (containing setup.py)
"""
from __future__ import print_function

import os

readme_lines = []
with open('README.rst', 'rt') as fobj:
    for line in fobj:
        readme_lines.append(line)
        if line.startswith('.. Following contents should be'):
            break
    else:
        raise ValueError('Expected comment not found')

rel = {}
execfile(os.path.join('nibabel', 'info.py'), rel)

readme = ''.join(readme_lines) + '\n' + rel['LONG_DESCRIPTION']

with open('README.rst', 'wt') as fobj:
    fobj.write(readme)

print('Done')
