summaryrefslogtreecommitdiffstats
path: root/ipalib/plugable.py
diff options
context:
space:
mode:
Diffstat (limited to 'ipalib/plugable.py')
-rw-r--r--ipalib/plugable.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 25698d8f5..3be8bb118 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -59,6 +59,33 @@ def is_production_mode(obj):
return obj.env.mode == 'production'
+class Registry(object):
+ """A decorator that makes plugins available to the API
+
+ Usage::
+
+ register = Registry()
+
+ @register()
+ class obj_mod(...):
+ ...
+
+ For forward compatibility, make sure that the module-level instance of
+ this object is named "register".
+ """
+ # TODO: Instead of auto-loading when plugin modules are imported,
+ # plugins should be stored in this object.
+ # The API should examine it and load plugins explicitly.
+ def __call__(self):
+ from ipalib import api
+
+ def decorator(cls):
+ api.register(cls)
+ return cls
+
+ return decorator
+
+
class SetProxy(ReadOnly):
"""
A read-only container with set/sequence behaviour.