'Renames a file from current_name to new_name. It automatically
rebases all links inside the file if the directory the file is in
changes. Note however, that links are not updated in the other files
that could reference this file. This is for performance, such updates
should be done once, in bulk.'

def rename(self, current_name, new_name):

    if (current_name in self.names_that_must_not_be_changed):
        raise ValueError((u'Renaming    of    %s    is    not    allowed' % current_name))
    if (self.exists(new_name) and ((new_name == current_name) or (new_name.lower() != current_name.lower()))):
        raise ValueError((u'Cannot    rename    %s    to    %s    as    %s    already    exists' % (current_name, new_name, new_name)))
    new_path = self.name_to_abspath(new_name)
    base = os.path.dirname(new_path)
    if os.path.isfile(base):
        raise ValueError((u'Cannot    rename    %s    to    %s    as    %s    is    a    file' % (current_name, new_name, base)))
    if (not os.path.exists(base)):
        os.makedirs(base)
    old_path = parent_dir = self.name_to_abspath(current_name)
    self.commit_item(current_name)
    os.rename(old_path, new_path)
    while parent_dir:
        parent_dir = os.path.dirname(parent_dir)
        try:
            os.rmdir(parent_dir)
        except EnvironmentError:
            break
    for x in (u'mime_map', u'encoding_map'):
        x = getattr(self, x)
        if (current_name in x):
            x[new_name] = x[current_name]
    self.name_path_map[new_name] = new_path
    for x in self.cache_names:
        x = getattr(self, x)
        try:
            x.pop(current_name, None)
        except TypeError:
            x.discard(current_name)
    if (current_name == self.opf_name):
        self.opf_name = new_name
    if (os.path.dirname(old_path) != os.path.dirname(new_path)):
        from calibre.ebooks.oeb.polish.replace import LinkRebaser
        repl = LinkRebaser(self, current_name, new_name)
        self.replace_links(new_name, repl)
        self.dirty(new_name)
