From: Dan Scott Date: Wed, 11 Jul 2012 01:20:41 +0000 (-0400) Subject: Use synchronous methods and cleaner results X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=51389a4f782c85ef03ded095c6d134fc98179eb5;p=contrib%2FConifer.git Use synchronous methods and cleaner results Rather than calling ldap.result(), which results in awkward lists of lists which are hard to handle, just iterate over the results from ldap.search_s() (which, btw, is now a synchronous call). Signed-off-by: Dan Scott --- diff --git a/tools/patron-load/ldap_osrf_sync b/tools/patron-load/ldap_osrf_sync index dadd143de9..ba8e250f50 100755 --- a/tools/patron-load/ldap_osrf_sync +++ b/tools/patron-load/ldap_osrf_sync @@ -70,15 +70,15 @@ class User: Less formal than an actual 'au' object """ - def __init__(self, raw_ldap): + def __init__(self, raw_cn, raw_atts): """ Map core LDAP schema attributes to Evergreen user bits Easier to replace hard-coded mappings with calls to functions """ - self.cname = raw_ldap[0] - self.ldap_atts = raw_ldap[1] + self.cname = raw_cn + self.ldap_atts = raw_atts self.cn = self._simple_map('cn') self.lang_pref = self._simple_map('preferredLanguage') @@ -317,15 +317,14 @@ def find_ldap_users(con, ldap_filter, attributes, auth): results = [] try: - result_id = con.search(base_dn, search_scope, ldap_filter, attributes) - while 1: - result_type, result_data = con.result(result_id, 0) - if result_data == []: - break + raw_results = con.search_ext_s(base_dn, search_scope, ldap_filter, attributes) + for raw_user, raw_atts in raw_results: + if raw_atts == []: + continue - user = User(result_data[0]) + user = User(raw_user, raw_atts) if ARGS.dump_ldap: - dump_data(result_data) + dump_data(raw_atts) if ARGS.create_users: res = create_evergreen_user(auth, user) if res: @@ -416,7 +415,7 @@ def find_evergreen_user(auth, user): return None -def retrieve_evergreen_user(auth, user, uid): +def retrieve_evergreen_user(auth, uid): """ Update account for an existing user in Evergreen @@ -454,7 +453,7 @@ def create_evergreen_user(auth, user): if found: print("Found: %s" % user.usrname) - egau = retrieve_evergreen_user(auth, user, found) + egau = retrieve_evergreen_user(auth, found) egau.ischanged(True) egau.active(True) else: @@ -551,9 +550,8 @@ def dump_data(result_data): """ print() - print(result_data[0][0]) - for key in result_data[0][1]: - print(key, result_data[0][1][key]) + for key in result_data: + print(key, result_data[key]) def ldap_query(con, auth): """ @@ -693,7 +691,7 @@ def main(args=None): print >> sys.stderr, exc sys.exit() finally: - con.unbind() + con.unbind_ext_s() return results