From 6f99bc3cea8bf76e53a67d29a6f25f7b0e27f683 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 5 Dec 2016 07:45:25 +0530 Subject: [PATCH] Make the original path to file available to FileType plugins --- src/calibre/customize/__init__.py | 5 +++-- src/calibre/customize/ui.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/calibre/customize/__init__.py b/src/calibre/customize/__init__.py index d155f3fad8..ff81ee0572 100644 --- a/src/calibre/customize/__init__.py +++ b/src/calibre/customize/__init__.py @@ -349,7 +349,9 @@ class FileTypePlugin(Plugin): # {{{ modified ebook. If no modifications are needed, it should return the path to the original ebook. If an error is encountered it should raise an Exception. The default implementation - simply return the path to the original ebook. + simply return the path to the original ebook. Note that the path to + the original file (before any file type plugins are run, is available as + self.original_path_to_file). The modified ebook file should be created with the :meth:`temporary_file` method. @@ -813,4 +815,3 @@ class LibraryClosedPlugin(Plugin): # {{{ raise NotImplementedError('LibraryClosedPlugin ' 'run method must be overridden in subclass') # }}} - diff --git a/src/calibre/customize/ui.py b/src/calibre/customize/ui.py index 94f972f66e..32487e74f8 100644 --- a/src/calibre/customize/ui.py +++ b/src/calibre/customize/ui.py @@ -39,6 +39,7 @@ def _config(): return ConfigProxy(c) + config = _config() @@ -97,6 +98,7 @@ def restore_plugin_state_to_default(plugin_or_name): ep.remove(x) config['enabled_plugins'] = ep + default_disabled_plugins = set([ 'Overdrive', 'Douban Books', 'OZON.ru', 'Edelweiss', 'Google Images', 'Big Book Search', ]) @@ -111,6 +113,7 @@ def is_disabled(plugin): # File type plugins {{{ + _on_import = {} _on_postimport = {} _on_preprocess = {} @@ -158,6 +161,7 @@ def _run_filetype_plugins(path_to_file, ft=None, occasion='preprocess'): oo, oe = sys.stdout, sys.stderr # Some file type plugins out there override the output streams with buggy implementations with plugin: try: + plugin.original_path_to_file = path_to_file nfp = plugin.run(path_to_file) if not nfp: nfp = path_to_file @@ -171,6 +175,7 @@ def _run_filetype_plugins(path_to_file, ft=None, occasion='preprocess'): nfp = path_to_file return nfp + run_plugins_on_import = functools.partial(_run_filetype_plugins, occasion='import') run_plugins_on_preprocess = functools.partial(_run_filetype_plugins, @@ -317,6 +322,8 @@ def available_stores(): # }}} # Metadata read/write {{{ + + _metadata_readers = {} _metadata_writers = {} @@ -362,6 +369,7 @@ class QuickMetadata(object): def __exit__(self, *args): self.quick = False + quick_metadata = QuickMetadata() @@ -376,6 +384,7 @@ class ApplyNullMetadata(object): def __exit__(self, *args): self.apply_null = False + apply_null_metadata = ApplyNullMetadata() @@ -390,6 +399,7 @@ class ForceIdentifiers(object): def __exit__(self, *args): self.force_identifiers = False + force_identifiers = ForceIdentifiers() @@ -629,6 +639,7 @@ def all_edit_book_tool_plugins(): # Initialize plugins {{{ + _initialized_plugins = [] @@ -694,6 +705,7 @@ def initialize_plugins(perf=False): reread_filetype_plugins() reread_metadata_plugins() + initialize_plugins() @@ -799,6 +811,7 @@ def main(args=sys.argv): return 0 + if __name__ == '__main__': sys.exit(main()) # }}}