'Add a format to the specified book. Return True of the format was added successfully.
:param replace: If True replace existing format, otherwise if the format already exists, return False.
:param run_hooks: If True, file type plugins are run on the format before and after being added.
:param dbapi: Internal use only.'

@api
def add_format(self, book_id, fmt, stream_or_path, replace=True, run_hooks=True, dbapi=None):

    if run_hooks:
        npath = run_import_plugins(stream_or_path, fmt)
        fmt = os.path.splitext(npath)[(-1)].lower().replace(u'.', u'').upper()
        stream_or_path = lopen(npath, u'rb')
        fmt = check_ebook_format(stream_or_path, fmt)
    with self.write_lock:
        fmt = (fmt or u'').upper()
        self.format_metadata_cache[book_id].pop(fmt, None)
        try:
            name = self.fields[u'formats'].format_fname(book_id, fmt)
        except Exception:
            name = None
        if (name and (not replace)):
            return False
        stream = (stream_or_path if hasattr(stream_or_path, u'read') else lopen(stream_or_path, u'rb'))
        (size, fname) = self._do_add_format(book_id, fmt, stream, name)
        del stream
        max_size = self.fields[u'formats'].table.update_fmt(book_id, fmt, fname, size, self.backend)
        self.fields[u'size'].table.update_sizes({book_id: max_size})
        self._update_last_modified((book_id,))
    if run_hooks:
        run_plugins_on_postimport((dbapi or self), book_id, fmt)
        stream_or_path.close()
    return True
