Fix adding the same plugin twice to a running calibre would not cause a code reload.

This commit is contained in:
Kovid Goyal 2011-03-27 17:13:56 -06:00
parent 157155d774
commit ed1e75cc82
3 changed files with 19 additions and 10 deletions

View File

@ -12,6 +12,7 @@ import os, zipfile, posixpath, importlib, threading, re, imp, sys
from collections import OrderedDict
from functools import partial
from calibre import as_unicode
from calibre.customize import (Plugin, numeric_version, platform,
InvalidPlugin, PluginNotFound)
@ -160,27 +161,31 @@ class PluginLoader(object):
try:
ans = None
m = importlib.import_module(
'calibre_plugins.%s'%plugin_name)
plugin_module = 'calibre_plugins.%s'%plugin_name
m = sys.modules.get(plugin_module, None)
if m is not None:
reload(m)
else:
m = importlib.import_module(plugin_module)
for obj in m.__dict__.itervalues():
if isinstance(obj, type) and issubclass(obj, Plugin) and \
obj.name != 'Trivial Plugin':
ans = obj
break
if ans is None:
raise InvalidPlugin('No plugin class found in %r:%r'%(
path_to_zip_file, plugin_name))
raise InvalidPlugin('No plugin class found in %s:%s'%(
as_unicode(path_to_zip_file), plugin_name))
if ans.minimum_calibre_version > numeric_version:
raise InvalidPlugin(
'The plugin at %r needs a version of calibre >= %r' %
(path_to_zip_file, '.'.join(map(str,
'The plugin at %s needs a version of calibre >= %s' %
(as_unicode(path_to_zip_file), '.'.join(map(unicode,
ans.minimum_calibre_version))))
if platform not in ans.supported_platforms:
raise InvalidPlugin(
'The plugin at %r cannot be used on %s' %
(path_to_zip_file, platform))
'The plugin at %s cannot be used on %s' %
(as_unicode(path_to_zip_file), platform))
return ans
except:

View File

@ -19,7 +19,7 @@ class HelloWorld(FileTypePlugin):
version = (1, 0, 0) # The version number of this plugin
file_types = set(['epub', 'mobi']) # The file types that this plugin will be applied to
on_postprocess = True # Run this plugin after conversion is complete
minimum_calibre_version = (0, 7, 52)
minimum_calibre_version = (0, 7, 53)
def run(self, path_to_ebook):
from calibre.ebooks.metadata.meta import get_metadata, set_metadata

View File

@ -25,7 +25,7 @@ class InterfacePluginDemo(InterfaceActionBase):
supported_platforms = ['windows', 'osx', 'linux']
author = 'Kovid Goyal'
version = (1, 0, 0)
minimum_calibre_version = (0, 7, 52)
minimum_calibre_version = (0, 7, 53)
#: This field defines the GUI plugin class that contains all the code
#: that actually does something. Its format is module_path:class_name
@ -57,6 +57,10 @@ class InterfacePluginDemo(InterfaceActionBase):
The base class implementation of this method raises NotImplementedError
so by default no user configuration is possible.
'''
# It is important to put this import statement here rather than at the
# top of the module as importing the config class will also cause the
# GUI libraries to be loaded, which we do not want when using calibre
# from the command line
from calibre_plugins.interface_demo.config import ConfigWidget
return ConfigWidget()