Changeset 194 for trunk/aeres/scripts


Ignore:
Timestamp:
04/27/12 15:52:49 (12 years ago)
Author:
pinsard
Message:

big progress on ldap reading

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/aeres/scripts/ldap_biblio.py

    r164 r194  
    11#! /usr/bin/env python 
    22# -*- coding: iso-8859-15 -*- 
     3 
     4__docformat__ = 'reStructuredText' 
     5__revision__ = "$Id$" 
     6__autodoc__ = ['ldap_biblio'] 
    37 
    48""" 
     
    6468TODO 
    6569==== 
     70 
     71make it work on halios (pb version python-ldap) 
    6672 
    6773server en argument 
     
    133139 
    134140import ldap 
     141 
     142import itertools 
     143 
    135144ldap_host = 'nestor.locean-ipsl.upmc.fr' 
    136  
    137  
    138145def get_option_parser (): 
    139146    """parse CLI arguments 
     
    156163    read LPAP  
    157164 
    158     return surname, firstname capitalize first 
    159     """ 
    160  
    161     # retrieve surname 
    162     retrieveAttributes = ['sn'] 
    163      
     165    return people dictionnary sn: uid: givenName:  mailForwardingAddress: 
     166    """ 
     167 
     168    retrieveAttributes = ['uid', 'sn', 'givenName', 'mailForwardingAddress'] 
     169    keys_for_all = [] 
     170    values_for_all = []  
    164171    ldap_result_id = ildap.search_s(baseDN, searchScope, searchFilter, retrieveAttributes) 
    165     surname = [] 
    166172    for ldap_result_one in ldap_result_id: 
    167173        if retrieveAttributes: 
     174            values_for_one = [] 
    168175            attrib_dict = ldap_result_one[1] 
     176            keys_for_one = attrib_dict.keys() 
    169177            for key in attrib_dict.keys(): 
    170                 surname.append(attrib_dict[key][0].title()) 
    171  
    172     # retrieve firstname 
    173     retrieveAttributes = ['givenName'] 
    174      
    175     ldap_result_id = ildap.search_s(baseDN, searchScope, searchFilter, retrieveAttributes) 
    176     firstname = [] 
    177     for ldap_result_one in ldap_result_id: 
    178         if retrieveAttributes: 
    179             attrib_dict = ldap_result_one[1] 
    180             for key in attrib_dict.keys(): 
    181                 firstname.append(attrib_dict[key][0].title()) 
    182  
    183     return surname, firstname 
     178                values_for_one.append(attrib_dict[key][0]) 
     179            keys_for_all.append(attrib_dict['uid'][0]) 
     180            values_for_all.append(dict(itertools.izip(keys_for_one, values_for_one))) 
     181 
     182            if is_verbose == True: 
     183                # pour voir la derniere personne ajoutée 
     184                print values_for_all[-1] 
     185 
     186    # populate dictonnary 
     187    people = dict(itertools.izip(keys_for_all, values_for_all)) 
     188 
     189    if is_verbose == True: 
     190        print attrib_dict.keys() 
     191        # vu le 20120427 avec retrieveAttributes = ['*'] 
     192        # ['uid', 'objectClass', 'uidNumber', 'sambaAcctFlags', 'street', 'cn', 'employeeType', 'facsimileTelephoneNumber', 'mailLocalAddress', 'sambaPwdMustChange', 'postalCode', 'mail', 'postalAddress', 'departmentNumber', 'loginShell', 'gidNumber', 'mailForwardingAddress', 'telephoneNumber', 'loceanAnnuaire', 'displayName', 'roomNumber', 'loceanPhotoUrl', 'carLicense', 'sambaSID', 'mailHost', 'sn', 'homeDirectory', 'givenName', 'loceanFinLogin'] 
     193 
     194        #print people.keys() 
     195        #print people['fplod'] 
     196        #print people['fplod'].values() 
     197 
     198    return people 
    184199 
    185200def ldap_biblio(): 
    186201    """main 
    187         """ 
     202    """ 
     203 
    188204    try: 
    189205        parser = get_option_parser () 
     
    208224    searchFilter = 'uid=*' 
    209225 
    210     surname, firstname = readldap(l, baseDN, searchScope, searchFilter, is_verbose) 
    211     print (' surname %s' % (surname)) 
    212     print (' firstname %s' % (firstname)) 
     226    people_ldap = readldap(l, baseDN, searchScope, searchFilter, is_verbose) 
     227 
     228    if is_verbose == True: 
     229        print (' result looking for key fplod: %s ' % people_ldap['fplod']) 
     230 
     231    #++ find in dict 
    213232 
    214233 
     
    216235if __name__ == '__main__': 
    217236    ldap_biblio() 
    218  
    219  
Note: See TracChangeset for help on using the changeset viewer.