mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Fix plugin loading mechanism so that it now works with the Hello World plugin
This commit is contained in:
parent
b082e9ac87
commit
2b8d5c0046
@ -38,6 +38,9 @@ config = _config()
|
|||||||
class InvalidPlugin(ValueError):
|
class InvalidPlugin(ValueError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class PluginNotFound(ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
def load_plugin(path_to_zip_file):
|
def load_plugin(path_to_zip_file):
|
||||||
'''
|
'''
|
||||||
Load plugin from zip file or raise InvalidPlugin error
|
Load plugin from zip file or raise InvalidPlugin error
|
||||||
@ -45,6 +48,8 @@ def load_plugin(path_to_zip_file):
|
|||||||
:return: A :class:`Plugin` instance.
|
:return: A :class:`Plugin` instance.
|
||||||
'''
|
'''
|
||||||
print 'Loading plugin from', path_to_zip_file
|
print 'Loading plugin from', path_to_zip_file
|
||||||
|
if not os.access(path_to_zip_file, os.R_OK):
|
||||||
|
raise PluginNotFound
|
||||||
zf = ZipFile(path_to_zip_file)
|
zf = ZipFile(path_to_zip_file)
|
||||||
for name in zf.namelist():
|
for name in zf.namelist():
|
||||||
if name.lower().endswith('plugin.py'):
|
if name.lower().endswith('plugin.py'):
|
||||||
@ -52,14 +57,12 @@ def load_plugin(path_to_zip_file):
|
|||||||
exec zf.read(name) in locals
|
exec zf.read(name) in locals
|
||||||
for x in locals.values():
|
for x in locals.values():
|
||||||
if isinstance(x, type) and issubclass(x, Plugin):
|
if isinstance(x, type) and issubclass(x, Plugin):
|
||||||
if x.minimum_calibre_version > version:
|
if x.minimum_calibre_version > version or \
|
||||||
raise InvalidPlugin(_('%s needs calibre version at least %s')%
|
platform not in x.supported_platforms:
|
||||||
(x.name, x.minimum_calibre_version))
|
continue
|
||||||
if platform not in x.supported_platforms:
|
|
||||||
raise InvalidPlugin(_('%s is not supported on %s')%
|
|
||||||
(x.name, platform))
|
|
||||||
|
|
||||||
return x
|
return x
|
||||||
|
|
||||||
raise InvalidPlugin(_('No valid plugin found in ')+path_to_zip_file)
|
raise InvalidPlugin(_('No valid plugin found in ')+path_to_zip_file)
|
||||||
|
|
||||||
_initialized_plugins = []
|
_initialized_plugins = []
|
||||||
@ -211,7 +214,10 @@ def initialize_plugins():
|
|||||||
_initialized_plugins = []
|
_initialized_plugins = []
|
||||||
for zfp in list(config['plugins'].values()) + builtin_plugins:
|
for zfp in list(config['plugins'].values()) + builtin_plugins:
|
||||||
try:
|
try:
|
||||||
plugin = load_plugin(zfp) if not isinstance(zfp, type) else zfp
|
try:
|
||||||
|
plugin = load_plugin(zfp) if not isinstance(zfp, type) else zfp
|
||||||
|
except PluginNotFound:
|
||||||
|
continue
|
||||||
plugin = initialize_plugin(plugin, zfp if not isinstance(zfp, type) else zfp)
|
plugin = initialize_plugin(plugin, zfp if not isinstance(zfp, type) else zfp)
|
||||||
_initialized_plugins.append(plugin)
|
_initialized_plugins.append(plugin)
|
||||||
except:
|
except:
|
||||||
|
@ -53,6 +53,8 @@ That's all. To add this code to |app| as a plugin, simply create a zip file with
|
|||||||
|
|
||||||
zip plugin.zip my_plugin.py
|
zip plugin.zip my_plugin.py
|
||||||
|
|
||||||
|
You can download the Hellow World plugin from
|
||||||
|
`helloworld_plugin.zip <http://calibre.kovidgoyal.net/wiki/UserRecipes>`_.
|
||||||
Now either use the configuration dialog in |app| GUI to add this zip file as a plugin, or
|
Now either use the configuration dialog in |app| GUI to add this zip file as a plugin, or
|
||||||
use the command::
|
use the command::
|
||||||
|
|
||||||
@ -109,4 +111,4 @@ See :ref:`pluginsFTPlugin` for details.
|
|||||||
Metadata plugins
|
Metadata plugins
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
Metadata plugins add the ability to read/write metadata from ebook files to |app|. See :ref:`pluginsMetadataPlugin` for details.
|
Metadata plugins add the ability to read/write metadata from ebook files to |app|. See :ref:`pluginsMetadataPlugin` for details.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user