Clean up invocation of MobiWriter

This commit is contained in:
Kovid Goyal 2011-07-16 21:28:23 -06:00
parent 0c8641faa1
commit 11d9073b47
2 changed files with 12 additions and 14 deletions

View File

@ -156,7 +156,7 @@ class MOBIOutput(OutputFormatPlugin):
# Fix up the periodical href to point to first section href # Fix up the periodical href to point to first section href
toc.nodes[0].href = toc.nodes[0].nodes[0].href toc.nodes[0].href = toc.nodes[0].nodes[0].href
# GR diagnostics # diagnostics
if self.opts.verbose > 3: if self.opts.verbose > 3:
self.dump_toc(toc) self.dump_toc(toc)
self.dump_manifest() self.dump_manifest()
@ -164,14 +164,11 @@ class MOBIOutput(OutputFormatPlugin):
def convert(self, oeb, output_path, input_plugin, opts, log): def convert(self, oeb, output_path, input_plugin, opts, log):
self.log, self.opts, self.oeb = log, opts, oeb self.log, self.opts, self.oeb = log, opts, oeb
from calibre.ebooks.mobi.writer import PALM_MAX_IMAGE_SIZE, \
MobiWriter, PALMDOC, UNCOMPRESSED
from calibre.ebooks.mobi.mobiml import MobiMLizer from calibre.ebooks.mobi.mobiml import MobiMLizer
from calibre.ebooks.oeb.transforms.manglecase import CaseMangler from calibre.ebooks.oeb.transforms.manglecase import CaseMangler
from calibre.ebooks.oeb.transforms.rasterize import SVGRasterizer, Unavailable from calibre.ebooks.oeb.transforms.rasterize import SVGRasterizer, Unavailable
from calibre.ebooks.oeb.transforms.htmltoc import HTMLTOCAdder from calibre.ebooks.oeb.transforms.htmltoc import HTMLTOCAdder
from calibre.customize.ui import plugin_for_input_format from calibre.customize.ui import plugin_for_input_format
imagemax = PALM_MAX_IMAGE_SIZE if opts.rescale_images else None
if not opts.no_inline_toc: if not opts.no_inline_toc:
tocadder = HTMLTOCAdder(title=opts.toc_title, position='start' if tocadder = HTMLTOCAdder(title=opts.toc_title, position='start' if
opts.mobi_toc_at_start else 'end') opts.mobi_toc_at_start else 'end')
@ -186,10 +183,9 @@ class MOBIOutput(OutputFormatPlugin):
mobimlizer = MobiMLizer(ignore_tables=opts.linearize_tables) mobimlizer = MobiMLizer(ignore_tables=opts.linearize_tables)
mobimlizer(oeb, opts) mobimlizer(oeb, opts)
self.check_for_periodical() self.check_for_periodical()
write_page_breaks_after_item = not input_plugin is plugin_for_input_format('cbz') write_page_breaks_after_item = input_plugin is not plugin_for_input_format('cbz')
writer = MobiWriter(opts, imagemax=imagemax, from calibre.ebooks.mobi.writer import MobiWriter
compression=UNCOMPRESSED if opts.dont_compress else PALMDOC, writer = MobiWriter(opts,
prefer_author_sort=opts.prefer_author_sort,
write_page_breaks_after_item=write_page_breaks_after_item) write_page_breaks_after_item=write_page_breaks_after_item)
writer(oeb, output_path) writer(oeb, output_path)

View File

@ -318,13 +318,15 @@ class Serializer(object): # {{{
class MobiWriter(object): class MobiWriter(object):
COLLAPSE_RE = re.compile(r'[ \t\r\n\v]+') COLLAPSE_RE = re.compile(r'[ \t\r\n\v]+')
def __init__(self, opts, compression=PALMDOC, imagemax=None, def __init__(self, opts,
prefer_author_sort=False, write_page_breaks_after_item=True): write_page_breaks_after_item=True):
self.opts = opts self.opts = opts
self.write_page_breaks_after_item = write_page_breaks_after_item self.write_page_breaks_after_item = write_page_breaks_after_item
self._compression = compression or UNCOMPRESSED self._compression = UNCOMPRESSED if getattr(opts, 'dont_compress',
self._imagemax = imagemax or OTHER_MAX_IMAGE_SIZE False) else PALMDOC
self._prefer_author_sort = prefer_author_sort self._imagemax = (PALM_MAX_IMAGE_SIZE if getattr(opts,
'rescale_images', False) else OTHER_MAX_IMAGE_SIZE)
self._prefer_author_sort = getattr(opts, 'prefer_author_sort', False)
self._primary_index_record = None self._primary_index_record = None
self._conforming_periodical_toc = False self._conforming_periodical_toc = False
self._indexable = False self._indexable = False