From 1cf67fe8503981b8aca985043bc5a8cd2799a365 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 10 Dec 2010 09:48:06 -0500 Subject: Remove common entries when deleting a master. Fixes: https://fedorahosted.org/freeipa/ticket/550 --- ipaserver/ipaldap.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'ipaserver/ipaldap.py') 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. -- cgit