From fe9a974e0afaec57bca7d63457c7aea39a06361d Mon Sep 17 00:00:00 2001 From: Antoine Durand-Gasselin Date: Sun, 17 Oct 2010 16:15:34 +0200 Subject: [PATCH] =?UTF-8?q?[attributs]=20toujours=20plus=20d'attributs,=20?= =?UTF-8?q?on=20va=20pe=20en=20venir=20=C3=A0=20bout...=20X=5Fx'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- attributs.py | 206 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 138 insertions(+), 68 deletions(-) diff --git a/attributs.py b/attributs.py index 8f766b7..b2628ec 100644 --- a/attributs.py +++ b/attributs.py @@ -133,18 +133,21 @@ class objectClass(Attr): self.value = unicode(val) -class aid(Attr): - singlevalue = True - optional = True - legend = u"Identifiant de l'adhérent" - - def parse_value(self, aid, ldif): - self.value = int(aid) +class intAttr(Attr): + def parse_value(self, val, ldif): + if int(val) <= 0: + raise ValueError("Valeur entière invalide : %s" % val) + self.value = int(val) def __unicode__(self): return unicode(self.value) -class uid(Attr): +class aid(intAttr): + singlevalue = True + optional = True + legend = u"Identifiant de l'adhérent" + +class uid(inAttr): singlevalue = True option = False legend = u"L'identifiant canonique de l'adhérent" @@ -178,33 +181,23 @@ class tel(Attr): raise ValueError("Numéro de téléphone invalide ('%s')" % val) -class paiement(Attr): +class yearAttr(intAttr): singlevalue = False - optional = True + optional= True + + def parse_value(self, val, ldif): + if int(val) < 1998 or int(val) > config.ann_scol: + raise ValueError("Année invalide (%s)" % val) + self.value = int(val) + + +class paiement(intAttr): legend = u"Paiement" - def parse_value(self, val, ldif): - if int(val) < 1998 or int(val) > config.ann_scol: - raise ValueError("Année de cotisation invalide (%s)" % val) - self.value = int(val) - def __unicode__(self): - return unicode(self.value) - - -class carteEtudiant(Attr): - singlevalue = False - optional = True +class carteEtudiant(intAttr): legend = u"Carte d'étudiant" - def parse_value(self, val, ldif): - if int(val) < 1998 or int(val) > config.ann_scol: - raise ValueError("Année de cotisation invalide (%s)" % val) - self.value = int(val) - - def __unicode__(self): - return unicode(self.value) - class mailAlias(Attr): singlevalue = False @@ -343,7 +336,7 @@ class puissance(Attr): optional = True legend = u"puissance d'émission pour les bornes wifi" -class canal(Attr): +class canal(intAttr): singlevalue = True optional = True legend = u'Canal d\'émission de la borne' @@ -354,6 +347,8 @@ class portAttr(Attr): optional = True def parse_value(self, port, ldif): + if int(port) <0 or int(port)> 65535: + raise ValueError("Port invalide: %s" % port) self.value = int(port) def __unicode__(self): @@ -381,17 +376,11 @@ class prise(Attr): ### Tu es une nounou, je te fais confiance self.value = prise -class cid(Attr): +class cid(intAttr): singlevalue = True optional = True legend = u"Identifiant du club" - def parse_value(self, cid, ldif): - self.value = int(cid) - - def __unicode__(self): - return unicode(self.value) - class responsable(Attr): singlevalue = True @@ -426,38 +415,119 @@ class historique(Attr): optional = True legend = u"Historique de l'objet" +class info(Attr): + singlevalue = False + optional = True + legend = u"Quelques informations" + +class homepageAlias(Attr): + singlevalue = True + optional = True + legend = u'Un alias pour la page personnelle' + +class charteMA(Attr): + singlevalue = True + optional = True + legend= "Signale si l'adhérent a signé la charte de membres actifs" + + def parse_value(self, signed, ldif): + if signed.upper() not in ["TRUE", "FALSE"]: + raise ValueError("La charte MA est soit TRUE ou FALSE, pas %s" % signed) + self.value = signed.upper() + +class homeDirectory(Attr): + singlevalue=True + optional = True + legend="Le chemin du home de l'adhérent" + + def parse_value(self, home, ldif): + if home != '/home/' + ldif['uid'][0]: + raise ValueError("Le répertoire personnel n'est pas bon: %s (devrait être %s)" % + (home, '/home/'+ ldif['uid'][0])) + self.value = home + +class loginShell(Attr): + singlevalue = True + optional = True + legend = "Le shell de l'adherent" + + def parse_value(self, shell, ldif): + with open('/etc/shells') as f: + shells = f.readlines() + if (shell not in shells) or shell.startswith('#'): + raise ValueError("Shell %s invalide" % shell) + self.value = shell + +class uidNumber(intAttr): + singlevalue = True + optional = True + legend = "L'uid du compte de l'adherent" + +class gidNumber(intAttr): + singlevalue = True + optional = True + legend = "Le gid du compte de l'adhérent" + +class gecos(Attr): + singlevalue = True + optional = True + legend = "Le gecos" + + def parse_value(self, gecos, ldif): + a, b, c, d = gecos.split(',') + self.value = gecos + +class mail(Attr): + singlevalue = True + optional = False + legend = "Le mail de l'adhérent" + + # XXX - to be implemented + #def parse_value(self, mail, ldif): + # pass CRANS_ATTRIBUTES= { -'objectClass' : objectClass, -'aid': aid, -'uid': uid, -'nom' : nom, -'prenom' : prenom, -'tel' : tel, -'paiement' : paiement, -'carteEtudiant' : carteEtudiant, -'mailAlias' : mailAlias, -'canonicalAlias' : canonicalAlias, -'etudes' : etudes, -'chbre' : chbre, -'droits' : droits, -'solde' : solde, -'mid' : mid, -'host' : host, -'macAddress': macAddress, -'ipHostNumber': ipHostNumber, -'hostAlias' : hostAlias, -'ipsec' : ipsec, -'puissance' : puissance, -'canal' : canal, -'portTCPout' : portTCPout, -'portTCPin' : portTCPin, -'portUDPout' : portUDPout, -'portUDPin' : portUDPin, -'prise' : prise, -'cid' : cid, -'responsable' : responsable, -'blacklist' : blacklist, -'historique' : historique + 'objectClass' : objectClass, + 'aid': aid, + 'uid': uid, + 'nom' : nom, + 'prenom' : prenom, + 'tel' : tel, + 'paiement' : paiement, + 'carteEtudiant' : carteEtudiant, + 'mailAlias' : mailAlias, + 'canonicalAlias' : canonicalAlias, + 'etudes' : etudes, + 'chbre' : chbre, + 'droits' : droits, + 'solde' : solde, + 'mid' : mid, + 'host' : host, + 'macAddress': macAddress, + 'ipHostNumber': ipHostNumber, + 'hostAlias' : hostAlias, + 'ipsec' : ipsec, + 'puissance' : puissance, + 'canal' : canal, + 'portTCPout' : portTCPout, + 'portTCPin' : portTCPin, + 'portUDPout' : portUDPout, + 'portUDPin' : portUDPin, + 'prise' : prise, + 'cid' : cid, + 'responsable' : responsable, + 'blacklist' : blacklist, + 'historique' : historique, + 'info': info, + 'homepageAlias': homepageAlias, + 'charteMA': charteMA, + 'mail' : mail, + + # {posix,shadow}Account + 'homeDirectory': homeDirectory, + 'loginShell': loginShell, + 'uidNumber': uidNumber, + 'gecos': gecos, + 'gidNumber': gidNumber }