scripts/gestion/gen_confs/supervison.py
glondu f16056b8b4 crans -> AssociationCrans
adherent -> Adherent
club -> Club

darcs-hash:20060325215156-68412-615c1bfb3b23e16cd10b82cc3dc467e716c258ea.gz
2006-03-25 22:51:56 +01:00

77 lines
2.5 KiB
Python
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#! /usr/bin/env python
# -*- coding: iso-8859-15 -*-
# Licence : GPLv2
import sys, smtplib, commands
sys.path.append('/usr/scripts/gestion')
from ldap_crans import smtpserv, crans_ldap, Machine, Adherent, Club
from whos import machine_details, adher_details, club_details
from gen_confs import gen_config
from affich_tools import cprint, OK, anim
class mail:
"""
Envoie un mail à toutes les personnes de la liste 'To', avec les
informations détaillées des objets contenus dans 'objets'
(instances des classes Adherent, Machine ou Club) """
From = 'root@crans.org'
To = [ 'roots@crans.org' ]
Subject = "Surveillance modifications de la base LDAP"
mail_template = """From: %(From)s
To: %(To)s
Subject: %(Subject)s
%(Text)s"""
# Avec les caract-Aères d'échappement qui vont bien pour la couleur ?-b
couleur = False
def __init__(self,recherches) :
self.recherches = recherches
def reconfigure(self) :
""" Envoi le mail """
cprint('Mail de notification de modifications','gras')
a = anim('\tRecherches dans la base',len(self.recherches))
db = crans_ldap()
details = []
vus = []
for rech in self.recherches :
for results in db.search(rech).values() :
for res in results :
if res.dn in vus : continue
vus.append(res.dn)
if isinstance(res, Machine):
details.append(machine_details(res))
elif res.__class__ == Adherent:
details.append(adher_details(res))
elif res.__class__ == Club:
details.append(club_details(res))
a.cycle()
texte = '\n\n- - - - = = = = # # # # # # = = = = - - - -\n\n'.join(details)
a.reinit()
if not details :
print "rien"
return
print OK
anim('\tEnvoi mail')
if not self.couleur :
import sre
texte = sre.sub('\x1b\[1;([0-9]|[0-9][0-9])m','',texte)
conn=smtplib.SMTP(smtpserv)
conn.sendmail(self.From, self.To , \
self.mail_template % { 'From' : self.From,
'To' : ','.join(self.To),
'Subject' : self.Subject,
'Text' : texte.encode('iso8859-15') } )
conn.quit()
print OK