summaryrefslogtreecommitdiffstats
path: root/ipalib/plugable.py
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2013-08-01 14:55:10 +0200
committerPetr Viktorin <pviktori@redhat.com>2013-08-14 12:08:27 +0200
commit7804a74826eebd1ed07bc9eaa28c1eb9bff5a3f7 (patch)
treef6a17744f3b2276976eb9372544304e3c9aaee20 /ipalib/plugable.py
parenta8d2ec6677d97907c84751242620a3198484dc7b (diff)
downloadfreeipa-7804a74826eebd1ed07bc9eaa28c1eb9bff5a3f7.tar.gz
freeipa-7804a74826eebd1ed07bc9eaa28c1eb9bff5a3f7.tar.xz
freeipa-7804a74826eebd1ed07bc9eaa28c1eb9bff5a3f7.zip
Allow API plugin registration via a decorator
This makes plugin registration easier to read, less error-prone, and, for many Plugins in a single module, faster to write. Functionally, the decorator is equivalent to current plugin registration. However, in the future this style will allow cleaner semantics. As an example, and to exercise the new syntax to prevent regressions, the ping plugin is converted to this style.
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.