

def convert_md_to_rst(source, destination=None, backup_dir=None):
    "Try to convert the source, an .md (markdown) file, to an .rst\n    (reStructuredText) file at the destination. If the destination isn't\n    provided, it defaults to be the same as the source path except for the\n    filename extension. If the destination file already exists, it will be\n    overwritten. In the event of an error, the destination file will be\n    left untouched."
    try:
        import pypandoc
    except ImportError:
        os.system('pip install pypandoc')
        import pypandoc
    destination = (destination or (os.path.splitext(source)[0] + '.rst'))
    backup_dir = (backup_dir or os.path.join(os.path.dirname(destination), 'bak'))
    bak_name = (os.path.basename(destination) + time.strftime('.%Y%m%d%H%M%S.bak'))
    bak_path = os.path.join(backup_dir, bak_name)
    if os.path.isfile(destination):
        if (not os.path.isdir(os.path.dirname(bak_path))):
            os.mkdir(os.path.dirname(bak_path))
        os.rename(destination, bak_path)
    try:
        pypandoc.convert(source, 'rst', format='md', outputfile=destination)
    except:
        if os.path.isfile(destination):
            os.remove(destination)
        if os.path.isfile(bak_path):
            os.rename(bak_path, destination)
        raise

dataset/ETHPy150Open hosford42/xcs/build_readme.py convert_md_to_rst/original