mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Refactor polishing code so it can be used from within Tweak Book
This commit is contained in:
parent
e00615d89d
commit
45edfa442c
@ -119,12 +119,8 @@ def update_metadata(ebook, new_opf):
|
|||||||
stream.truncate()
|
stream.truncate()
|
||||||
stream.write(opf.render())
|
stream.write(opf.render())
|
||||||
|
|
||||||
def polish(file_map, opts, log, report):
|
def polish_one(ebook, opts, report):
|
||||||
rt = lambda x: report('\n### ' + x)
|
rt = lambda x: report('\n### ' + x)
|
||||||
st = time.time()
|
|
||||||
for inbook, outbook in file_map.iteritems():
|
|
||||||
report(_('## Polishing: %s')%(inbook.rpartition('.')[-1].upper()))
|
|
||||||
ebook = get_container(inbook, log)
|
|
||||||
jacket = None
|
jacket = None
|
||||||
|
|
||||||
if opts.subset or opts.embed:
|
if opts.subset or opts.embed:
|
||||||
@ -178,6 +174,13 @@ def polish(file_map, opts, log, report):
|
|||||||
subset_all_fonts(ebook, stats.font_stats, report)
|
subset_all_fonts(ebook, stats.font_stats, report)
|
||||||
report('')
|
report('')
|
||||||
|
|
||||||
|
|
||||||
|
def polish(file_map, opts, log, report):
|
||||||
|
st = time.time()
|
||||||
|
for inbook, outbook in file_map.iteritems():
|
||||||
|
report(_('## Polishing: %s')%(inbook.rpartition('.')[-1].upper()))
|
||||||
|
ebook = get_container(inbook, log)
|
||||||
|
polish_one(ebook, opts, report)
|
||||||
ebook.commit(outbook)
|
ebook.commit(outbook)
|
||||||
report('-'*70)
|
report('-'*70)
|
||||||
report(_('Polishing took: %.1f seconds')%(time.time()-st))
|
report(_('Polishing took: %.1f seconds')%(time.time()-st))
|
||||||
@ -204,6 +207,15 @@ def gui_polish(data):
|
|||||||
log(msg)
|
log(msg)
|
||||||
return '\n\n'.join(report)
|
return '\n\n'.join(report)
|
||||||
|
|
||||||
|
def tweak_polish(container, actions):
|
||||||
|
opts = ALL_OPTS.copy()
|
||||||
|
opts.update(actions)
|
||||||
|
O = namedtuple('Options', ' '.join(ALL_OPTS.iterkeys()))
|
||||||
|
opts = O(**opts)
|
||||||
|
report = []
|
||||||
|
polish_one(container, opts, report.append)
|
||||||
|
return report
|
||||||
|
|
||||||
def option_parser():
|
def option_parser():
|
||||||
from calibre.utils.config import OptionParser
|
from calibre.utils.config import OptionParser
|
||||||
USAGE = '%prog [options] input_file [output_file]\n\n' + re.sub(
|
USAGE = '%prog [options] input_file [output_file]\n\n' + re.sub(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user