summaryrefslogtreecommitdiffstats
path: root/ipalib/frontend.py
diff options
context:
space:
mode:
authorPavel Zuna <pzuna@redhat.com>2009-02-23 18:41:16 +0100
committerRob Crittenden <rcritten@redhat.com>2009-02-23 13:49:21 -0500
commit016b82250ea15dbdcb61da264fd45356422dbd8b (patch)
tree12efbfbf7754af89a1908d8c19c051795c3302e9 /ipalib/frontend.py
parentf2abe05398e5979dfa723dc353d96dc53fd9fc6f (diff)
downloadfreeipa-016b82250ea15dbdcb61da264fd45356422dbd8b.tar.gz
freeipa-016b82250ea15dbdcb61da264fd45356422dbd8b.tar.xz
freeipa-016b82250ea15dbdcb61da264fd45356422dbd8b.zip
Add ipalib.frontend.Command method to build an entry from params with attribute=True.
Often plugins need to build LDAP entries from params. This should make things a bit easier. Crud methods (Create, Retrieve, Update, Delete, Search) have attribute=True by default. And it also works for multivalue params.
Diffstat (limited to 'ipalib/frontend.py')
-rw-r--r--ipalib/frontend.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index 54f7c87a..db045fe6 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -176,6 +176,21 @@ class Command(plugable.Plugin):
if name in options:
yield (name, options[name])
+ def args_options_2_entry(self, *args, **options):
+ """
+ Creates a LDAP entry from attributes in args and options.
+ """
+ kw = self.args_options_2_params(*args, **options)
+ return dict(self.__attributes_2_entry(kw))
+
+ def __attributes_2_entry(self, kw):
+ for name in self.params:
+ if self.params[name].attribute and name in kw:
+ if type(kw[name]) is tuple:
+ yield (name, [str(value) for value in kw[name]])
+ else:
+ yield (name, str(kw[name]))
+
def params_2_args_options(self, **params):
"""
Split params into (args, options).