def main():
    parser = ArgumentParser(prog='set_core_version')
    parser.add_argument('newversion')
    toml_list = ['Cargo.toml', 'deltachat-ffi/Cargo.toml']
    try:
        opts = parser.parse_args()
    except SystemExit:
        print()
        for x in toml_list:
            print('{}: {}'.format(x, read_toml_version(x)))
        print('package.json:', str(read_json_version('package.json')))
        print()
        raise SystemExit('need argument: new version, example: 1.25.0')
    newversion = opts.newversion
    if (newversion.count('.') < 2):
        raise SystemExit('need at least two dots in version')
    core_toml = read_toml_version('Cargo.toml')
    ffi_toml = read_toml_version('deltachat-ffi/Cargo.toml')
    assert (core_toml == ffi_toml), (core_toml, ffi_toml)
    if ('alpha' not in newversion):
        for line in open('CHANGELOG.md'):
            if line.startswith('## '):
                if line[2:].strip().startswith(newversion):
                    break
        else:
            raise SystemExit('CHANGELOG.md contains no entry for version: {}'.format(newversion))
    replace_toml_version('Cargo.toml', newversion)
    replace_toml_version('deltachat-ffi/Cargo.toml', newversion)
    update_package_json(newversion)
    print('running cargo check')
    subprocess.call(['cargo', 'check'])
    print('adding changes to git index')
    subprocess.call(['git', 'add', '-u'])
    print('after commit, on master make sure to: ')
    print('')
    print('   git tag -a {}'.format(newversion))
    print('   git push origin {}'.format(newversion))
    print('   git tag -a py-{}'.format(newversion))
    print('   git push origin py-{}'.format(newversion))
    print('')
def main():
    parser = ArgumentParser(prog='set_core_version')
    parser.add_argument('newversion')
    toml_list = ['Cargo.toml', 'deltachat-ffi/Cargo.toml']
    try:
        opts = parser.parse_args()
    except SystemExit:
        print()
        for x in toml_list:
            print('{}: {}'.format(x, read_toml_version(x)))
        print('package.json:', str(read_json_version('package.json')))
        print()
        raise SystemExit('need argument: new version, example: 1.25.0')
    newversion = opts.newversion
    if (newversion.count('.') < 2):
        raise SystemExit('need at least two dots in version')
    core_toml = read_toml_version('Cargo.toml')
    ffi_toml = read_toml_version('deltachat-ffi/Cargo.toml')
    assert (core_toml == ffi_toml), (core_toml, ffi_toml)
    if ('alpha' not in newversion):
        for line in open('CHANGELOG.md'):
            if line.startswith('## '):
                if line[2:].strip().startswith(newversion):
                    break
        else:
            raise SystemExit('CHANGELOG.md contains no entry for version: {}'.format(newversion))
    replace_toml_version('Cargo.toml', newversion)
    replace_toml_version('deltachat-ffi/Cargo.toml', newversion)
    update_package_json(newversion)
    print('running cargo check')
    subprocess.call(['cargo', 'check'])
    print('adding changes to git index')
    subprocess.call(['git', 'add', '-u'])
    print('after commit, on master make sure to: ')
    print()
    print('   git tag -a {}'.format(newversion))
    print('   git push origin {}'.format(newversion))
    print('   git tag -a py-{}'.format(newversion))
    print('   git push origin py-{}'.format(newversion))
    print()