Modernisation et passage à lc_ldap de mail_invalide
This commit is contained in:
parent
fcfdfbced9
commit
c3ba567ec8
1 changed files with 30 additions and 26 deletions
|
@ -1,4 +1,4 @@
|
||||||
#! /usr/bin/env python
|
#!/bin/bash /usr/scripts/python.sh
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -12,9 +12,8 @@ Licence : GPL v2
|
||||||
|
|
||||||
import os, sys, time
|
import os, sys, time
|
||||||
import subprocess
|
import subprocess
|
||||||
sys.path.append('/usr/scripts/gestion')
|
from lc_ldap import shortcuts
|
||||||
from ldap_crans import crans_ldap
|
from gestion.config import upload
|
||||||
from config import upload
|
|
||||||
# logging tools
|
# logging tools
|
||||||
import syslog
|
import syslog
|
||||||
def log(x):
|
def log(x):
|
||||||
|
@ -30,6 +29,8 @@ import utils.exceptions
|
||||||
import locale
|
import locale
|
||||||
locale.setlocale(locale.LC_TIME, 'fr_FR.UTF-8')
|
locale.setlocale(locale.LC_TIME, 'fr_FR.UTF-8')
|
||||||
|
|
||||||
|
# On blackliste 14 jours après que le script ait été éxécuté
|
||||||
|
DELAY = 14
|
||||||
|
|
||||||
help = """Script de déconnexion pour mail invalide.
|
help = """Script de déconnexion pour mail invalide.
|
||||||
Une fiche sera générée pour chaque adhérent.
|
Une fiche sera générée pour chaque adhérent.
|
||||||
|
@ -49,22 +50,23 @@ l'adhérent ayant l'aid 42."""
|
||||||
def generate_ps(proprio, mail):
|
def generate_ps(proprio, mail):
|
||||||
"""On génère la feuille d'avertissement et on retourne son emplacement."""
|
"""On génère la feuille d'avertissement et on retourne son emplacement."""
|
||||||
barcode = "/usr/scripts/admin/mail_invalide/barcode.eps"
|
barcode = "/usr/scripts/admin/mail_invalide/barcode.eps"
|
||||||
|
name = unicode(proprio['prenom'][0]) + u" " + unicode(proprio['nom'][0])
|
||||||
try:
|
try:
|
||||||
log('Generate invalid mail notice for %s' % proprio.Nom())
|
log(u'Generate invalid mail notice for %s' % name)
|
||||||
# Dossier de génération du ps
|
# Dossier de génération du ps
|
||||||
dossier = '/usr/scripts/var/mails_invalides'
|
dossier = '/usr/scripts/var/mails_invalides'
|
||||||
|
|
||||||
# Base pour le nom du fichier
|
# Base pour le nom du fichier
|
||||||
fichier = time.strftime('%Y-%m-%d-%H-%M') + '-mail-%s' % (proprio.Nom().
|
fichier = time.strftime('%Y-%m-%d-%H-%M') + '-mail-%s' % (name.
|
||||||
lower().replace(' ', '-'))
|
lower().replace(' ', '-'))
|
||||||
|
|
||||||
# Création du fichier tex
|
# Création du fichier tex
|
||||||
format_date = '%A %d %B %Y'
|
format_date = '%A %d %B %Y'
|
||||||
with open('%s/mail_invalide.tex' % os.path.dirname(__file__), 'r') as tempfile:
|
with open('%s/mail_invalide.tex' % os.path.dirname(__file__), 'r') as tempfile:
|
||||||
template = tempfile.read()
|
template = tempfile.read()
|
||||||
template = template.replace('~prenom~', proprio.prenom().encode('utf-8'))
|
template = template.replace('~prenom~', proprio['prenom'][0].encode('utf-8'))
|
||||||
template = template.replace('~nom~', proprio.nom().encode('utf-8'))
|
template = template.replace('~nom~', proprio['nom'][0].encode('utf-8'))
|
||||||
template = template.replace('~chambre~', proprio.chbre().encode('utf-8'))
|
template = template.replace('~chambre~', proprio['chbre'][0].encode('utf-8'))
|
||||||
template = template.replace('~mail~', mail.encode('utf-8').replace('_', '\\_'))
|
template = template.replace('~mail~', mail.encode('utf-8').replace('_', '\\_'))
|
||||||
template = template.replace('~fin~',
|
template = template.replace('~fin~',
|
||||||
time.strftime(format_date, time.localtime(time.time()+14*86400)))
|
time.strftime(format_date, time.localtime(time.time()+14*86400)))
|
||||||
|
@ -83,35 +85,37 @@ def generate_ps(proprio, mail):
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log('Erreur lors de la génération du ps : ')
|
log('Erreur lors de la génération du ps : ')
|
||||||
log(str(e))
|
log(str(e))
|
||||||
log("Values : adherent:%s" % proprio.Nom())
|
log("Values : adherent:%s" % name)
|
||||||
log(utils.exceptions.formatExc())
|
log(utils.exceptions.formatExc())
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def set_mail_invalide(adherent, mail, a_verifier, a_imprimer):
|
def set_mail_invalide(adherent, mail, a_verifier, a_imprimer):
|
||||||
if adherent.chbre() in ['????', 'EXT']:
|
if adherent['chbre'][0] in ['????', 'EXT']:
|
||||||
print u"Chambre de %s : %s, générer la fiche ? [Yn]" % (adherent.Nom().encode('utf-8'), adherent.chbre())
|
name = unicode(adherent['prenom'][0]) + u" " + unicode(adherent['nom'][0])
|
||||||
|
print u"Chambre de %s : %s, générer la fiche ? [Yn]" % (name, adherent['chbre'][0])
|
||||||
read = ''
|
read = ''
|
||||||
while read not in ['y', 'n']:
|
while read not in ['y', 'n']:
|
||||||
read = raw_input().lower()
|
read = raw_input().lower()
|
||||||
if read == 'n':
|
if read == 'n':
|
||||||
print u"Chambre de %s : %s, impossible de générer la fiche." % (adherent.Nom().encode('utf-8'), adherent.chbre())
|
print u"Chambre de %s : %s, impossible de générer la fiche." % (name, adherent['chbre'][0])
|
||||||
a_verifier.append(mail)
|
a_verifier.append(mail)
|
||||||
return
|
return
|
||||||
|
|
||||||
print "Génération de la fiche pour %s :" % adherent.Nom().encode('utf-8')
|
print u"Génération de la fiche pour %s :" % name
|
||||||
fiche = generate_ps(adherent, mail)
|
fiche = generate_ps(adherent, mail)
|
||||||
print fiche
|
print fiche
|
||||||
a_imprimer.append(fiche)
|
a_imprimer.append(fiche)
|
||||||
adherent.blacklist([time.time() + 14 * 24 * 3600,
|
with adherent as adh:
|
||||||
'-', 'mail_invalide', "Mail invalide"])
|
adh.blacklist('mail_invalide','Mail Invalide - Script',debut=int(time.time()) + DELAY * 24 * 3600)
|
||||||
adherent.save()
|
adh.history_gen()
|
||||||
|
adh.save()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if '--help' in sys.argv or '-h' in sys.argv or len(sys.argv) < 2:
|
if '--help' in sys.argv or '-h' in sys.argv or len(sys.argv) < 2:
|
||||||
print help
|
print help
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
db = crans_ldap()
|
ldap = shortcuts.lc_ldap_admin()
|
||||||
|
|
||||||
# On fait la liste des .forwards dans les homes
|
# On fait la liste des .forwards dans les homes
|
||||||
print " * Lecture des .forward ..."
|
print " * Lecture des .forward ..."
|
||||||
|
@ -141,24 +145,24 @@ if __name__ == "__main__":
|
||||||
# Est-ce un aid ?
|
# Est-ce un aid ?
|
||||||
if adresse[0] == '-':
|
if adresse[0] == '-':
|
||||||
print " * Recherche de aid=%s ..." % adresse[1:]
|
print " * Recherche de aid=%s ..." % adresse[1:]
|
||||||
res = db.search("aid=%s" % adresse[1:], 'w')['adherent']
|
res = ldap.search(u"aid=%s" % adresse[1:], mode='rw')
|
||||||
if len(res) == 0:
|
if len(res) == 0:
|
||||||
print "*** Erreur : aucun résultat pour aid=%s" % adresse[1:]
|
print "*** Erreur : aucun résultat pour aid=%s" % adresse[1:]
|
||||||
a_verifier.append(adresse)
|
a_verifier.append(adresse)
|
||||||
elif len(res) > 1:
|
elif len(res) > 1:
|
||||||
print "*** Erreur : plusieurs résultats pour aid=%s :" % adresse[1:]
|
print "*** Erreur : plusieurs résultats pour aid=%s :" % adresse[1:]
|
||||||
for adh in res:
|
for adh in res:
|
||||||
print adh.Nom()
|
print unicode(adh['prenom'][0]) + u" " + unicode(adh['nom'][0])
|
||||||
a_verifier.append(adresse)
|
a_verifier.append(adresse)
|
||||||
else:
|
else:
|
||||||
adherent = res[0]
|
adherent = res[0]
|
||||||
set_mail_invalide(adherent, adherent.email(), a_verifier, a_imprimer)
|
set_mail_invalide(adherent, adherent['mail'][0], a_verifier, a_imprimer)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print " * Recherche de %s ..." % adresse
|
print " * Recherche de %s ..." % adresse
|
||||||
# Est-ce un .forward ?
|
# Est-ce un .forward ?
|
||||||
if forwards.has_key(adresse):
|
if forwards.has_key(adresse):
|
||||||
res = db.search("uid=%s" % forwards[adresse], 'w')['adherent']
|
res = ldap.search(u"uid=%s" % forwards[adresse], mode='rw')
|
||||||
if len(res) == 0:
|
if len(res) == 0:
|
||||||
print "*** Erreur : aucun résultat pour uid=%s" % forwards[adresse]
|
print "*** Erreur : aucun résultat pour uid=%s" % forwards[adresse]
|
||||||
a_verifier.append(adresse)
|
a_verifier.append(adresse)
|
||||||
|
@ -168,18 +172,18 @@ if __name__ == "__main__":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Est-ce une adresse mail sans compte Cr@ns ?
|
# Est-ce une adresse mail sans compte Cr@ns ?
|
||||||
res = db.search("mail=%s" % adresse, 'w')['adherent']
|
res = ldap.search(u"(|(mail=%s)(mailExt=%s))" % (adresse,adresse), mode='rw')
|
||||||
if len(res) == 0:
|
if len(res) == 0:
|
||||||
print "*** Erreur : aucun résultat pour %s" % adresse
|
print "*** Erreur : aucun résultat pour %s" % adresse
|
||||||
a_verifier.append(adresse)
|
a_verifier.append(adresse)
|
||||||
elif len(res) > 1:
|
elif len(res) > 1:
|
||||||
print "*** Erreur : plusieurs résultats pour %s :" % adresse
|
print "*** Erreur : plusieurs résultats pour %s :" % adresse
|
||||||
for adh in res:
|
for adh in res:
|
||||||
print adh.Nom()
|
print unicode(adh['prenom'][0]) + u" " + unicode(adh['nom'][0])
|
||||||
a_verifier.append(adresse)
|
a_verifier.append(adresse)
|
||||||
else:
|
else:
|
||||||
adherent = res[0]
|
adherent = res[0]
|
||||||
set_mail_invalide(adherent, adherent.email(), a_verifier, a_imprimer)
|
set_mail_invalide(adherent, adresse, a_verifier, a_imprimer)
|
||||||
|
|
||||||
if len(a_verifier) + len(a_imprimer) > 0:
|
if len(a_verifier) + len(a_imprimer) > 0:
|
||||||
print ''
|
print ''
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue