mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Make the original path to file available to FileType plugins
This commit is contained in:
parent
cc0d25c123
commit
6f99bc3cea
@ -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')
|
||||
# }}}
|
||||
|
||||
|
@ -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())
|
||||
# }}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user