diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-09-24 04:44:52 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-09-24 04:44:52 +0000 |
commit | 3e70c3b56b29dcc9c0f6dd15eee7d4a24945944a (patch) | |
tree | 8f95bee2fb1e5919862e0d4795d1b73e3bbccd55 /ipalib/plugable.py | |
parent | 3bf2da571488b6f1ef27527fa3bff0133b44c2f5 (diff) | |
download | freeipa.git-3e70c3b56b29dcc9c0f6dd15eee7d4a24945944a.tar.gz freeipa.git-3e70c3b56b29dcc9c0f6dd15eee7d4a24945944a.tar.xz freeipa.git-3e70c3b56b29dcc9c0f6dd15eee7d4a24945944a.zip |
325: API.finalize() now creates instance attribtue 'plugins', which is a tuple of PluginInfo objects; renamed show_plugins cli command to namespaces; added new cli command plugins
Diffstat (limited to 'ipalib/plugable.py')
-rw-r--r-- | ipalib/plugable.py | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 8bf90ea8..cd130a19 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -708,16 +708,47 @@ class API(DictProxy): """ assert not self.__finalized, 'finalize() can only be called once' - instances = {} - def plugin_iter(base, classes): - for klass in classes: - if klass not in instances: - instances[klass] = klass() - plugin = instances[klass] + class PluginInstance(object): + """ + Represents a plugin instance. + """ + + i = 0 + + def __init__(self, klass): + self.created = self.next() + self.klass = klass + self.instance = klass() + self.bases = [] + + @classmethod + def next(cls): + cls.i += 1 + return cls.i + + class PluginInfo(ReadOnly): + def __init__(self, p): + assert isinstance(p, PluginInstance) + self.created = p.created + self.name = p.klass.__name__ + self.module = str(p.klass.__module__) + self.plugin = '%s.%s' % (self.module, self.name) + self.bases = tuple(b.__name__ for b in p.bases) + lock(self) + + plugins = {} + def plugin_iter(base, subclasses): + for klass in subclasses: + assert issubclass(klass, base) + if klass not in plugins: + plugins[klass] = PluginInstance(klass) + p = plugins[klass] + assert base not in p.bases + p.bases.append(base) if base.__proxy__: - yield PluginProxy(base, plugin) + yield PluginProxy(base, p.instance) else: - yield plugin + yield p.instance for name in self.register: base = self.register[name] @@ -731,10 +762,14 @@ class API(DictProxy): self.__d[name] = namespace object.__setattr__(self, name, namespace) - for plugin in instances.itervalues(): - plugin.set_api(self) - assert plugin.api is self + for p in plugins.itervalues(): + p.instance.set_api(self) + assert p.instance.api is self - for plugin in instances.itervalues(): - plugin.finalize() + for p in plugins.itervalues(): + p.instance.finalize() object.__setattr__(self, '_API__finalized', True) + tuple(PluginInfo(p) for p in plugins.itervalues()) + object.__setattr__(self, 'plugins', + tuple(PluginInfo(p) for p in plugins.itervalues()) + ) |