diff options
author | Simo Sorce <ssorce@redhat.com> | 2010-12-10 09:48:06 -0500 |
---|---|---|
committer | Simo Sorce <ssorce@redhat.com> | 2010-12-21 17:28:13 -0500 |
commit | 1cf67fe8503981b8aca985043bc5a8cd2799a365 (patch) | |
tree | b36aa7612450d407d9737b5d3600d3b987b1c800 /ipaserver/ipaldap.py | |
parent | 5884fdf0f864d67fe7ee48d29f3c023882bc2891 (diff) | |
download | freeipa-1cf67fe8503981b8aca985043bc5a8cd2799a365.tar.gz freeipa-1cf67fe8503981b8aca985043bc5a8cd2799a365.tar.xz freeipa-1cf67fe8503981b8aca985043bc5a8cd2799a365.zip |
Remove common entries when deleting a master.
Fixes: https://fedorahosted.org/freeipa/ticket/550
Diffstat (limited to 'ipaserver/ipaldap.py')
-rw-r--r-- | ipaserver/ipaldap.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/ipaserver/ipaldap.py b/ipaserver/ipaldap.py index f7e0f3dd..b1f9f40c 100644 --- a/ipaserver/ipaldap.py +++ b/ipaserver/ipaldap.py @@ -640,6 +640,35 @@ class IPAdmin(SimpleLDAPObject): return ",".join(ary) normalizeDN = staticmethod(normalizeDN) + def get_dns_sorted_by_length(self, entries, reverse=False): + """ + Sorts a list of entries [(dn, entry_attrs)] based on their DN. + Entries within the same node are not sorted in any meaningful way. + If Reverse is set to True, leaf entries are returned first. This is + useful to perform recursive deletes where you need to delete entries + starting from the leafs and go up to delete nodes only when all its + leafs are removed. + + Returns a "sorted" dict keyed by dn lengths and corresponding list + of DNs. + {'1': [dn1, dn2, dn3], '2': [dn4, dn5], ..} + """ + + res = dict() + + for e in entries: + sdn = ldap.dn.str2dn(e.dn) + l = len(sdn) + if not l in res: + res[l] = [] + res[l].append(e.dn) + + keys = res.keys() + keys.sort(reverse=reverse) + + return map(res.get, keys) + + def notfound(args): """Return a string suitable for displaying as an error when a search returns no results. |