'Upload books to device:'

def _upload_books(self, files, names, on_card=None, metadata=None, plugboards=None):

    from calibre.ebooks.metadata.meta import set_metadata
    if (hasattr(self.connected_device, 'set_plugboards') and callable(self.connected_device.set_plugboards)):
        self.connected_device.set_plugboards(plugboards, find_plugboard)
    if (metadata and files and (len(metadata) == len(files))):
        for (f, mi) in zip(files, metadata):
            if isinstance(f, unicode):
                ext = f.rpartition('.')[(-1)].lower()
                cpb = find_plugboard(device_name_for_plugboards(self.connected_device), ext, plugboards)
                if ext:
                    try:
                        if DEBUG:
                            prints('Setting    metadata    in:', mi.title, 'at:', f, file=sys.__stdout__)
                        with lopen(f, 'r+b') as stream:
                            if cpb:
                                newmi = mi.deepcopy_metadata()
                                newmi.template_to_attribute(mi, cpb)
                            else:
                                newmi = mi
                            nuke_comments = getattr(self.connected_device, 'NUKE_COMMENTS', None)
                            if (nuke_comments is not None):
                                mi.comments = nuke_comments
                            set_metadata(stream, newmi, stream_type=ext)
                    except:
                        if DEBUG:
                            prints(traceback.format_exc(), file=sys.__stdout__)
    try:
        return self.device.upload_books(files, names, on_card, metadata=metadata, end_session=False)
    finally:
        if metadata:
            for mi in metadata:
                try:
                    if mi.cover:
                        os.remove(mi.cover)
                except:
                    pass
