summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Ulrich Niedermann <hun@n-dimensional.de>2008-07-15 23:51:00 +0200
committerHans Ulrich Niedermann <hun@n-dimensional.de>2008-07-15 23:51:00 +0200
commitfc2bbdeec62a9006fde4bbd004ad4e5c81601c7e (patch)
tree9d388e4466d126c9c5bd9ca29730b2866eb13673
parent972e6308a88aa3c7b2da0e191029dddc42ce490b (diff)
downloadnbb-fc2bbdeec62a9006fde4bbd004ad4e5c81601c7e.tar.gz
nbb-fc2bbdeec62a9006fde4bbd004ad4e5c81601c7e.tar.xz
nbb-fc2bbdeec62a9006fde4bbd004ad4e5c81601c7e.zip
More robust plugin duplicate detection
When running pychecker, we got a few duplicate plugin errors due to multiple imports of the same module or something similar.
-rw-r--r--src/nbblib/plugins.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/nbblib/plugins.py b/src/nbblib/plugins.py
index c37b8a1..c3ab4fb 100644
--- a/src/nbblib/plugins.py
+++ b/src/nbblib/plugins.py
@@ -85,7 +85,12 @@ class NoPluginsRegistered(Exception):
__all__.append('DuplicatePluginName')
class DuplicatePluginName(Exception):
"""Raised when another plugin tries to register the same name"""
- pass
+ def __init__(self, name, old, new):
+ super(DuplicatePluginName, self).__init__()
+ self.msg = "Duplicate plugin name %s, old plugin %s, new plugin %s" \
+ % (repr(name), str(old), str(new))
+ def __str__(self):
+ return self.msg
__all__.append('PluginNoMatch')
@@ -182,8 +187,12 @@ class PluginDict(dict):
# This is the important difference between PluginDict and dict.
def __setitem__(self, key, value):
- if key in self:
- raise DuplicatePluginName()
+ if (key in self):
+ old = self[key]
+ if old.__name__ == value.__name__ and old.__module__ == value.__module__:
+ pass
+ else:
+ raise DuplicatePluginName(name=key, old=self[key], new=value)
else:
super(PluginDict, self).__setitem__(key, value)