[ldap_crans.py] on fait hériter ldap_crans de dict
Ignore-this: 367e9e6dda023f2b5c8d410fca96777a darcs-hash:20090916190406-bd074-46fae3d6a4517be4b1c17740eaad915d2580a000.gz
This commit is contained in:
parent
a62d0a2257
commit
c399d0a4f6
1 changed files with 84 additions and 1 deletions
|
@ -256,7 +256,7 @@ class Service:
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.__unicode__().encode("utf-8", "ignore")
|
return self.__unicode__().encode("utf-8", "ignore")
|
||||||
|
|
||||||
class CransLdap:
|
class CransLdap(dict):
|
||||||
"""
|
"""
|
||||||
Classe de connexion à la base LDAP du crans.
|
Classe de connexion à la base LDAP du crans.
|
||||||
"""
|
"""
|
||||||
|
@ -880,6 +880,14 @@ class CransLdap:
|
||||||
|
|
||||||
return self.__machines
|
return self.__machines
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Méthodes pour fournir une interface proche d'un dictionnaire
|
||||||
|
def copy(self):
|
||||||
|
new = dict.copy(self)
|
||||||
|
new._locks = self._locks
|
||||||
|
new.conn = self.conn
|
||||||
|
return new
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
class BaseClasseCrans(CransLdap):
|
class BaseClasseCrans(CransLdap):
|
||||||
|
@ -1811,6 +1819,30 @@ class BaseProprietaire(BaseClasseCrans):
|
||||||
|
|
||||||
return self._data[champ]
|
return self._data[champ]
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# définition des méthodes de dictionnaire
|
||||||
|
def __setitem__(self, lbl, value):
|
||||||
|
# on exécute la parente
|
||||||
|
BaseClasseCrans.__setitem__(self, lbl, value)
|
||||||
|
|
||||||
|
# on fait des trucs sur les labels qui nous intéressent
|
||||||
|
if lbl in ['+p', '+c']:
|
||||||
|
if value == True: self.controle(lbl)
|
||||||
|
elif value == False: self.controle('-' + lbl[1])
|
||||||
|
else: raise ValueError(lbl + u'doit être True ou False')
|
||||||
|
elif lbl == 'shell': self.chsh(value)
|
||||||
|
elif lbl == 'alias': self.alias(value)
|
||||||
|
elif lbl == 'greylist': self.contourneGreylist(value)
|
||||||
|
else: pass
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
new = CransLdap.copy(self)
|
||||||
|
new._init_data = self._init_data
|
||||||
|
new._data = self._data
|
||||||
|
new.modifs = self.modifs
|
||||||
|
new.modifiable = self.modifiable
|
||||||
|
return new
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
class Adherent(BaseProprietaire):
|
class Adherent(BaseProprietaire):
|
||||||
|
@ -2404,6 +2436,38 @@ class Adherent(BaseProprietaire):
|
||||||
def is_nounou( self ):
|
def is_nounou( self ):
|
||||||
return u"Nounou" in self.droits()
|
return u"Nounou" in self.droits()
|
||||||
|
|
||||||
|
##############################################################
|
||||||
|
# définition de __setitem__
|
||||||
|
def __setitem__(self, lbl, value):
|
||||||
|
# on exécute la parente
|
||||||
|
BaseProprietaire.__setitem__(self, lbl, value)
|
||||||
|
|
||||||
|
# on fait les affectations
|
||||||
|
if lbl == 'nom': self.nom(value)
|
||||||
|
elif lbl == 'prenom': self.prenom(value)
|
||||||
|
elif lbl == 'tel': self.tel(value)
|
||||||
|
elif lbl == 'chbre': self.chbre(value)
|
||||||
|
elif re.match(r'addr\d+', lbl):
|
||||||
|
addr = self.addresse()
|
||||||
|
addr[int(lbl[4]) + 1] = value
|
||||||
|
self.addresse(addr)
|
||||||
|
elif lbl == 'mail': self.mail(value)
|
||||||
|
elif lbl == 'chartema': self.charteMA(value)
|
||||||
|
elif lbl == 'payant': self.adherentPayant(value)
|
||||||
|
elif re.match(r'etud\d+', lbl):
|
||||||
|
etud = self.etudes()
|
||||||
|
etud[int(lbl[4]) + 1] = value
|
||||||
|
self.etudes(etud)
|
||||||
|
elif lbl == 'carte':
|
||||||
|
if value == True: self.carteEtudiant(ann_scol)
|
||||||
|
elif value == False: self.carteEtudiant(-ann_scol)
|
||||||
|
else: raise ValueError(u"carte doit être True ou False")
|
||||||
|
elif lbl == 'compte': self.compte(value)
|
||||||
|
elif re.match('droits_.*', lbl):
|
||||||
|
if value == True: self.droits(droits.append(value[7:]))
|
||||||
|
elif value == False: self.droit(droits.remove(value[7:]))
|
||||||
|
else: raise ValueError(u"les droits_* doivent être True ou False")
|
||||||
|
else: pass
|
||||||
|
|
||||||
class Club(BaseProprietaire):
|
class Club(BaseProprietaire):
|
||||||
u""" Classe de définition d'un club """
|
u""" Classe de définition d'un club """
|
||||||
|
@ -3083,6 +3147,25 @@ Contactez nounou si la MAC est bien celle d'une carte.""", 3)
|
||||||
u"""Retourne un hash de l'objet Machine"""
|
u"""Retourne un hash de l'objet Machine"""
|
||||||
return hash(self.nom())
|
return hash(self.nom())
|
||||||
|
|
||||||
|
################################################################
|
||||||
|
# définintion de __setitem__
|
||||||
|
def __setitem__(self, label, value):
|
||||||
|
CransLdap.__setitem__(self, label, value)
|
||||||
|
|
||||||
|
if lbl == 'mac': self.mac(value)
|
||||||
|
elif lbl == 'host': self.nom(value)
|
||||||
|
elif lbl == 'prise': self.prise(value)
|
||||||
|
elif lbl == 'alias': self.alias(value)
|
||||||
|
elif lbl == 'ip': self.alias(value)
|
||||||
|
elif lbl == 'exempt': self.exempt(value)
|
||||||
|
elif lbl == 'proprio':
|
||||||
|
try:
|
||||||
|
if re.match(r'\([a-zA-Z]=\d+\)', value):
|
||||||
|
proprio = self.search(value)['club'][0]
|
||||||
|
else:
|
||||||
|
proprio = self.search('(aid=%s)' % value
|
||||||
|
|
||||||
|
|
||||||
class MachineFixe(Machine):
|
class MachineFixe(Machine):
|
||||||
u""" Classe de définition d'une machine fixe """
|
u""" Classe de définition d'une machine fixe """
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue