From e47d04693d5217beab13e5fccf8c95fddd6979f2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 22 Jan 2010 12:33:17 -0700 Subject: [PATCH] Hook in notifications to catalog plugins --- src/calibre/customize/__init__.py | 2 +- src/calibre/customize/conversion.py | 3 + src/calibre/gui2/catalog/catalog_epub_mobi.py | 3 +- src/calibre/gui2/convert/gui_conversion.py | 7 +- src/calibre/library/catalog.py | 70 ++++++++----------- 5 files changed, 37 insertions(+), 48 deletions(-) diff --git a/src/calibre/customize/__init__.py b/src/calibre/customize/__init__.py index 5f35a38e12..0980f7b3a3 100644 --- a/src/calibre/customize/__init__.py +++ b/src/calibre/customize/__init__.py @@ -312,7 +312,7 @@ class CatalogPlugin(Plugin): continue resources.close() - def run(self, path_to_output, opts, db, ids): + def run(self, path_to_output, opts, db, ids, notification=None): ''' Run the plugin. Must be implemented in subclasses. It should generate the catalog in the format specified diff --git a/src/calibre/customize/conversion.py b/src/calibre/customize/conversion.py index a4c8a43e59..bd79f85e7f 100644 --- a/src/calibre/customize/conversion.py +++ b/src/calibre/customize/conversion.py @@ -85,6 +85,9 @@ class OptionRecommendation(object): class DummyReporter(object): + def __init__(self): + self.cancel_requested = False + def __call__(self, percent, msg=''): pass diff --git a/src/calibre/gui2/catalog/catalog_epub_mobi.py b/src/calibre/gui2/catalog/catalog_epub_mobi.py index 85f728552a..acb158a05f 100644 --- a/src/calibre/gui2/catalog/catalog_epub_mobi.py +++ b/src/calibre/gui2/catalog/catalog_epub_mobi.py @@ -44,8 +44,7 @@ class PluginWidget(QWidget,Ui_Form): for opt in self.OPTION_FIELDS: opt_value = unicode(getattr(self, opt[0]).text()) gprefs.set(self.name + '_' + opt[0], opt_value) - if opt[0] == 'exclude_tags': - opt_value = opt_value.split(',') + opt_value = opt_value.split(',') opts_dict[opt[0]] = opt_value opts_dict['output_profile'] = [load_defaults('page_setup')['output_profile']] diff --git a/src/calibre/gui2/convert/gui_conversion.py b/src/calibre/gui2/convert/gui_conversion.py index 4a1ce0d25b..7941586274 100644 --- a/src/calibre/gui2/convert/gui_conversion.py +++ b/src/calibre/gui2/convert/gui_conversion.py @@ -53,11 +53,6 @@ def gui_catalog(fmt, title, dbspec, ids, out_file_name, fmt_options, # Fetch and run the plugin for fmt plugin = plugin_for_catalog_format(fmt) - plugin.run(out_file_name, opts, db) - - - - - + plugin.run(out_file_name, opts, db, notification=notification) diff --git a/src/calibre/library/catalog.py b/src/calibre/library/catalog.py index e1dcf98537..188f29c72b 100644 --- a/src/calibre/library/catalog.py +++ b/src/calibre/library/catalog.py @@ -5,6 +5,7 @@ from xml.sax.saxutils import escape from calibre.ebooks.BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag, NavigableString from calibre.customize import CatalogPlugin from calibre.ptempfile import PersistentTemporaryDirectory +from calibre.customize.conversion import OptionRecommendation, DummyReporter FIELDS = ['all', 'author_sort', 'authors', 'comments', @@ -44,11 +45,12 @@ class CSV_XML(CatalogPlugin): "Default: '%default'\n" "Applies to: CSV, XML output formats"))] - def run(self, path_to_output, opts, db): + def run(self, path_to_output, opts, db, notification=DummyReporter()): from calibre.utils.logging import Log log = Log() self.fmt = path_to_output.rpartition('.')[2] + self.notification = notification if False and opts.verbose: log("%s:run" % self.name) @@ -467,12 +469,6 @@ class EPUB_MOBI(CatalogPlugin): # title dc:title in OPF metadata, NCX periodical # verbosity level of diagnostic printout - class DummyReporter(object): - def __init__(self): - self.cancelRequested = False - - def __call__(self, percent, msg=''): - pass def __init__(self, db, opts, plugin, generateForMobigen=False, @@ -664,47 +660,47 @@ class EPUB_MOBI(CatalogPlugin): # Methods def buildSources(self): - if self.reporter.cancelRequested: return 1 + if self.reporter.cancel_requested: return 1 if not self.booksByTitle: self.fetchBooksByTitle() - if self.reporter.cancelRequested: return 1 + if self.reporter.cancel_requested: return 1 self.fetchBooksByAuthor() - if self.reporter.cancelRequested: return 1 + if self.reporter.cancel_requested: return 1 self.generateHTMLDescriptions() - if self.reporter.cancelRequested: return 1 + if self.reporter.cancel_requested: return 1 self.generateHTMLByTitle() - if self.reporter.cancelRequested: return 1 + if self.reporter.cancel_requested: return 1 self.generateHTMLByAuthor() - if self.reporter.cancelRequested: return 1 + if self.reporter.cancel_requested: return 1 self.generateHTMLByTags() - if self.reporter.cancelRequested: return 1 + if self.reporter.cancel_requested: return 1 self.generateThumbnails() - if self.reporter.cancelRequested: return 1 + if self.reporter.cancel_requested: return 1 self.generateOPF() - if self.reporter.cancelRequested: return 1 + if self.reporter.cancel_requested: return 1 self.generateNCXHeader() - if self.reporter.cancelRequested: return 1 + if self.reporter.cancel_requested: return 1 self.generateNCXDescriptions("Descriptions") - if self.reporter.cancelRequested: return 1 + if self.reporter.cancel_requested: return 1 self.generateNCXByTitle("Titles", single_article_per_section=False) - if self.reporter.cancelRequested: return 1 + if self.reporter.cancel_requested: return 1 self.generateNCXByAuthor("Authors", single_article_per_section=False) - if self.reporter.cancelRequested: return 1 + if self.reporter.cancel_requested: return 1 self.generateNCXByTags("Genres") - if self.reporter.cancelRequested: return 1 + if self.reporter.cancel_requested: return 1 self.writeNCX() return 0 @@ -2520,8 +2516,7 @@ class EPUB_MOBI(CatalogPlugin): self.reporter(self.progressInt, self.progressString) return "%d%% %s" % (self.progressInt, self.progressString) - def run(self, path_to_output, opts, db): - from calibre.ebooks.conversion.cli import main as ebook_convert + def run(self, path_to_output, opts, db, notification=DummyReporter()): from calibre.utils.logging import Log log = Log() @@ -2548,28 +2543,25 @@ class EPUB_MOBI(CatalogPlugin): log(" %s: %s" % (key, opts_dict[key])) # Launch the Catalog builder - catalog = self.CatalogBuilder(db, opts, self) + catalog = self.CatalogBuilder(db, opts, self, notification=notification) catalog.createDirectoryStructure() catalog.copyResources() catalog.buildSources() - cmd_line_args = ['ebook-convert', - os.path.join(catalog.catalogPath, - opts.basename + '.opf'), - path_to_output] + recommendations = [] - if opts.fmt == 'mobi': - # options - if opts.output_profile.startswith("kindle"): - cmd_line_args.append("--output-profile=%s" % str(opts.output_profile)) - cmd_line_args.append("--no-inline-toc") - - - elif opts.fmt == 'epub': - pass + if opts.fmt == 'mobi' and opts.output_profile.startswith("kindle"): + recommendations.append(('output_profile', opts.output_profile, + OptionRecommendation.HIGH)) + recommendations.append(('no_inline_toc', True, + OptionRecommendation.HIGH)) # Run ebook-convert - ebook_convert(args=cmd_line_args) + from calibre.ebooks.conversion.plumber import Plumber + plumber = Plumber(os.path.join(catalog.catalogPath, + opts.basename + '.opf'), path_to_output, log, report_progress=notification, + abort_after_input_dump=False) + plumber.merge_ui_recommendations(recommendations) + plumber.run() - return None