[ressuscite.py] Résurrection de clubs (merci Stall)
darcs-hash:20110118084236-ffbb2-ed9a1e979997c37da866410f189f2d6aa8f8af7c.gz
This commit is contained in:
parent
4f83a35258
commit
08865eae57
1 changed files with 96 additions and 7 deletions
|
@ -29,7 +29,7 @@ import time, pwd, ldap, ldap.modlist, random
|
|||
from time import mktime, strptime
|
||||
|
||||
sys.path.append('/usr/scripts/gestion')
|
||||
from ldap_crans import crans_ldap, MachineFixe, MachineWifi, Adherent, date_format
|
||||
from ldap_crans import crans_ldap, MachineFixe, MachineWifi, Adherent, Club, date_format
|
||||
from gest_crans import select, set_machine
|
||||
from whos import aff
|
||||
import affich_tools
|
||||
|
@ -50,7 +50,9 @@ def menu_principal():
|
|||
choices=[("A",u"Ressusciter à partir d'un adhérent",u"Rechercher les anciennes machines d'un adhérent"),
|
||||
("D",u"Ressusciter à partir de la date",u"Rechercher à partir de la date de suppression de la machine"),
|
||||
("F",u"Ressusciter à partir d'un fichier",u"Récupérer depuis un fichier du cimetière"),
|
||||
("C",u"Ressusciter un adhérent",u"Ressusciter un adhérent depuis un fichier du cimetière")],
|
||||
("C",u"Ressusciter un adhérent",u"Ressusciter un adhérent depuis un fichier du cimetière"),
|
||||
("K",u"Ressusciter un club",u"Ressusciter un club depuis un fichier du cimetière"),
|
||||
],
|
||||
item_help=1,title=u"Ressusciter")
|
||||
if annul: break
|
||||
|
||||
|
@ -155,6 +157,26 @@ def menu_principal():
|
|||
if not adh: continue
|
||||
ressuscite_adherent(adh)
|
||||
|
||||
elif choix == 'K':
|
||||
# Ressusciter à partir d'un fichier
|
||||
fichier = None
|
||||
while 1:
|
||||
annul, result = dlg.inputbox(width=54, height=12,
|
||||
text=u"Vous pourrez peut-être aussi exécuter le script sur le fichier\nressuscite [le fichier]\n\nFichier : ",
|
||||
init=u"/home/cimetiere/Club",
|
||||
title=u"Sélection du fichier")
|
||||
if annul: break
|
||||
try:
|
||||
fichier = open(result, 'r')
|
||||
break
|
||||
except:
|
||||
dlg.msgbox(text=u"Fichier invalide",title=u"Sélection du fichier")
|
||||
continue
|
||||
if fichier != None:
|
||||
club = cPickle.load(fichier)
|
||||
if not club: continue
|
||||
ressuscite_club(club)
|
||||
|
||||
continue
|
||||
|
||||
|
||||
|
@ -212,6 +234,8 @@ def choixadherent(machine, oldadh=None):
|
|||
"""Permet de choisir l'adhérent à qui rattacher la machine."""
|
||||
if oldadh == None:
|
||||
oldadhl = db.search(machine.dn.split(',', 2)[1])['adherent']
|
||||
if not oldadhl:
|
||||
oldadhl = db.search(machine.dn.split(',', 2)[1])['club']
|
||||
else:
|
||||
oldadhl = [oldadh]
|
||||
|
||||
|
@ -219,8 +243,7 @@ def choixadherent(machine, oldadh=None):
|
|||
arg += u'--menu "%s.' % machine.proprio
|
||||
|
||||
# Est-ce que l'adhérent existe encore ?
|
||||
if (len(oldadhl) > 0 and str(machine.proprio) == "%s %s"
|
||||
% (oldadhl[0].prenom(), oldadhl[0].nom())):
|
||||
if (len(oldadhl) > 0 and machine.proprio == oldadhl[0].Nom()):
|
||||
annul, choix = dlg.menu(u"Le propriétaire de la machine est %s" % machine.proprio,
|
||||
choices=[("Garder",u"Ajouter à cet adhérent"),
|
||||
("Autre",u"Ajouter à un autre adhérent")],
|
||||
|
@ -426,6 +449,75 @@ def ressuscite_adherent(old):
|
|||
print data
|
||||
raise ValueError("debug")
|
||||
|
||||
def ressuscite_club(old):
|
||||
"""Ressuscite une instance d'un club"""
|
||||
|
||||
if not isinstance(old, Club):
|
||||
dlg.msgbox(text=u"Ceci n'est pas un club !",
|
||||
title=u"Mauvais type d'objet")
|
||||
return
|
||||
if not isadm:
|
||||
dlg.msgbox(text=u"Vous devez être nounou !",
|
||||
title=u"Droits insuffisants")
|
||||
return
|
||||
|
||||
# On contourne ldap_crans
|
||||
data = old._data
|
||||
|
||||
# Ajout d'une entrée dans l'historique
|
||||
timestamp = time.localtime()
|
||||
hist = "%s, %s : " % (time.strftime(date_format, timestamp), cur_user)
|
||||
hist += "resurrection"
|
||||
data['historique'].append(hist)
|
||||
|
||||
# Entrées à vérifier :
|
||||
# aid, canonicalAlias, homeDirectory, mail, mailAlias, uid, uidNumber
|
||||
|
||||
# On recherche les aid/uidNumber pris
|
||||
used_cid = [0]
|
||||
used_uidNumber = [0]
|
||||
for r in db.conn.search_s(Club.base_dn, 1, Club.filtre_idn):
|
||||
# r = ( dn, {} )
|
||||
d = r[1]
|
||||
if d.has_key('cid'):
|
||||
used_cid.append(int(d['cid'][0]))
|
||||
if d.has_key('uidNumber'):
|
||||
used_uidNumber.append(int(d['uidNumber'][0]))
|
||||
|
||||
# Nouvelle valeur pour cid (peut mieux faire)
|
||||
cid = max(used_cid) + random.randint(1, 10)
|
||||
data['cid'] = [str(cid)]
|
||||
dn = 'cid=%d,ou=data,dc=crans,dc=org' % cid
|
||||
|
||||
if 'posixAccount' in data['objectClass']:
|
||||
# L'adhérent avait un compte, il faut changer/vérifier ses attributs
|
||||
uidNumber = max(used_uidNumber) + random.randint(1, 10)
|
||||
data['uidNumber'] = [str(uidNumber)]
|
||||
|
||||
# Disponibilité du login (vérification sommaire)
|
||||
login = data['uid'][0]
|
||||
if os.path.exists("/home/" + login):
|
||||
no = dlg.yesno(text=u"Le compte %s existe déjà, continuer ?" % login,
|
||||
title=u"Compte existant")
|
||||
if no:
|
||||
return
|
||||
if True:
|
||||
# On croise les doigts
|
||||
try:
|
||||
modlist = ldap.modlist.addModlist(data)
|
||||
db.conn.add_s(dn, modlist)
|
||||
dlg.msgbox(text=u"Résurrection effectée ! Veuillez maintenant restaurer le home et les mails",
|
||||
title=u"Fin")
|
||||
# Au cas où l'adhérent avait des droits
|
||||
db.services_to_restart('droits')
|
||||
# On notifie après une résurrection
|
||||
db.services_to_restart('mail_modif', ['uid=' + login])
|
||||
except Exception, e:
|
||||
dlg.msgbox(text=unicode(e), title=u"Erreur")
|
||||
|
||||
else:
|
||||
print data
|
||||
raise ValueError("debug")
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 2:
|
||||
|
@ -433,11 +525,8 @@ if __name__ == '__main__':
|
|||
os.system("clear")
|
||||
else:
|
||||
for path in sys.argv[1:]:
|
||||
try:
|
||||
fichier = open(path, 'r')
|
||||
machine = cPickle.load(fichier)
|
||||
adh = choixadherent(machine)
|
||||
if adh:
|
||||
ressuscite(adh, machine)
|
||||
except:
|
||||
print "Fichier invalide : %s" % fichier
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue