Show the whole tree

Michael Ströder michael at stroeder.com
Thu Dec 4 19:00:37 CET 2003


Lukas Meyer wrote:
> 
> I want to show the whole tree with a for loop or anything else.

Really the whole tree at once?

Then you could retrieve the whole sub-tree in one search request and sort 
the reversed normalized DN into a list or to construct a dictionary-based 
tree-structure depending on your needs. I'm doing this to reconstruct the 
correct tree order of entries in LDIF files.

Off course this does not scale well on directories with 100000+ entries 
since it consumes memory. Also be prepared to hit a search limit which will 
leave your tree incomplete.

> hasLeaveEntry() is a funktion that returns 0 or 1 if a subentry is there.
> 
>    for name, attrs in l.search_s(dn, ldap.SCOPE_ONELEVEL, 
> "objectclass=*", []):
>          x = hasLeaveEntry(name)
>          if x == 1:
>                for name, attrs in l.search_s(dn, ldap.SCOPE_ONELEVEL, 
> "objectclass=*", []):
>                   x = hasLeaveEntry(name)
>                   and so on...
>          else:
>                continue

It's recursive which might be a problem on highly nested directory trees. 
Also I'd use the operational attribute 'hasSubordinates' if present or 
similar to spare the one search request per leaf entry.

You might wanna check the sources of web2ldap which do the recursive deletes 
(file pylib/w2lapp/delete.py).

Ciao, Michael.



More information about the python-ldap mailing list