plugable: remember overriden plugins in API

Remember what plugin class was overriden by what plugin class in API
objects. Add new method API.get_plugin_next which returns the plugin
class which was overriden by the plugin class specified as argument.

https://fedorahosted.org/freeipa/ticket/4739

Reviewed-By: David Kupka <dkupka@redhat.com>
This commit is contained in:
Jan Cholasta 2016-05-25 12:54:53 +02:00
parent 19cf6e9509
commit 1391cd65ad

View File

@ -267,6 +267,7 @@ class API(ReadOnly):
def __init__(self):
super(API, self).__init__()
self.__plugins = {}
self.__next = {}
self.__done = set()
self.env = Env()
@ -593,6 +594,8 @@ class API(ReadOnly):
name=klass.__name__,
plugin=klass,
)
self.__next[klass] = prev
else:
if override:
# There was nothing already registered to override:
@ -653,6 +656,12 @@ class API(ReadOnly):
if not production_mode:
lock(self)
def get_plugin_next(self, klass):
if not inspect.isclass(klass):
raise TypeError('plugin must be a class; got %r' % klass)
return self.__next[klass]
class IPAHelpFormatter(optparse.IndentedHelpFormatter):
def format_epilog(self, text):