Allow running the new upgrade book tool via ebook-polish

This commit is contained in:
Kovid Goyal 2018-04-15 17:58:14 +05:30
parent 7973f8798a
commit a37d55c96d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -15,6 +15,7 @@ from calibre.ebooks.oeb.polish.container import get_container
from calibre.ebooks.oeb.polish.stats import StatsCollector
from calibre.ebooks.oeb.polish.subset import subset_all_fonts, iter_subsettable_fonts
from calibre.ebooks.oeb.polish.images import compress_images
from calibre.ebooks.oeb.polish.upgrade import upgrade_book
from calibre.ebooks.oeb.polish.embed import embed_all_fonts
from calibre.ebooks.oeb.polish.cover import set_cover
from calibre.ebooks.oeb.polish.replace import smarten_punctuation
@ -33,6 +34,7 @@ ALL_OPTS = {
'smarten_punctuation':False,
'remove_unused_css':False,
'compress_images': False,
'upgrade_book': False,
}
CUSTOMIZATION = {
@ -112,6 +114,10 @@ that need to parse them all.</p>
affecting image quality.</p>
'''),
'upgrade_book': _('''\
<p>Upgrade the internal structures of the book, if possible. For instance,
upgrades EPUB 2 books to EPUB 3 books.</p>
'''),
}
@ -225,6 +231,12 @@ def polish_one(ebook, opts, report, customization=None):
changed = True
report('')
if opts.upgrade_book:
rt(_('Upgrading book, if possible'))
if upgrade_book(ebook, report):
changed = True
report('')
return changed
@ -292,6 +304,7 @@ def option_parser():
o('--smarten-punctuation', '-p', help=CLI_HELP['smarten_punctuation'])
o('--remove-unused-css', '-u', help=CLI_HELP['remove_unused_css'])
o('--compress-images', '-i', help=CLI_HELP['compress_images'])
o('--upgrade-book', '-U', help=CLI_HELP['upgrade_book'])
o('--verbose', help=_('Produce more verbose output, useful for debugging.'))