Replace entry.setValue/setValues by item assignment

Part of the work for: https://fedorahosted.org/freeipa/ticket/2660
This commit is contained in:
Petr Viktorin
2013-01-21 04:42:16 -05:00
committed by Martin Kosek
parent c613caab67
commit 66c7fd1323
5 changed files with 21 additions and 44 deletions

View File

@@ -500,8 +500,8 @@ class LDAPUpdate:
e = list(e) e = list(e)
e.append(value) e.append(value)
else: else:
e = value e = [value]
entry.setValues(attr, e) entry[attr] = e
return self._entry_to_entity(entry) return self._entry_to_entity(entry)
@@ -583,7 +583,7 @@ class LDAPUpdate:
except ValueError: except ValueError:
self.warning("remove: '%s' not in %s", update_value, attr) self.warning("remove: '%s' not in %s", update_value, attr)
pass pass
entry.setValues(attr, entry_values) entry[attr] = entry_values
self.debug('remove: updated value %s', entry_values) self.debug('remove: updated value %s', entry_values)
elif action == 'add': elif action == 'add':
self.debug("add: '%s' to %s, current value %s", update_value, attr, entry_values) self.debug("add: '%s' to %s, current value %s", update_value, attr, entry_values)
@@ -594,7 +594,7 @@ class LDAPUpdate:
pass pass
entry_values.append(update_value) entry_values.append(update_value)
self.debug('add: updated value %s', entry_values) self.debug('add: updated value %s', entry_values)
entry.setValues(attr, entry_values) entry[attr] = entry_values
elif action == 'addifnew': elif action == 'addifnew':
self.debug("addifnew: '%s' to %s, current value %s", update_value, attr, entry_values) self.debug("addifnew: '%s' to %s, current value %s", update_value, attr, entry_values)
# Only add the attribute if it doesn't exist. Only works # Only add the attribute if it doesn't exist. Only works
@@ -602,7 +602,7 @@ class LDAPUpdate:
if len(entry_values) == 0: if len(entry_values) == 0:
entry_values.append(update_value) entry_values.append(update_value)
self.debug('addifnew: set %s to %s', attr, entry_values) self.debug('addifnew: set %s to %s', attr, entry_values)
entry.setValues(attr, entry_values) entry[attr] = entry_values
elif action == 'addifexist': elif action == 'addifexist':
self.debug("addifexist: '%s' to %s, current value %s", update_value, attr, entry_values) self.debug("addifexist: '%s' to %s, current value %s", update_value, attr, entry_values)
# Only add the attribute if the entry doesn't exist. We # Only add the attribute if the entry doesn't exist. We
@@ -610,7 +610,7 @@ class LDAPUpdate:
if entry.get('objectclass'): if entry.get('objectclass'):
entry_values.append(update_value) entry_values.append(update_value)
self.debug('addifexist: set %s to %s', attr, entry_values) self.debug('addifexist: set %s to %s', attr, entry_values)
entry.setValues(attr, entry_values) entry[attr] = entry_values
elif action == 'only': elif action == 'only':
self.debug("only: set %s to '%s', current value %s", attr, update_value, entry_values) self.debug("only: set %s to '%s', current value %s", attr, update_value, entry_values)
if only.get(attr): if only.get(attr):
@@ -618,7 +618,7 @@ class LDAPUpdate:
else: else:
entry_values = [update_value] entry_values = [update_value]
only[attr] = True only[attr] = True
entry.setValues(attr, entry_values) entry[attr] = entry_values
self.debug('only: updated value %s', entry_values) self.debug('only: updated value %s', entry_values)
elif action == 'onlyifexist': elif action == 'onlyifexist':
self.debug("onlyifexist: '%s' to %s, current value %s", update_value, attr, entry_values) self.debug("onlyifexist: '%s' to %s, current value %s", update_value, attr, entry_values)
@@ -631,7 +631,7 @@ class LDAPUpdate:
entry_values = [update_value] entry_values = [update_value]
only[attr] = True only[attr] = True
self.debug('onlyifexist: set %s to %s', attr, entry_values) self.debug('onlyifexist: set %s to %s', attr, entry_values)
entry.setValues(attr, entry_values) entry[attr] = entry_values
elif action == 'deleteentry': elif action == 'deleteentry':
# skip this update type, it occurs in __delete_entries() # skip this update type, it occurs in __delete_entries()
return None return None
@@ -667,7 +667,7 @@ class LDAPUpdate:
entry_values.remove(old) entry_values.remove(old)
entry_values.append(new) entry_values.append(new)
self.debug('replace: updated value %s', entry_values) self.debug('replace: updated value %s', entry_values)
entry.setValues(attr, entry_values) entry[attr] = entry_values
except ValueError: except ValueError:
self.debug('replace: %s not found, skipping', old) self.debug('replace: %s not found, skipping', old)

View File

@@ -82,7 +82,7 @@ class update_replica_attribute_lists(PreUpdate):
current = replica.toDict() current = replica.toDict()
# Need to add it altogether # Need to add it altogether
replica.setValues(attribute, template % " ".join(values)) replica[attribute] = [template % " ".join(values)]
try: try:
repl.conn.updateEntry(replica.dn, current, replica.toDict()) repl.conn.updateEntry(replica.dn, current, replica.toDict())
@@ -100,8 +100,8 @@ class update_replica_attribute_lists(PreUpdate):
', '.join(missing)) ', '.join(missing))
current = replica.toDict() current = replica.toDict()
replica.setValue(attribute, replica[attribute] = [
'%s %s' % (attrlist, ' '.join(missing))) '%s %s' % (attrlist, ' '.join(missing))]
try: try:
repl.conn.updateEntry(replica.dn, current, replica.toDict()) repl.conn.updateEntry(replica.dn, current, replica.toDict())

View File

@@ -489,13 +489,13 @@ class ReplicationManager(object):
ds_subtree = DN(IPA_USER_CONTAINER, self.suffix) ds_subtree = DN(IPA_USER_CONTAINER, self.suffix)
windomain = ipautil.suffix_to_realm(self.suffix) windomain = ipautil.suffix_to_realm(self.suffix)
entry.setValues("objectclass", "nsDSWindowsReplicationAgreement") entry["objectclass"] = ["nsDSWindowsReplicationAgreement"]
entry.setValues("nsds7WindowsReplicaSubtree", win_subtree) entry["nsds7WindowsReplicaSubtree"] = [win_subtree]
entry.setValues("nsds7DirectoryReplicaSubtree", ds_subtree) entry["nsds7DirectoryReplicaSubtree"] = [ds_subtree]
# for now, just sync users and ignore groups # for now, just sync users and ignore groups
entry.setValues("nsds7NewWinUserSyncEnabled", 'true') entry["nsds7NewWinUserSyncEnabled"] = ['true']
entry.setValues("nsds7NewWinGroupSyncEnabled", 'false') entry["nsds7NewWinGroupSyncEnabled"] = ['false']
entry.setValues("nsds7WindowsDomain", windomain) entry["nsds7WindowsDomain"] = [windomain]
def agreement_dn(self, hostname, master=None): def agreement_dn(self, hostname, master=None):
""" """

View File

@@ -199,9 +199,9 @@ class Service(object):
entry.dn = newdn entry.dn = newdn
classes = entry.get("objectclass") classes = entry.get("objectclass")
classes = classes + ["ipaobject", "ipaservice", "pkiuser"] classes = classes + ["ipaobject", "ipaservice", "pkiuser"]
entry.setValues("objectclass", list(set(classes))) entry["objectclass"] = list(set(classes))
entry.setValue("ipauniqueid", 'autogenerate') entry["ipauniqueid"] = ['autogenerate']
entry.setValue("managedby", hostdn) entry["managedby"] = [hostdn]
self.admin_conn.addEntry(entry) self.admin_conn.addEntry(entry)
return newdn return newdn

View File

@@ -705,29 +705,6 @@ class LDAPEntry(dict):
return value[0] return value[0]
return value return value
def setValue(self, name, *value):
# FIXME: for backwards compatibility only
"""
Set a value on this entry.
The value passed in may be a single value, several values, or a
single sequence. For example:
* ent.setValue('name', 'value')
* ent.setValue('name', 'value1', 'value2', ..., 'valueN')
* ent.setValue('name', ['value1', 'value2', ..., 'valueN'])
* ent.setValue('name', ('value1', 'value2', ..., 'valueN'))
Since value is a tuple, we may have to extract a list or tuple from
that tuple as in the last two examples above.
"""
if isinstance(value[0],list) or isinstance(value[0],tuple):
self.data[name] = value[0]
else:
self.data[name] = value
setValues = setValue
def toTupleList(self): def toTupleList(self):
# FIXME: for backwards compatibility only # FIXME: for backwards compatibility only
"""Convert the attrs and values to a list of 2-tuples. The first element """Convert the attrs and values to a list of 2-tuples. The first element