def convert(self, oeb_book, output_path, input_plugin, opts, log): close = False if not hasattr(output_path, 'write'): close = True if not os.path.exists(os.path.dirname(output_path)) and os.path.dirname(output_path): os.makedirs(os.path.dirname(output_path)) out_stream = lopen(output_path, 'wb') else: out_stream = output_path Writer = get_writer(opts.format) if Writer is None: raise PDBError('No writer available for format %s.' % format) setattr(opts, 'max_line_length', 0) setattr(opts, 'force_max_line_length', False) writer = Writer(opts, log) out_stream.seek(0) out_stream.truncate() writer.write_content(oeb_book, out_stream, oeb_book.metadata) if close: out_stream.close()
def convert(self, stream, options, file_ext, log, accelerators): from calibre.ebooks.pdb.header import PdbHeaderReader from calibre.ebooks.pdb import PDBError, IDENTITY_TO_NAME, get_reader header = PdbHeaderReader(stream) Reader = get_reader(header.ident) if Reader is None: raise PDBError('No reader available for format within container.\n Identity is %s. Book type is %s' % (header.ident, IDENTITY_TO_NAME.get(header.ident, _('Unknown')))) log.debug('Detected ebook format as: %s with identity: %s' % (IDENTITY_TO_NAME[header.ident], header.ident)) reader = Reader(header, stream, log, options) opf = reader.extract_content(os.getcwdu()) return opf