summaryrefslogtreecommitdiffstats
path: root/src/nbblib/newplugins.py
diff options
context:
space:
mode:
authorHans Ulrich Niedermann <hun@n-dimensional.de>2008-06-26 18:31:53 +0200
committerHans Ulrich Niedermann <hun@n-dimensional.de>2008-07-15 12:28:53 +0200
commitf41bcd76c51161593fc329daa6d5c11aafd44c03 (patch)
tree00acfad4e3ad8f1f3b9ace8435cbcd03c89bec18 /src/nbblib/newplugins.py
parentcd162092db9007603fec7ff08aaaa3d527b6a9e9 (diff)
downloadnbb-f41bcd76c51161593fc329daa6d5c11aafd44c03.tar.gz
nbb-f41bcd76c51161593fc329daa6d5c11aafd44c03.tar.xz
nbb-f41bcd76c51161593fc329daa6d5c11aafd44c03.zip
Unified new plugin architecture
Changes required on the way: - New nbb commands detect-vcs and detect-bs including tests. - misc small fixes
Diffstat (limited to 'src/nbblib/newplugins.py')
-rw-r--r--src/nbblib/newplugins.py37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/nbblib/newplugins.py b/src/nbblib/newplugins.py
index 06905fe..ee59a48 100644
--- a/src/nbblib/newplugins.py
+++ b/src/nbblib/newplugins.py
@@ -1,7 +1,21 @@
-"""Usage of newplugins module:
+"""\
+newplugins.py - generic plugin system
+
+Basic plugin architecture (metaclass tricks) by Marty Alchin from
+http://gulopine.gamemusic.org/2008/jan/10/simple-plugin-framework/
+
+GenericPluginMeta slightly modified to
+ - store plugins as dict
+ - support plugin class hierarchies
+Extended by GenericDetectPlugin to
+ - support auto-detection of the adequate plugin
+
+Example usage of the newplugins module:
np = __import__(newplugins)
+Example non-auto-detection plugin:
+
class NonDetectPluginType(object):
__metaclass__ = np.GenericPluginMeta
@@ -10,8 +24,16 @@ class PluginA(NonDetectPluginType):
class PluginB(NonDetectPluginType):
name = "PB"
+Example auto-detection plugin:
+
class MyPluginType(np.GenericDetectPlugin):
__metaclass__ = np.GenericPluginMeta
+
+ # The calling convention for constructor
+ # detect(context, <mystuff...>)
+ # is defined here, and the same <mystuff...> is used
+ # to construct the exceptions.
+
[no_match_exception = ...]
[ambigous_match_exception = ...]
[
@@ -25,13 +47,13 @@ class MyPluginA(MyPluginType):
def __init__(self, context):
super(MyPluginA, self).__init__(self, context)
if not some_detection_successful:
- raise np.PluginNoMatch()
+ raise self.no_match_exception()
class MyPluginB(MyPluginType):
name = "MB"
def __init__(self, context):
super(MyPluginB, self).__init__(self, context)
if not other_detection_successful:
- raise np.PluginNoMatch()
+ raise self.no_match_exception()
"""
@@ -94,15 +116,6 @@ class PluginDict(dict):
super(PluginDict, self).__setitem__(key, value)
-########################################################################
-# Generic plugin system
-########################################################################
-# Plugin architecture (metaclass tricks) by Marty Alchin from
-# http://gulopine.gamemusic.org/2008/jan/10/simple-plugin-framework/
-# Slightly modified go store plugins as dict.
-########################################################################
-
-
class GenericPluginMeta(type):
def __init__(cls, name, bases, attrs):
logging.debug("%s %s %s %s", cls, name, bases, attrs)