From 66c7fd1323619a99c48eb9babe4cbe7f48dca303 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Mon, 21 Jan 2013 04:42:16 -0500 Subject: Replace entry.setValue/setValues by item assignment Part of the work for: https://fedorahosted.org/freeipa/ticket/2660 --- ipaserver/install/ldapupdate.py | 18 ++++++++--------- .../install/plugins/fix_replica_agreements.py | 6 +++--- ipaserver/install/replication.py | 12 +++++------ ipaserver/install/service.py | 6 +++--- ipaserver/ipaldap.py | 23 ---------------------- 5 files changed, 21 insertions(+), 44 deletions(-) (limited to 'ipaserver') diff --git a/ipaserver/install/ldapupdate.py b/ipaserver/install/ldapupdate.py index 90975d7d7..23d332d30 100644 --- a/ipaserver/install/ldapupdate.py +++ b/ipaserver/install/ldapupdate.py @@ -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) diff --git a/ipaserver/install/plugins/fix_replica_agreements.py b/ipaserver/install/plugins/fix_replica_agreements.py index 2819acc92..54cbdd4d7 100644 --- a/ipaserver/install/plugins/fix_replica_agreements.py +++ b/ipaserver/install/plugins/fix_replica_agreements.py @@ -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()) diff --git a/ipaserver/install/replication.py b/ipaserver/install/replication.py index c017bbdac..a9d3d9c58 100644 --- a/ipaserver/install/replication.py +++ b/ipaserver/install/replication.py @@ -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): """ diff --git a/ipaserver/install/service.py b/ipaserver/install/service.py index e01415987..c0406d0ef 100644 --- a/ipaserver/install/service.py +++ b/ipaserver/install/service.py @@ -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 diff --git a/ipaserver/ipaldap.py b/ipaserver/ipaldap.py index 8a4e7ee98..b496bfbb4 100644 --- a/ipaserver/ipaldap.py +++ b/ipaserver/ipaldap.py @@ -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 -- cgit