summaryrefslogtreecommitdiffstats
path: root/ipalib/frontend.py
diff options
context:
space:
mode:
authorMartin Kosek <mkosek@redhat.com>2011-11-29 09:59:11 +0100
committerMartin Kosek <mkosek@redhat.com>2011-11-29 10:08:28 +0100
commit1b0b9645d197f512eee61051775414ca35ee7f6d (patch)
treeaf96542f62da62d8c4021474fc326b7470e46a95 /ipalib/frontend.py
parent046147b3a44b793049ee0100d775b8fe5c709999 (diff)
downloadfreeipa-1b0b9645d197f512eee61051775414ca35ee7f6d.tar.gz
freeipa-1b0b9645d197f512eee61051775414ca35ee7f6d.tar.xz
freeipa-1b0b9645d197f512eee61051775414ca35ee7f6d.zip
Add --delattr option to complement --setattr/--addattr
Add a --delattr option to round out multi-valued attribute manipulation. The new option is available for all LDAPUpdate based commands. --delattr is evaluated last, it can remove any value present either in --addattr/--setattr option or in current LDAP object. --*attr processing was completely refactored and placed to one independent function available for all baseldap commands. For this purpose a missing common base class for all baseldap commands has been implemented. The new class should serve not only for --*attr processing but also for other common baseldap methods and attributes. This approach will also benefit other custom commands based neither on LDAPCreate nor LDAPUpdate. They can easily integrate --*attr option processing when needed. https://fedorahosted.org/freeipa/ticket/1929
Diffstat (limited to 'ipalib/frontend.py')
-rw-r--r--ipalib/frontend.py62
1 files changed, 1 insertions, 61 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index 2ab457c3d..b79aad955 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -30,7 +30,7 @@ from util import make_repr
from output import Output, Entry, ListOfEntries
from text import _, ngettext
-from errors import ZeroArgumentError, MaxArgumentError, OverlapError, RequiresRoot, VersionError, RequirementError, ValidationError
+from errors import ZeroArgumentError, MaxArgumentError, OverlapError, RequiresRoot, VersionError, RequirementError
from errors import InvocationError
from constants import TYPE_ERROR
from ipapython.version import API_VERSION
@@ -535,45 +535,6 @@ class Command(HasParam):
kw = self.args_options_2_params(*args, **options)
return dict(self.__attributes_2_entry(kw))
- def __convert_2_dict(self, attrs, append=True):
- """
- Convert a string in the form of name/value pairs into
- a dictionary. The incoming attribute may be a string or
- a list.
-
- Any attribute found that is also a param is validated.
-
- append controls whether this returns a list of values or a single
- value.
- """
- newdict = {}
- if not type(attrs) in (list, tuple):
- attrs = [attrs]
- for a in attrs:
- m = re.match("\s*(.*?)\s*=\s*(.*?)\s*$", a)
- attr = str(m.group(1)).lower()
- value = m.group(2)
- if len(value) == 0:
- # None means "delete this attribute"
- value = None
- if attr in self.params:
- try:
- value = self.params[attr](value)
- except ValidationError, err:
- (name, error) = str(err.strerror).split(':')
- raise ValidationError(name=attr, error=error)
- if append and attr in newdict:
- if type(value) in (tuple,):
- newdict[attr] += list(value)
- else:
- newdict[attr].append(value)
- else:
- if type(value) in (tuple,):
- newdict[attr] = list(value)
- else:
- newdict[attr] = [value]
- return newdict
-
def __attributes_2_entry(self, kw):
for name in self.params:
if self.params[name].attribute and name in kw:
@@ -583,27 +544,6 @@ class Command(HasParam):
else:
yield (name, kw[name])
- adddict = {}
- if kw.get('setattr'):
- adddict = self.__convert_2_dict(kw['setattr'], append=False)
-
- if kw.get('addattr'):
- for (k, v) in self.__convert_2_dict(kw['addattr']).iteritems():
- if k in adddict:
- adddict[k] += v
- else:
- adddict[k] = v
-
- for name in adddict:
- value = adddict[name]
- if isinstance(value, list):
- if len(value) == 1:
- yield (name, value[0])
- else:
- yield (name, [v for v in value])
- else:
- yield (name, value)
-
def params_2_args_options(self, **params):
"""
Split params into (args, options).