Passe la connexion en argument des fonctions en ayant besoin
This commit is contained in:
parent
0492338bf8
commit
1e769cc9a9
1 changed files with 6 additions and 5 deletions
|
@ -14,6 +14,7 @@ from ldap import SIZELIMIT_EXCEEDED
|
|||
from gestion.config import encoding
|
||||
from gestion import affichage
|
||||
from gestion import annuaires_pg
|
||||
|
||||
import lc_ldap.shortcuts
|
||||
import lc_ldap.objets
|
||||
import lc_ldap.filter2 as lfilter
|
||||
|
@ -48,15 +49,15 @@ def print_data(data, args):
|
|||
print lc_ldap.printing.sprint_list(elem).encode(ENCODING)
|
||||
print "%s résultats" % len(elem)
|
||||
|
||||
def explore_db(args):
|
||||
def explore_db(args, ldap):
|
||||
"""Utilise le contenu de args pour décider comment explorer la base de données."""
|
||||
data = search_ldap(args)
|
||||
data = search_ldap(args, ldap)
|
||||
data = macro_expand(data, args)
|
||||
data = limits(data, args)
|
||||
|
||||
return data
|
||||
|
||||
def search_ldap(args):
|
||||
def search_ldap(args, ldap):
|
||||
"""Cherche et trie"""
|
||||
data = {}
|
||||
if args.ldap:
|
||||
|
@ -70,7 +71,7 @@ def search_ldap(args):
|
|||
search_filter = wild_search_filter(search_filter)
|
||||
|
||||
try:
|
||||
resultats = LDAP.search(search_filter, sizelimit=args.limite)
|
||||
resultats = ldap.search(search_filter, sizelimit=args.limite)
|
||||
except SIZELIMIT_EXCEEDED:
|
||||
raise EnvironmentError("La limite de résultats LDAP (%s) a été dépassée. Vous pouvez l'augmenter avec l'option -l" % (args.limite,))
|
||||
|
||||
|
@ -236,4 +237,4 @@ if __name__ == "__main__":
|
|||
else:
|
||||
LDAP = lc_ldap.shortcuts.lc_ldap_readonly()
|
||||
|
||||
print_data(explore_db(args), args)
|
||||
print_data(explore_db(args, LDAP), args)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue