diff options
author | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2008-07-26 11:26:15 +0200 |
---|---|---|
committer | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2008-07-26 11:26:15 +0200 |
commit | 7a90533a806fd76e89795fff427473e7264662f7 (patch) | |
tree | 7bcf5c2f4455887a9786bdb60708126ef936329b /src/nbblib/plugins.py | |
parent | 37ee99e8e72e2b8c50bec80f9b2bacc8dde04df7 (diff) | |
download | nbb-releases.tar.gz nbb-releases.tar.xz nbb-releases.zip |
nbb 0.2releases
* Switch to release tags including the package name
* Make automake's "nbb make" depend on configure etc.
Squashed commit of the following:
commit 9c4a035b71c7648b006b91a52e86edb2baea5138
Author: Hans Ulrich Niedermann <hun@n-dimensional.de>
Date: Sat Jul 26 10:36:31 2008 +0200
New version tag syntax: "make tag VER=1.2"
commit fefebc702664a683ceeafa800b0fe75178d63037
Author: Hans Ulrich Niedermann <hun@n-dimensional.de>
Date: Sat Jul 26 10:30:02 2008 +0200
Switch to release tags including the package name
This will reduce tag confusion when we fork into a
different project.
A tag like nbb-1.2 or foo-tools-1.2 is much more useful
than v1.2.
commit 330c382390ffbe3c361a763d5cee6febe1b30f5e
Author: Hans Ulrich Niedermann <hun@n-dimensional.de>
Date: Tue Jul 22 12:08:41 2008 +0200
Remove obsolete .htaccess file
commit b1d5fc06e235a45561bf53b4bfd07856cec4ea81
Author: Hans Ulrich Niedermann <hun@n-dimensional.de>
Date: Thu Jul 24 15:03:14 2008 +0200
Make automake's "make" command depend on configure
commit 958e81655ad143dfd54b099637db60db42f77fb0
Author: Hans Ulrich Niedermann <hun@n-dimensional.de>
Date: Thu Jul 24 15:00:33 2008 +0200
Adjust testcases for absolute builddirs
When configure is called as /path/to/configure instead of
../path/to/configure, the ".git/" test directories are reported
by "git init" using absolute pathnames, not must ".git/".
commit 72dac191283299c66356dc895eb6ba19982b16ab
Author: Hans Ulrich Niedermann <hun@n-dimensional.de>
Date: Thu Jul 24 14:59:19 2008 +0200
Fix typo in automake/distcheck test case
commit 7ca2e00188d8668b6b1f4116559ddae4e3cbb35c
Author: Hans Ulrich Niedermann <hun@n-dimensional.de>
Date: Thu Jul 24 13:32:49 2008 +0200
Open 0.1.x section in NEWS
commit e05a138e9e3099455fa23799550949512188b3c9
Author: Hans Ulrich Niedermann <hun@n-dimensional.de>
Date: Tue Jul 22 08:40:31 2008 +0200
Add license review to TODO
commit e2fd1f2e101486859899049147df7993c8042df7
Author: Hans Ulrich Niedermann <hun@n-dimensional.de>
Date: Sat Jul 19 00:25:12 2008 +0200
Ensure cmp/mv/rm rules are correct and silent
Make sure the "if cmp ... mv .. rm" in make rules are
correct and useful, and the cmp is silent.
commit b6e7a354ed1ab53aebdb775a800156629744a065
Author: Hans Ulrich Niedermann <hun@n-dimensional.de>
Date: Wed Jul 16 21:03:36 2008 +0200
Reflect code progress in TODO file, add plans
commit 9559ceb5def8ec5d2e5674e7bf25b484877b3e60
Author: Hans Ulrich Niedermann <hun@n-dimensional.de>
Date: Wed Jul 16 06:12:30 2008 +0200
Fix some issues found by pylint/pychecker
Includes real issues like wrong argument numbers and missing
ancestor __init__() calls, whitespace and comment cleanups.
Cannot "fix" everything because of a good amount of the warnings
raised by pylint/pychecker are false alarms.
commit c73487455e8d9a283fcb328eab8573c4c5bc73c7
Author: Hans Ulrich Niedermann <hun@n-dimensional.de>
Date: Wed Jul 16 06:11:57 2008 +0200
Add pylint and pychecker checks as "lint" target
Diffstat (limited to 'src/nbblib/plugins.py')
-rw-r--r-- | src/nbblib/plugins.py | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/src/nbblib/plugins.py b/src/nbblib/plugins.py index a21e2d4..d4b753a 100644 --- a/src/nbblib/plugins.py +++ b/src/nbblib/plugins.py @@ -55,13 +55,16 @@ class MyPluginB(MyPluginType): if not other_detection_successful: raise self.no_match_exception() -Ideas: - * Get rid of references to 'context', and handle that in derived classes. - Bad idea, as any serious plugin using program will have the plugins - operating in some kind of context. """ +# TODO: Check plugin instances for defined members. +# 1. class AbstractMember(...): __get__, __set__ +# 2. class ConcreteMember(...): __get__, __set__ +# 3. plugin registration checks presence of AbstractMember instances, +# and fails if one is found + + import logging import functools import inspect @@ -107,6 +110,7 @@ __all__.append('AmbigousPluginDetection') class AmbigousPluginDetection(Exception): """Raised when more than one registered plugin matches the given args""" def __init__(self, matches, cls, context, *args, **kwargs): + super(AmbigousPluginDetection, self).__init__() self.matches = matches self.cls = cls self.context = context @@ -130,10 +134,11 @@ class AbstractMethodsInConcreteClass(Exception): implemented if this class is not abstract itself. """ def __init__(self, cls, methods): + super(AbstractMethodsInConcreteClass, self).__init__() self.cls = cls self.methods = methods def __str__(self): - methods = " ".join((k for k,v in self.methods)) + methods = " ".join((key for key, value in self.methods)) return "Class %s.%s must implement the %s abstract methods." \ % (self.cls.__module__, self.cls.__name__, @@ -144,10 +149,11 @@ __all__.append('AbstractMethodError') class AbstractMethodError(Exception): """Raised when an abstract method is called""" def __init__(self, name, module): + super(AbstractMethodError, self).__init__() self.name = name self.module = module def __str__(self): - # FIXME: Class name? + # FIXME: How to print class name alongside module and method name? return "Abstract method %s called someplace in %s" \ % (repr(self.name), repr(self.module)) @@ -167,12 +173,12 @@ def abstractmethod(fun): before the actual program is run! """ @functools.wraps(fun) - def f(self, *args, **kwargs): + def wrapper(self, *args, **kwargs): # fun(self, *args, **kwargs) raise AbstractMethodError(name=fun.__name__, module=fun.__module__) - f.abstract_method = True - return f + wrapper.abstract_method = True + return wrapper # Internal type __all__.append('PluginDict') @@ -216,26 +222,27 @@ class GenericPluginMeta(type): You can add abstract subclasses of Plugin by giving them a __name__ = None, define an @abstractmethod method in that abstract subclass, and much more. """ - def __init__(cls, name, bases, attrs): - logging.debug("META_INIT %s %s %s %s", cls, name, bases, attrs) - if not hasattr(cls, 'plugins'): + def __init__(mcs, name, bases, attrs): + super(GenericPluginMeta, mcs).__init__() + logging.debug("META_INIT %s %s %s %s", mcs, name, bases, attrs) + if not hasattr(mcs, 'plugins'): # This branch only executes when processing the mount point itself. # So, since this is a new plugin type, not an implementation, this # class shouldn't be registered as a plugin. Instead, it sets up a # list where plugins can be registered later. - cls.plugins = PluginDict() - elif cls.name is not None: + mcs.plugins = PluginDict() + elif mcs.name is not None: # This must be a plugin implementation, which should be registered. # Simply appending it to the list is all that's needed to keep # track of it later. def abstract_method_filter(member): return hasattr(member, '__call__') \ and hasattr(member, 'abstract_method') - ams = inspect.getmembers(cls, abstract_method_filter) + ams = inspect.getmembers(mcs, abstract_method_filter) if ams: - raise AbstractMethodsInConcreteClass(cls, ams) - logging.debug("Registering %s with %s as %s", cls, cls.plugins, cls.name) - cls.plugins[cls.name] = cls + raise AbstractMethodsInConcreteClass(mcs, ams) + logging.debug("Registering %s with %s as %s", mcs, mcs.plugins, mcs.name) + mcs.plugins[mcs.name] = mcs else: # This must be an abstract subclass of plugins. pass @@ -310,7 +317,7 @@ class GenericDetectPlugin(object): logging.debug("KLASS %s validated", klass) matches[key] = t except PluginNoMatch: - pass + pass # ignore non-matching plugins logging.debug("Matches: %s", matches) if len(matches) > 1: raise cls.ambigous_match_exception(matches, |