summaryrefslogtreecommitdiffstats
path: root/ipalib/plugable.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-10-26 23:28:06 -0600
committerJason Gerard DeRose <jderose@redhat.com>2008-10-26 23:28:06 -0600
commit6b8abb0d78a8d86d7ca52083a267fe226bf74656 (patch)
treea271c1f3fed3141d7d333ea619cb7b677942d17f /ipalib/plugable.py
parentff5cb4cf6f036db892ebedc018b9740438c7e192 (diff)
downloadfreeipa-6b8abb0d78a8d86d7ca52083a267fe226bf74656.tar.gz
freeipa-6b8abb0d78a8d86d7ca52083a267fe226bf74656.tar.xz
freeipa-6b8abb0d78a8d86d7ca52083a267fe226bf74656.zip
Implemented placeholder API.bootstrap() method; added API __doing(), __do_if_not_done(), isdone() methods borrowed from Env; API.finalize() now cascades call to API.bootstrap()
Diffstat (limited to 'ipalib/plugable.py')
-rw-r--r--ipalib/plugable.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index fd87586d6..f01214332 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -707,19 +707,40 @@ class API(DictProxy):
"""
Dynamic API object through which `Plugin` instances are accessed.
"""
- __finalized = False
def __init__(self, *allowed):
self.__d = dict()
+ self.__done = set()
self.register = Registrar(*allowed)
self.env = Environment()
super(API, self).__init__(self.__d)
+ def __doing(self, name):
+ if name in self.__done:
+ raise StandardError(
+ '%s.%s() already called' % (self.__class__.__name__, name)
+ )
+ self.__done.add(name)
+
+ def __do_if_not_done(self, name):
+ if name not in self.__done:
+ getattr(self, name)()
+
+ def isdone(self, name):
+ return name in self.__done
+
+ def bootstrap(self, **overrides):
+ """
+ Initialize environment variables needed by built-in plugins.
+ """
+ self.__doing('bootstrap')
+
def finalize(self):
"""
Finalize the registration, instantiate the plugins.
"""
- assert not self.__finalized, 'finalize() can only be called once'
+ self.__doing('finalize')
+ self.__do_if_not_done('bootstrap')
class PluginInstance(object):
"""