Changeset 194 for trunk/aeres/scripts
- Timestamp:
- 04/27/12 15:52:49 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/aeres/scripts/ldap_biblio.py
r164 r194 1 1 #! /usr/bin/env python 2 2 # -*- coding: iso-8859-15 -*- 3 4 __docformat__ = 'reStructuredText' 5 __revision__ = "$Id$" 6 __autodoc__ = ['ldap_biblio'] 3 7 4 8 """ … … 64 68 TODO 65 69 ==== 70 71 make it work on halios (pb version python-ldap) 66 72 67 73 server en argument … … 133 139 134 140 import ldap 141 142 import itertools 143 135 144 ldap_host = 'nestor.locean-ipsl.upmc.fr' 136 137 138 145 def get_option_parser (): 139 146 """parse CLI arguments … … 156 163 read LPAP 157 164 158 return surname, firstname capitalize first159 """ 160 161 # retrieve surname162 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 = [] 164 171 ldap_result_id = ildap.search_s(baseDN, searchScope, searchFilter, retrieveAttributes) 165 surname = []166 172 for ldap_result_one in ldap_result_id: 167 173 if retrieveAttributes: 174 values_for_one = [] 168 175 attrib_dict = ldap_result_one[1] 176 keys_for_one = attrib_dict.keys() 169 177 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 184 199 185 200 def ldap_biblio(): 186 201 """main 187 """ 202 """ 203 188 204 try: 189 205 parser = get_option_parser () … … 208 224 searchFilter = 'uid=*' 209 225 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 213 232 214 233 … … 216 235 if __name__ == '__main__': 217 236 ldap_biblio() 218 219
Note: See TracChangeset
for help on using the changeset viewer.