From a53c1dd3d9a7c7e36cda61425ada4dbf36e6210a Mon Sep 17 00:00:00 2001 From: Progfou Date: Fri, 25 Nov 2011 19:48:32 +0700 Subject: [PATCH] =?utf8?q?Mise=20=C3=A0=20jour=20de=20l'outil=20de=20g=C3=A9?= =?utf8?q?n=C3=A9ration=20de=20LDIF=20pour=20l'annuaire=20AuF.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- auf-annuaire | 61 ++++++++++++++++++++++++---------------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/auf-annuaire b/auf-annuaire index 9296e23..ed59d02 100755 --- a/auf-annuaire +++ b/auf-annuaire @@ -29,28 +29,12 @@ objectClass: organizationalUnit ou: People """ -PERSONNELS = aufrefer.get('personnels.json') ISO_3166 = aufrefer.get('iso-3166-fr.json') NOMS_BUREAU = aufrefer.get('bureaux.json') -PAYS_IMPLANT = {'IFMT': 'LA', 'DANANG.VN': 'VN'} - -def capitale_sur_les_mots(s): - r = '' - previous_isalpha = False - for c in s: - isalpha = c.isalpha() - if isalpha and not previous_isalpha: - c = c.upper() - r += c - previous_isalpha = isalpha - return r - -def pays_implantation(implant): - return PAYS_IMPLANT.get(implant.upper(), implant.upper()) - -def nom_pays(country): - return ISO_3166.get(country.upper(), - u'### Pays absent de la norme ISO-3166 ###') +PAYS_IMPLANT = {'DANANG.VN': 'VN', 'HCMV.VN': 'VN', 'IFI': 'VN', + 'IFMT': 'LA', 'ITC': 'KH', 'IFAG': 'BG', 'IFE': 'MU'} + +PHOTO_FILENAME = "/var/lib/auf-refer-photos/%s.jpg" def noms_bureau(cc): for code, data in NOMS_BUREAU.items(): @@ -58,12 +42,6 @@ def noms_bureau(cc): return code, data[0] return u'### implantation inconnue ###', u'### implantation inconnue ###' -def login_nom_personnel(adel): - info = filter(lambda p: p['adel'] == adel, PERSONNELS) - if not info: - return None, None - return info[0]['login'], info[0]['nom'] - class LdapEntry(object): _attributes_order = [ 'objectClass', 'sn', 'givenName', 'cn', 'ou', 'l', 'mail', 'o', @@ -99,7 +77,7 @@ class LdapEntry(object): attribute = attribute + ':' if type(value) == unicode: value = value.encode('utf-8') - value = value.encode('base64').rstrip('\n') + value = value.encode('base64').replace('\n', '') return u'%s: %s' % (attribute, value) def to_ldif(self, changeType=None): @@ -129,26 +107,26 @@ class AnnuaireAuF(object): self.data = None def json2ldap(self, json_dict): - CC = pays_implantation(json_dict['implant']) + implant = json_dict['implant'].upper() + CC = PAYS_IMPLANT.get(implant, implant) nom_bureau_court, nom_bureau_long = noms_bureau(CC) adel = json_dict['adel'] - user, domain = adel.split('@') - cn = capitale_sur_les_mots(user) - cn = cn.replace('-De-', '-de-').replace('.', ' ') + user, domain = adel.rsplit('@', 1) + cn = user.title().replace('-De-', '-de-').replace('.', ' ') prenom, nom = cn.rsplit(' ', 1) - login, nom_affichage = login_nom_personnel(user) - if nom_affichage is None: - nom_affichage = json_dict['nom'] and json_dict['nom'] or cn + login = json_dict['login'] + nom_affichage = json_dict['nom'] and json_dict['nom'] or cn ldap_dict = { } ldap_dict['objectClass'] = [ - u'top', u'person', u'organizationalPerson', u'inetOrgPerson' + u'top', u'person', u'organizationalPerson', u'inetOrgPerson', + u'inetLocalMailRecipient', ] ldap_dict['sn'] = [ nom ] ldap_dict['givenName'] = [ prenom ] ldap_dict['cn'] = [ nom_affichage ] ldap_dict['ou'] = [ u'People', nom_bureau_court, nom_bureau_long ] - ldap_dict['l'] = [ nom_pays(CC) ] + ldap_dict['l'] = [ ISO_3166.get(CC, u'### Pays absent de la norme ISO-3166 ###') ] ldap_dict['mail'] = [ adel ] ldap_dict['o'] = [ u'AuF', u'Agence universitaire de la Francophonie' ] if json_dict.has_key('mdp') and json_dict['mdp']: @@ -157,6 +135,17 @@ class AnnuaireAuF(object): ldap_dict['telephoneNumber'] = [ json_dict['tel_ip'] ] if login is not None and login: ldap_dict['uid'] = [ login ] + else: + ldap_dict['uid'] = [ user ] + # objectClass: inetLocalMailRecipient + ldap_dict['mailLocalAddress'] = [ json_dict['redir'] ] + ldap_dict['mailHost'] = [ 'imaps://mail.%s:993' % json_dict['redir'].rsplit('@', 1)[1] ] + # photo JPEG + photo_filename = PHOTO_FILENAME % adel + if os.path.exists(photo_filename): + ldap_dict['jpegPhoto'] = [ file(photo_filename, 'rb').read() ] + #ldap_dict['photo'] = [ file(photo_filename, 'rb').read() ] + # identification unique ldap_dn = u'mail=%s,%s' % (adel, self.ldap_base) return ldap_dn, ldap_dict -- 1.7.10.4