<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_changelog(debug=False):
 """Write a changelog based on the git changelog."""

    changelog = _iter_log_oneline(debug)
    if changelog:
        changelog = _iter_changelog(changelog)
    if not changelog:
        return
    if debug:
        print('Writing ChangeLog')
    new_changelog = os.path.join(os.path.curdir, 'ChangeLog')
    # If there's already a ChangeLog and it's not writable, just use it
    if (os.path.exists(new_changelog)
            and not os.access(new_changelog, os.W_OK)):
        return
    with io.open(new_changelog, 'w', encoding='utf-8') as changelog_file:
        for release, content in changelog:
            changelog_file.write(content)