Ajout de l'attribut __slots__ aux classes pour économiser de la ram

This commit is contained in:
Valentin Samir 2014-11-22 22:01:42 +01:00
parent 61bf832112
commit d8bac8d47e
5 changed files with 174 additions and 47 deletions

View file

@ -196,6 +196,7 @@ class AttrsList(list):
self._commit()
class AttrsDict(dict):
__slots__ = ("_conn", "_parent", "_iterator")
def __init__(self, conn, uldif={}, Parent=None):
super(AttrsDict, self).__init__(uldif)
self._conn = conn
@ -250,10 +251,10 @@ class Attr(object):
* ``val`` : valeur de l'attribut
* ``ldif`` : objet contenant l'attribut (permet de faire les validations sur l'environnement)
"""
__slots__ = ("value", "conn", "parent")
legend = "Human-readable description of attribute"
singlevalue = False
optional = True
conn = None
unique = False
concurrent = True
historique = "full" # valeurs possibles "full", "partial", "info", None
@ -386,6 +387,7 @@ def crans_attribute(classe):
@crans_attribute
class objectClass(Attr):
__slots__ = ()
singlevalue = False
optional = False
legend = "entité"
@ -408,7 +410,7 @@ class objectClass(Attr):
class intAttr(Attr):
__slots__ = ()
python_type = int
def __add__(self, obj):
@ -432,7 +434,7 @@ class intAttr(Attr):
return unicode(self.value)
class floatAttr(Attr):
__slots__ = ()
python_type = float
def __add__(self, obj):
@ -454,7 +456,7 @@ class floatAttr(Attr):
return unicode(self.value)
class boolAttr(Attr):
__slots__ = ()
python_type = bool
def parse_value(self, val):
@ -472,6 +474,7 @@ class boolAttr(Attr):
@crans_attribute
class aid(intAttr):
__slots__ = ()
singlevalue = True
optional = True
legend = u"Identifiant de l'adhérent"
@ -489,6 +492,7 @@ class aid(intAttr):
@crans_attribute
class uid(Attr):
__slots__ = ()
singlevalue = True
option = False
legend = u"L'identifiant canonique de l'adhérent"
@ -499,6 +503,7 @@ class uid(Attr):
@crans_attribute
class preferedLanguage(Attr):
__slots__ = ()
singlevalue = True
option = True
legend = u"La langue préférée de l'adhérent"
@ -508,6 +513,7 @@ class preferedLanguage(Attr):
@crans_attribute
class nom(Attr):
__slots__ = ()
singlevalue = True
optional = False
legend = "Nom"
@ -526,6 +532,7 @@ class nom(Attr):
@crans_attribute
class prenom(Attr):
__slots__ = ()
singlevalue = True
optional = False
legend = u"Prénom"
@ -538,6 +545,7 @@ class prenom(Attr):
@crans_attribute
class compteWiki(Attr):
__slots__ = ()
singlevalue = False
optional = True
legend = u"Compte WiKi"
@ -551,6 +559,7 @@ class compteWiki(Attr):
@crans_attribute
class tel(Attr):
__slots__ = ()
singlevalue = True
optional = False
legend = u"Téléphone"
@ -564,6 +573,7 @@ class tel(Attr):
raise ValueError("Numéro de téléphone invalide (%r)" % tel)
class yearAttr(intAttr):
__slots__ = ()
singlevalue = False
optional = True
@ -575,6 +585,7 @@ class yearAttr(intAttr):
@crans_attribute
class paiement(yearAttr):
__slots__ = ()
legend = u"Paiement"
can_modify = [cableur, nounou, tresorier]
category = 'perso'
@ -582,6 +593,7 @@ class paiement(yearAttr):
@crans_attribute
class carteEtudiant(Attr):
__slots__ = ()
legend = u"Carte d'étudiant"
category = 'perso'
can_modify = [cableur, nounou, tresorier]
@ -592,6 +604,7 @@ class carteEtudiant(Attr):
@crans_attribute
class derniereConnexion(intAttr):
__slots__ = ()
legend = u"Dernière connexion"
can_modify = [nounou, cableur, soi] # il faut bien pouvoir le modifier pour le mettre à jour
ldap_name = "derniereConnexion"
@ -601,6 +614,7 @@ class generalizedTimeFormat(Attr):
une donnée de temps suivant la RFC 4517
"""
__slots__ = ("_stamp",)
default = "19700101000000Z"
def __float__(self):
@ -649,6 +663,7 @@ class generalizedTimeFormat(Attr):
@crans_attribute
class debutAdhesion(generalizedTimeFormat):
__slots__ = ()
legend = u"Date de début de l'adhésion"
category = 'Adh'
can_modify = [cableur, nounou]
@ -657,6 +672,7 @@ class debutAdhesion(generalizedTimeFormat):
@crans_attribute
class finAdhesion(generalizedTimeFormat):
__slots__ = ()
legend = u"Date de fin de l'adhésion"
category = 'Adh'
can_modify = [cableur, nounou]
@ -664,6 +680,7 @@ class finAdhesion(generalizedTimeFormat):
@crans_attribute
class debutConnexion(generalizedTimeFormat):
__slots__ = ()
legend = u"Date de début de la connexion"
category = 'Adh'
can_modify = [cableur, nounou]
@ -671,6 +688,7 @@ class debutConnexion(generalizedTimeFormat):
@crans_attribute
class finConnexion(generalizedTimeFormat):
__slots__ = ()
legend = u"Date de fin de la connexion"
category = 'Adh'
can_modify = [cableur, nounou]
@ -678,6 +696,7 @@ class finConnexion(generalizedTimeFormat):
@crans_attribute
class mail(Attr):
__slots__ = ()
singlevalue = False
optional = False
unique = True
@ -733,6 +752,7 @@ class mail(Attr):
@crans_attribute
class canonicalAlias(mail):
__slots__ = ()
singlevalue = True
optional = True
unique = True
@ -747,6 +767,7 @@ class canonicalAlias(mail):
@crans_attribute
class mailAlias(mail):
__slots__ = ()
singlevalue = False
optional = True
unique = True
@ -757,6 +778,7 @@ class mailAlias(mail):
@crans_attribute
class mailExt(mail):
__slots__ = ()
singlevalue = False
optional = True
unique = True
@ -774,6 +796,7 @@ class mailExt(mail):
@crans_attribute
class mailInvalide(boolAttr):
__slots__ = ()
optional = True
legend = u"Mail invalide"
can_modify = [bureau, nounou]
@ -781,6 +804,7 @@ class mailInvalide(boolAttr):
@crans_attribute
class contourneGreylist(boolAttr):
__slots__ = ()
optionnal = True
legend = u"Contourner la greylist"
category = 'mail'
@ -792,6 +816,7 @@ class contourneGreylist(boolAttr):
@crans_attribute
class etudes(Attr):
__slots__ = ()
singlevalue = False
optional = True
legend = u"Études"
@ -801,6 +826,7 @@ class etudes(Attr):
@crans_attribute
class chbre(Attr):
__slots__ = ()
singlevalue = True
optional = False
unique = True
@ -824,6 +850,7 @@ class chbre(Attr):
@crans_attribute
class droits(Attr):
__slots__ = ()
singlevalue = False
optional = True
legend = u"Droits sur les serveurs"
@ -851,6 +878,7 @@ class droits(Attr):
@crans_attribute
class solde(floatAttr):
__slots__ = ()
python_type = float
singlevalue = True
concurrent = False
@ -869,6 +897,7 @@ class solde(floatAttr):
return u"%.2f" % self.value
class dnsAttr(Attr):
__slots__ = ()
category = 'dns'
ldap_name = "dnsAttr"
python_type = unicode
@ -883,6 +912,7 @@ class dnsAttr(Attr):
@crans_attribute
class host(dnsAttr):
__slots__ = ()
singlevalue = True
unique = True
optional = False
@ -902,6 +932,7 @@ class host(dnsAttr):
@crans_attribute
class hostAlias(host):
__slots__ = ()
singlevalue = False
unique = True
optional = True
@ -911,6 +942,7 @@ class hostAlias(host):
@crans_attribute
class macAddress(Attr):
__slots__ = ()
singlevalue = True
optional = False
legend = u"Adresse physique de la carte réseau"
@ -933,6 +965,7 @@ class macAddress(Attr):
@crans_attribute
class ipHostNumber(Attr):
__slots__ = ()
singlevalue = True
optional = True
unique = True
@ -954,6 +987,7 @@ class ipHostNumber(Attr):
@crans_attribute
class ip6HostNumber(Attr):
__slots__ = ()
singlevalue = True
optional = True
unique = True
@ -977,6 +1011,7 @@ class ip6HostNumber(Attr):
@crans_attribute
class mid(intAttr):
__slots__ = ()
singlevalue = True
optional = False
unique = True
@ -986,6 +1021,7 @@ class mid(intAttr):
@crans_attribute
class rid(intAttr):
__slots__ = ()
singlevalue = True
optional = True
unique = True
@ -1017,6 +1053,7 @@ class rid(intAttr):
@crans_attribute
class ipsec(Attr):
__slots__ = ()
singlevalue = False
optional = True
legend = u'Clef wifi'
@ -1036,6 +1073,7 @@ class ipsec(Attr):
@crans_attribute
class puissance(Attr):
__slots__ = ()
singlevalue = True
optional = True
legend = u"puissance d'émission pour les bornes wifi"
@ -1045,6 +1083,7 @@ class puissance(Attr):
@crans_attribute
class canal(intAttr):
__slots__ = ()
singlevalue = True
optional = True
legend = u'Canal d\'émission de la borne'
@ -1054,6 +1093,7 @@ class canal(intAttr):
@crans_attribute
class hotspot(boolAttr):
__slots__ = ()
singlevalue = True
optional = True
legend = u'Hotspot'
@ -1063,6 +1103,7 @@ class hotspot(boolAttr):
@crans_attribute
class positionBorne(Attr):
__slots__ = ()
legend = u"Position de la borne"
category = "wifi"
can_modify = [nounou]
@ -1072,12 +1113,14 @@ class positionBorne(Attr):
@crans_attribute
class nvram(Attr):
__slots__ = ()
legend = u"Configuration speciale"
optional = True
can_modify = [nounou]
ldap_name = "nvram"
class portAttr(Attr):
__slots__ = ()
singlevalue = False
optional = True
legend = u'Ouverture de port'
@ -1114,26 +1157,31 @@ class portAttr(Attr):
@crans_attribute
class portTCPout(portAttr):
__slots__ = ()
legend = u"Port TCP ouvert vers l'extérieur"
ldap_name = "portTCPout"
@crans_attribute
class portTCPin(portAttr):
__slots__ = ()
legend = u"Port TCP ouvert depuis l'extérieur"
ldap_name = "portTCPin"
@crans_attribute
class portUDPout(portAttr):
__slots__ = ()
legend = u"Port UDP ouvert vers l'extérieur"
ldap_name = "portUDPout"
@crans_attribute
class portUDPin(portAttr):
__slots__ = ()
legend = u"Port UDP ouvert depuis l'extérieur"
ldap_name = "portUDPin"
@crans_attribute
class exempt(Attr):
__slots__ = ()
legend = u"Exemption vers une IP"
ldap_name = "exempt"
python_type = netaddr.IPNetwork
@ -1147,6 +1195,7 @@ class exempt(Attr):
@crans_attribute
class nombrePrises(intAttr):
__slots__ = ()
legend = u"Nombre de prises ethernet de la machine"
singlevalue = True
optional = True
@ -1156,6 +1205,7 @@ class nombrePrises(intAttr):
@crans_attribute
class prise(Attr):
__slots__ = ()
singlevalue = True
optional = True
legend = u"Prise sur laquelle est branchée la machine"
@ -1165,6 +1215,7 @@ class prise(Attr):
@crans_attribute
class cid(intAttr):
__slots__ = ()
singlevalue = True
optional = True
unique = True
@ -1177,6 +1228,7 @@ class cid(intAttr):
@crans_attribute
class responsable(Attr):
__slots__ = ('__value', '_value')
singlevalue = True
optional = True
legend = u"Responsable du club"
@ -1222,6 +1274,7 @@ class responsable(Attr):
@crans_attribute
class imprimeurClub(Attr):
__slots__ = ("__value", "_value")
optional = True
legend = u"Imprimeur du club"
category = "perso"
@ -1262,6 +1315,7 @@ class imprimeurClub(Attr):
@crans_attribute
class blacklist(Attr):
__slots__ = ()
singlevalue = False
optional = True
legend = u"Blackliste"
@ -1314,7 +1368,7 @@ class blacklist(Attr):
@crans_attribute
class historique(Attr):
"""Un historique est usuellement de la forme JJ/MM/AAAA HH:mm:ss, action comm"""
__slots__ = ()
singlevalue = False
concurrent = False
optional = True
@ -1339,6 +1393,7 @@ class historique(Attr):
@crans_attribute
class info(Attr):
__slots__ = ()
singlevalue = False
optional = True
legend = u"Quelques informations"
@ -1349,6 +1404,7 @@ class info(Attr):
@crans_attribute
class homepageAlias(Attr):
__slots__ = ()
singlevalue = True
optional = True
legend = u'Un alias pour la page personnelle'
@ -1358,6 +1414,7 @@ class homepageAlias(Attr):
@crans_attribute
class charteMA(boolAttr):
__slots__ = ()
singlevalue = True
optional = True
legend= "Signale si l'adhérent a signé la charte de membres actifs"
@ -1367,6 +1424,7 @@ class charteMA(boolAttr):
@crans_attribute
class homeDirectory(Attr):
__slots__ = ()
singlevalue=True
optional = True
unique = True
@ -1392,6 +1450,7 @@ class homeDirectory(Attr):
@crans_attribute
class loginShell(Attr):
__slots__ = ()
singlevalue = True
optional = True
legend = "Le shell de l'adherent"
@ -1408,6 +1467,7 @@ class loginShell(Attr):
@crans_attribute
class uidNumber(intAttr):
__slots__ = ()
singlevalue = True
optional = True
unique = True
@ -1417,6 +1477,7 @@ class uidNumber(intAttr):
@crans_attribute
class gidNumber(intAttr):
__slots__ = ()
singlevalue = True
optional = True
legend = "Le gid du compte de l'adhérent"
@ -1425,6 +1486,7 @@ class gidNumber(intAttr):
@crans_attribute
class gecos(Attr):
__slots__ = ()
singlevalue = True
optional = True
legend = "Le gecos"
@ -1433,6 +1495,7 @@ class gecos(Attr):
@crans_attribute
class userPassword(Attr):
__slots__ = ()
singlevalue = True
optional = True
legend = "Le mot de passe"
@ -1459,6 +1522,7 @@ class userPassword(Attr):
@crans_attribute
class sshFingerprint(Attr):
__slots__ = ()
singlevalue = False
optional = True
legend = "Clef ssh de la machine"
@ -1506,6 +1570,7 @@ class sshFingerprint(Attr):
@crans_attribute
class gpgFingerprint(Attr):
__slots__ = ()
singlevalue = False
optional = True
unique = True
@ -1517,6 +1582,7 @@ class gpgFingerprint(Attr):
class gpgMail(mail):
"""Attribut servant à stocker un mail allant de paire avec
l'un des uid dans la clef gpg pointée par gpgFingerprint"""
__slots__ = ()
singlevalue = False
optional = True
unique = True
@ -1532,6 +1598,7 @@ class gpgMail(mail):
@crans_attribute
class cn(Attr):
__slots__ = ()
singlevalue = True
optional = False
category = 'id'
@ -1539,6 +1606,7 @@ class cn(Attr):
@crans_attribute
class dn(Attr):
__slots__ = ()
singlevalue = True
optional = False
unique = True
@ -1547,6 +1615,7 @@ class dn(Attr):
@crans_attribute
class postalAddress(Attr):
__slots__ = ()
singlevalue = False
optional = True
can_modify = [soi, cableur, nounou, bureau]
@ -1556,6 +1625,7 @@ class postalAddress(Attr):
@crans_attribute
class controle(Attr):
__slots__ = ()
singlevalue = True
optional = True
legend = u"Contrôle"
@ -1570,6 +1640,7 @@ class controle(Attr):
@crans_attribute
class fid(intAttr):
__slots__ = ()
legend = u"Id de facture"
category = 'factures'
optional = False
@ -1578,6 +1649,7 @@ class fid(intAttr):
@crans_attribute
class modePaiement(Attr):
__slots__ = ()
legend = u"Mode de paiement"
category = 'factures'
optional = False
@ -1592,11 +1664,13 @@ class modePaiement(Attr):
@crans_attribute
class recuPaiement(Attr):
__slots__ = ()
ldap_name = "recuPaiement"
can_modify = [cableur, nounou]
@crans_attribute
class article(Attr):
__slots__ = ()
singlevalue = False
optional = True
legend = u"Articles"
@ -1640,26 +1714,31 @@ class article(Attr):
@crans_attribute
class dnsIpv6(boolAttr):
__slots__ = ()
ldap_name = "dnsIpv6"
legend = "Détermine si l'ipv6 apparait dans le dns"
can_modify = [nounou, parent, cableur]
@crans_attribute
class rewriteMailHeaders(boolAttr):
__slots__ = ()
ldap_name = "rewriteMailHeaders"
@crans_attribute
class machineAlias(boolAttr):
__slots__ = ()
ldap_name = "machineAlias"
@crans_attribute
class issuerCN(Attr):
__slots__ = ()
ldap_name = "issuerCN"
can_modify = [nounou]
legend = "Common Name de l'éméteur du certificat"
@crans_attribute
class serialNumber(Attr):
__slots__ = ()
ldap_name = "serialNumber"
python_type = int
can_modify = [nounou]
@ -1667,18 +1746,21 @@ class serialNumber(Attr):
@crans_attribute
class start(intAttr):
__slots__ = ()
ldap_name = "start"
can_modify = [nounou]
legend = "Date de début"
@crans_attribute
class end(intAttr):
__slots__ = ()
ldap_name = "end"
can_modify = [nounou]
legend = "Date de fin"
@crans_attribute
class crlUrl(Attr):
__slots__ = ()
ldap_name = "crlUrl"
optional = True
can_modify = [parent, nounou]
@ -1686,6 +1768,7 @@ class crlUrl(Attr):
@crans_attribute
class revocked(boolAttr):
__slots__ = ()
ldap_name = "revocked"
singlevalue = True
optional = True
@ -1694,6 +1777,7 @@ class revocked(boolAttr):
@crans_attribute
class encrypted(boolAttr):
__slots__ = ()
ldap_name = "encrypted"
singlevalue = True
optional = True
@ -1702,6 +1786,7 @@ class encrypted(boolAttr):
@crans_attribute
class privatekey(Attr):
__slots__ = ()
ldap_name = "privatekey"
python_type = str
can_modify = [parent, nounou]
@ -1710,6 +1795,7 @@ class privatekey(Attr):
@crans_attribute
class csr(Attr):
__slots__ = ("data",)
ldap_name = "csr"
python_type = str
can_modify = [parent, nounou]
@ -1739,6 +1825,7 @@ class csr(Attr):
@crans_attribute
class certificat(Attr):
__slots__ = ("data",)
ldap_name = "certificat"
binary = True
python_type = str
@ -1799,6 +1886,7 @@ class certificat(Attr):
@crans_attribute
class certificatUsage(intAttr):
__slots__ = ()
ldap_name = "certificatUsage"
singlevalue = True
can_modify = [parent, nounou]
@ -1806,6 +1894,7 @@ class certificatUsage(intAttr):
@crans_attribute
class selector(intAttr):
__slots__ = ()
ldap_name = "selector"
singlevalue = True
can_modify = [parent, nounou]
@ -1813,6 +1902,7 @@ class selector(intAttr):
@crans_attribute
class matchingType(intAttr):
__slots__ = ()
ldap_name = "matchingType"
singlevalue = True
can_modify = [parent, nounou]
@ -1820,6 +1910,7 @@ class matchingType(intAttr):
@crans_attribute
class xid(intAttr):
__slots__ = ()
ldap_name = "xid"
category = 'id'
unique = True
@ -1830,6 +1921,7 @@ class xid(intAttr):
@crans_attribute
class hostCert(dnsAttr):
__slots__ = ()
optional = False
can_modify = [parent, nounou]
ldap_name = "hostCert"
@ -1850,6 +1942,7 @@ class shadowExpire(intAttr):
Durée de validité du mot de passe d'un compte.
On l'utilise en mettant sa valeur à 0 pour désactiver un compte
"""
__slots__ = ()
optinal = True
can_modify = [nounou, bureau]
ldap_name = "shadowExpire"