diff --git a/gestion/gen_confs/adherents.py b/gestion/gen_confs/adherents.py index e4c8f3eb..656ebbe0 100755 --- a/gestion/gen_confs/adherents.py +++ b/gestion/gen_confs/adherents.py @@ -4,12 +4,22 @@ # Copyright (C) Frédéric Pauget # Licence : GPLv2 -import smtplib, sys, commands, shutil, os +import smtplib, sys, commands, shutil, os, traceback sys.path.append('/usr/scripts/gestion') from affich_tools import cprint, anim, OK, WARNING, ERREUR import config from time import strftime +try: + sys.path.append('/usr/lib/mailman') + from Mailman.MailList import MailList + from Mailman.UserDesc import UserDesc + from Mailman.Errors import MMAlreadyAMember +except: + # Machine sans mailman, les ML ne seront pas reconfigurées + pass + + class del_user: """ Suppression des fichiers d'un compte utilisateur """ @@ -135,12 +145,18 @@ class ML_ens: def reconfigure(self): cprint(u'Inscription ML-ENS', 'gras') + mlist = MailList('com-ens') for mail in self.mails: anim('\t' + mail) - status, output = commands.getstatusoutput("echo '%s' | /usr/sbin/add_members -r - com-ens >/dev/null 2>&1" % mail) - if status: + try: + mlist.ApprovedAddMember(UserDesc(mail)) + except MMAlreadyAMember: + cprint(u"DÉJÀ INSCRIT", "jaune") + except: print ERREUR - if self.debug: - sys.stderr.write(output + '\n') + if self.debug: + traceback.print_exc() else: print OK + mlist.Save() + mlist.Unlock()