<commit_before>import shutil
import os

from django.conf import settings


def file_rename(old_path='', new_name='', new_ext='', move=True):
    """
    Renames a file, keeping the extension.

    Parameters:

    * old_path: the file path relative to MEDIA_ROOT
    * new_name: the new basename of the file (no extension)
    * new_ext: adds new extension
    * move: do not move

    Returns the new file path on success.
    Returns the original old_path on error.

    inspired by: http://code.djangoproject.com/wiki/CustomUploadAndFilters
    """
    # return if no file or file_name given
    if not (old_path and new_name):
        return old_path

    # get important three parts
    dir_base, old_name, extension = split_path(old_path)

    if not new_ext:
        # if new extension is not given, use old one
        new_ext = extension
    else:
        # if it is, complete trailing dot
        new_ext = '.%s' % new_ext

    # to be sure createpath again
    old_file = old_name + extension
    new_file = new_name + new_ext
    old_absolute_path = os.path.join(settings.MEDIA_ROOT, dir_base, old_file)
    new_absolute_path = os.path.join(settings.MEDIA_ROOT, dir_base, new_file)

    # try to rename
    try:
        if move:
            shutil.move(old_absolute_path, new_absolute_path)
    except IOError:<commit_msg>ability to rename with empty extension<commit_after>import shutil
import os

from django.conf import settings


def file_rename(old_path='', new_name='', new_ext=None, move=True):
    """
    Renames a file, keeping the extension.

    Parameters:

    * old_path: the file path relative to MEDIA_ROOT
    * new_name: the new basename of the file (no extension)
    * new_ext: adds new extension
    * move: do not move

    Returns the new file path on success.
    Returns the original old_path on error.

    inspired by: http://code.djangoproject.com/wiki/CustomUploadAndFilters
    """
    # return if no file or file_name given
    if not (old_path and new_name):
        return old_path

    # get important three parts
    dir_base, old_name, extension = split_path(old_path)

    if new_ext is None:
        # if new extension is not given, use old one
        new_ext = extension

    # to be sure createpath again
    old_file = old_name + extension
    new_file = new_name + new_ext
    old_absolute_path = os.path.join(settings.MEDIA_ROOT, dir_base, old_file)
    new_absolute_path = os.path.join(settings.MEDIA_ROOT, dir_base, new_file)

    # try to rename
    try:
        if move:
            shutil.move(old_absolute_path, new_absolute_path)
    except IOError:
{'fraction_non_alphanumeric': 0.07309605817068504, 'fraction_numerical': 0.0, 'mean_word_length': 2.942684766214178, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '642309', 'n_tokens_mistral': 825, 'n_tokens_neox': 801, 'n_words': 265}