From 1391cd65ad87e70b9544c11cf8c9d22f54df2902 Mon Sep 17 00:00:00 2001 From: Jan Cholasta Date: Wed, 25 May 2016 12:54:53 +0200 Subject: [PATCH] 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 --- ipalib/plugable.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ipalib/plugable.py b/ipalib/plugable.py index ed63ec646..b248a2c28 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -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):