'Set the cover for this book.
`data`: Can be either a QImage, QPixmap, file object or bytestring'

def set_cover(self, id, data, notify=True, commit=True):

    base_path = os.path.join(self.library_path, self.path(id, index_is_id=True))
    if (not os.path.exists(base_path)):
        self.set_path(id, index_is_id=True)
        base_path = os.path.join(self.library_path, self.path(id, index_is_id=True))
        self.dirtied([id])
        if (not os.path.exists(base_path)):
            os.makedirs(base_path)
    path = os.path.join(base_path, 'cover.jpg')
    if callable(getattr(data, 'save', None)):
        data.save(path)
    else:
        if callable(getattr(data, 'read', None)):
            data = data.read()
        try:
            save_cover_data_to(data, path)
        except (IOError, OSError):
            time.sleep(0.2)
            save_cover_data_to(data, path)
    now = nowf()
    self.conn.execute('UPDATE    books    SET    has_cover=1,last_modified=?    WHERE    id=?', (now, id))
    if commit:
        self.conn.commit()
    self.data.set(id, self.FIELD_MAP['cover'], True, row_is_id=True)
    self.data.set(id, self.FIELD_MAP['last_modified'], now, row_is_id=True)
    if notify:
        self.notify('cover', [id])
