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

View File

@@ -82,7 +82,7 @@ class update_replica_attribute_lists(PreUpdate):
current = replica.toDict()
# Need to add it altogether
replica.setValues(attribute, template % " ".join(values))
replica[attribute] = [template % " ".join(values)]
try:
repl.conn.updateEntry(replica.dn, current, replica.toDict())
@@ -100,8 +100,8 @@ class update_replica_attribute_lists(PreUpdate):
', '.join(missing))
current = replica.toDict()
replica.setValue(attribute,
'%s %s' % (attrlist, ' '.join(missing)))
replica[attribute] = [
'%s %s' % (attrlist, ' '.join(missing))]
try:
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)
windomain = ipautil.suffix_to_realm(self.suffix)
entry.setValues("objectclass", "nsDSWindowsReplicationAgreement")
entry.setValues("nsds7WindowsReplicaSubtree", win_subtree)
entry.setValues("nsds7DirectoryReplicaSubtree", ds_subtree)
entry["objectclass"] = ["nsDSWindowsReplicationAgreement"]
entry["nsds7WindowsReplicaSubtree"] = [win_subtree]
entry["nsds7DirectoryReplicaSubtree"] = [ds_subtree]
# for now, just sync users and ignore groups
entry.setValues("nsds7NewWinUserSyncEnabled", 'true')
entry.setValues("nsds7NewWinGroupSyncEnabled", 'false')
entry.setValues("nsds7WindowsDomain", windomain)
entry["nsds7NewWinUserSyncEnabled"] = ['true']
entry["nsds7NewWinGroupSyncEnabled"] = ['false']
entry["nsds7WindowsDomain"] = [windomain]
def agreement_dn(self, hostname, master=None):
"""

View File

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

View File

@@ -705,29 +705,6 @@ class LDAPEntry(dict):
return value[0]
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):
# FIXME: for backwards compatibility only
"""Convert the attrs and values to a list of 2-tuples. The first element