Ajout de l'attribut __slots__ aux classes pour économiser de la ram
This commit is contained in:
parent
61bf832112
commit
d8bac8d47e
5 changed files with 174 additions and 47 deletions
115
objets.py
115
objets.py
|
@ -66,14 +66,6 @@ import cranslib.deprecated
|
|||
|
||||
#: Champs à ignorer dans l'historique
|
||||
HIST_IGNORE_FIELDS = ["modifiersName", "entryCSN", "modifyTimestamp", "historique"]
|
||||
crans_account_attribs = [attributs.uid, attributs.canonicalAlias, attributs.solde,
|
||||
attributs.contourneGreylist, attributs.derniereConnexion,
|
||||
attributs.homepageAlias, attributs.loginShell, attributs.gecos,
|
||||
attributs.uidNumber, attributs.homeDirectory,
|
||||
attributs.gidNumber, attributs.userPassword,
|
||||
attributs.mailAlias, attributs.cn, attributs.rewriteMailHeaders,
|
||||
attributs.mailExt, attributs.compteWiki, attributs.droits,
|
||||
attributs.shadowExpire]
|
||||
|
||||
def new_cransldapobject(conn, dn, mode='ro', uldif=None, lockId=None):
|
||||
"""Crée un objet :py:class:`CransLdapObject` en utilisant la classe correspondant à
|
||||
|
@ -107,6 +99,7 @@ class CransLdapObject(object):
|
|||
Cette classe ne devrait pas être utilisée directement."""
|
||||
|
||||
""" Qui peut faire quoi ? """
|
||||
__slots__ = ("in_context", "conn", "lockId", "attrs", "_modifs", "dn", "parent_dn", "mode")
|
||||
can_be_by = { variables.created: [attributs.nounou],
|
||||
variables.modified: [attributs.nounou],
|
||||
variables.deleted: [attributs.nounou],
|
||||
|
@ -218,9 +211,9 @@ class CransLdapObject(object):
|
|||
# Sortie du context manager
|
||||
self.in_context = False
|
||||
# On rend les écriture impossible
|
||||
self.save = self._out_of_context
|
||||
self.create = self._out_of_context
|
||||
self.delete = self._out_of_context
|
||||
#self.save = self._out_of_context
|
||||
#self.create = self._out_of_context
|
||||
#self.delete = self._out_of_context
|
||||
# On retombe en read only
|
||||
self.mode = 'ro'
|
||||
# On purge les lock de l'objet
|
||||
|
@ -805,6 +798,7 @@ class ObjectFactory(object):
|
|||
Cette classe n'est jamais instanciée.
|
||||
|
||||
"""
|
||||
__slots__ = ()
|
||||
_classes = {}
|
||||
|
||||
@classmethod
|
||||
|
@ -830,6 +824,7 @@ def crans_object(classe):
|
|||
|
||||
@crans_object
|
||||
class InetOrgPerson(CransLdapObject):
|
||||
__slots__ = ()
|
||||
ldap_name = "inetOrgPerson"
|
||||
def __repr__(self):
|
||||
return str(self.__class__.__name__) + " : cn=" + str(self['cn'][0])
|
||||
|
@ -837,16 +832,33 @@ class InetOrgPerson(CransLdapObject):
|
|||
|
||||
class proprio(CransLdapObject):
|
||||
u""" Un propriétaire de machine (adhérent, club…) """
|
||||
__slots__ = ("_machines", "_factures", "full")
|
||||
can_be_by = { variables.created: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
variables.modified: [attributs.nounou, attributs.bureau, attributs.soi, attributs.cableur],
|
||||
variables.deleted: [attributs.nounou, attributs.bureau,],
|
||||
}
|
||||
|
||||
attribs = [attributs.nom, attributs.chbre, attributs.paiement, attributs.info,
|
||||
|
||||
crans_account_attribs = [attributs.uid, attributs.canonicalAlias, attributs.solde,
|
||||
attributs.contourneGreylist, attributs.derniereConnexion,
|
||||
attributs.homepageAlias, attributs.loginShell, attributs.gecos,
|
||||
attributs.uidNumber, attributs.homeDirectory,
|
||||
attributs.gidNumber, attributs.userPassword,
|
||||
attributs.mailAlias, attributs.cn, attributs.rewriteMailHeaders,
|
||||
attributs.mailExt, attributs.compteWiki, attributs.droits,
|
||||
attributs.shadowExpire]
|
||||
default_attribs = [attributs.nom, attributs.chbre, attributs.paiement, attributs.info,
|
||||
attributs.blacklist, attributs.controle, attributs.historique,
|
||||
attributs.debutAdhesion, attributs.finAdhesion, attributs.debutConnexion,
|
||||
attributs.finConnexion]
|
||||
|
||||
@property
|
||||
def attribs(self):
|
||||
if u'cransAccount' in self['objectClass']:
|
||||
return self.default_attribs + self.crans_account_attribs
|
||||
else:
|
||||
return self.default_attribs
|
||||
|
||||
def __repr__(self):
|
||||
return str(self.__class__.__name__) + " : nom=" + str(self['nom'][0])
|
||||
|
||||
|
@ -854,9 +866,6 @@ class proprio(CransLdapObject):
|
|||
super(proprio, self).__init__(*args, **kwargs)
|
||||
self._machines = None
|
||||
self._factures = None
|
||||
if u'cransAccount' in self['objectClass']:
|
||||
self.attribs = self.attribs + crans_account_attribs
|
||||
self.full = True
|
||||
|
||||
def delete_compte(self, mail):
|
||||
# Je pense qu'en pratique cette vérification ne sert à rien puisqu'on se fera jetter à la tentative de modification
|
||||
|
@ -880,7 +889,6 @@ class proprio(CransLdapObject):
|
|||
self['mailExt']=[]
|
||||
self['uid' ]=[]
|
||||
self._modifs['objectClass'] = [u'adherent']
|
||||
self.attribs = list(set(self.attribs).difference(crans_account_attribs))
|
||||
self.full = False
|
||||
|
||||
|
||||
|
@ -907,9 +915,6 @@ class proprio(CransLdapObject):
|
|||
if os.path.exists("/var/mail/" + login):
|
||||
raise ValueError('Création du compte impossible : /var/mail/%s existant' % str(login))
|
||||
|
||||
if not self.full:
|
||||
self.attribs = self.attribs + crans_account_attribs
|
||||
self.full = True
|
||||
self['uid' ] = [login]
|
||||
self['homeDirectory'] = [home]
|
||||
self['mail'] = [login + u"@crans.org"]
|
||||
|
@ -1094,6 +1099,7 @@ class proprio(CransLdapObject):
|
|||
|
||||
class machine(CransLdapObject):
|
||||
u""" Une machine """
|
||||
__slots__ = ("_proprio", "_certificats")
|
||||
can_be_by = { variables.created: [attributs.nounou, attributs.bureau, attributs.cableur, attributs.parent, attributs.respo],
|
||||
variables.modified: [attributs.nounou, attributs.bureau, attributs.cableur, attributs.parent, attributs.respo],
|
||||
variables.deleted: [attributs.nounou, attributs.bureau, attributs.cableur, attributs.parent, attributs.respo],
|
||||
|
@ -1272,6 +1278,7 @@ class machine(CransLdapObject):
|
|||
|
||||
class AssociationCrans(proprio):
|
||||
""" Association crans (propriétaire particulier)."""
|
||||
__slots__ = ()
|
||||
def save(self):
|
||||
pass
|
||||
|
||||
|
@ -1284,18 +1291,22 @@ class AssociationCrans(proprio):
|
|||
return str(self.__class__.__name__) + " : Le Crans"
|
||||
|
||||
class BaseInvites(proprio):
|
||||
u"""Un artefact de la base ldap"""
|
||||
u"""Un artefact de la base ldap"""
|
||||
__slots__ = ()
|
||||
def __repr__(self):
|
||||
return str(self.__class__.__name__)
|
||||
|
||||
def __repr__(self):
|
||||
return str(self.__class__.__name__)
|
||||
|
||||
def delete(self, comm, login):
|
||||
def delete(self, comm, login):
|
||||
raise EnvironmentError("Les pauvres invites")
|
||||
|
||||
@crans_object
|
||||
class adherent(proprio):
|
||||
u"""Adhérent crans."""
|
||||
attribs = proprio.attribs + [attributs.aid, attributs.prenom, attributs.tel,
|
||||
__slots__ = ("_clubs", "_imprimeur_clubs")
|
||||
|
||||
@property
|
||||
def attribs(self):
|
||||
return super(adherent, self).attribs + [attributs.aid, attributs.prenom, attributs.tel,
|
||||
attributs.mail, attributs.mailInvalide, attributs.charteMA,
|
||||
attributs.derniereConnexion, attributs.gpgFingerprint,
|
||||
attributs.carteEtudiant, attributs.etudes,
|
||||
|
@ -1334,23 +1345,32 @@ class adherent(proprio):
|
|||
@crans_object
|
||||
class club(proprio):
|
||||
u"""Club crans"""
|
||||
__slots__ = ()
|
||||
can_be_by = { variables.created: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
variables.modified: [attributs.nounou, attributs.bureau, attributs.respo, attributs.cableur],
|
||||
variables.deleted: [attributs.nounou, attributs.bureau],
|
||||
}
|
||||
attribs = proprio.attribs + [attributs.cid, attributs.responsable, attributs.imprimeurClub]
|
||||
ldap_name = "club"
|
||||
|
||||
@property
|
||||
def attribs(self):
|
||||
return super(club, self).attribs + [attributs.cid, attributs.responsable, attributs.imprimeurClub]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(club, self).__init__(*args, **kwargs)
|
||||
|
||||
def __repr__(self):
|
||||
return "Club : " + str(self['nom'][0])
|
||||
|
||||
@crans_object
|
||||
class machineFixe(machine):
|
||||
u"""Machine fixe"""
|
||||
__slots__ = ()
|
||||
ldap_name = "machineFixe"
|
||||
|
||||
class machineMulticast(machine):
|
||||
u"""Machine pour inféré à partir des announces sap"""
|
||||
__slots__ = ()
|
||||
ldap_name = None
|
||||
def save(self):
|
||||
pass
|
||||
|
@ -1368,6 +1388,7 @@ class machineMulticast(machine):
|
|||
@crans_object
|
||||
class machineWifi(machine):
|
||||
u"""Machine wifi"""
|
||||
__slots__ = ()
|
||||
attribs = machine.attribs + [attributs.ipsec]
|
||||
ldap_name = "machineWifi"
|
||||
|
||||
|
@ -1388,6 +1409,7 @@ class machineWifi(machine):
|
|||
|
||||
@crans_object
|
||||
class machineCrans(machine):
|
||||
__slots__ = ()
|
||||
can_be_by = { variables.created: [attributs.nounou],
|
||||
variables.modified: [attributs.nounou],
|
||||
variables.deleted: [attributs.nounou],
|
||||
|
@ -1397,6 +1419,7 @@ class machineCrans(machine):
|
|||
|
||||
@crans_object
|
||||
class borneWifi(machine):
|
||||
__slots__ = ()
|
||||
can_be_by = { variables.created: [attributs.nounou],
|
||||
variables.modified: [attributs.nounou],
|
||||
variables.deleted: [attributs.nounou],
|
||||
|
@ -1407,6 +1430,7 @@ class borneWifi(machine):
|
|||
|
||||
@crans_object
|
||||
class switchCrans(machine):
|
||||
__slots__ = ()
|
||||
can_be_by = { variables.created: [attributs.nounou],
|
||||
variables.modified: [attributs.nounou],
|
||||
variables.deleted: [attributs.nounou],
|
||||
|
@ -1417,6 +1441,7 @@ class switchCrans(machine):
|
|||
|
||||
@crans_object
|
||||
class facture(CransLdapObject):
|
||||
__slots__ = ("_proprio", "_has_frais", "_recuPaiement", "_article_frais")
|
||||
can_be_by = { variables.created: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
variables.modified: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
variables.deleted: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
|
@ -1427,16 +1452,16 @@ class facture(CransLdapObject):
|
|||
attributs.finConnexion, attributs.controle ]
|
||||
ldap_name = "facture"
|
||||
|
||||
_proprio = None
|
||||
|
||||
def __repr__(self):
|
||||
return str(self.__class__.__name__) + " : fid=" + str(self['fid'][0])
|
||||
|
||||
#### GROS HACK pour rester comptatible avec ldap_crans où l'article representant les frais n'est ajouté qu'une fois le paiement reçu
|
||||
def __init__(self, *args, **kwargs):
|
||||
self._proprio = None
|
||||
super(facture, self).__init__(*args, **kwargs)
|
||||
self._has_frais = True if [art for art in self.attrs.get('article', []) if art['code'] != 'FRAIS'] else False
|
||||
self._recuPaiement = True if self['recuPaiement'] else False
|
||||
self._article_frais = None
|
||||
|
||||
def __getitem__(self,attr, default=None):
|
||||
ret = super(facture, self).__getitem__(attr, default)
|
||||
|
@ -1451,7 +1476,6 @@ class facture(CransLdapObject):
|
|||
raise EnvironmentError("Paiement déjà effectué pour cette facture, impossible de modifier son contenu")
|
||||
return super(facture, self).__setitem__(attr, value)
|
||||
|
||||
_article_frais = None
|
||||
def _frais(self, mode=None):
|
||||
if mode is None:
|
||||
mode = self['modePaiement'][0]
|
||||
|
@ -1536,11 +1560,12 @@ class facture(CransLdapObject):
|
|||
|
||||
@crans_object
|
||||
class baseCert(CransLdapObject):
|
||||
__slots__ = ("_machine",)
|
||||
can_be_by = { variables.created: [attributs.nounou, attributs.bureau, attributs.parent],
|
||||
variables.modified: [attributs.nounou, attributs.bureau, attributs.parent],
|
||||
variables.deleted: [attributs.nounou, attributs.bureau, attributs.parent],
|
||||
}
|
||||
attribs = [ attributs.xid, attributs.certificat, attributs.hostCert, attributs.historique,
|
||||
default_attribs = [ attributs.xid, attributs.certificat, attributs.hostCert, attributs.historique,
|
||||
attributs.info, attributs.csr ]
|
||||
|
||||
tlsa_attribs = [ attributs.certificatUsage, attributs.selector, attributs.matchingType,
|
||||
|
@ -1550,11 +1575,24 @@ class baseCert(CransLdapObject):
|
|||
|
||||
private_attribs = [ attributs.privatekey, attributs.encrypted ]
|
||||
|
||||
@property
|
||||
def attribs(self):
|
||||
attribs = list(self.default_attribs)
|
||||
if "TLSACert" in self['objectClass']:
|
||||
attribs.extend(self.tlsa_attribs)
|
||||
if 'x509Cert' in self['objectClass']:
|
||||
attribs.extend(self.x509_attribs)
|
||||
if "privateKey" in self['objectClass']:
|
||||
attribs.extend(self.private_attribs)
|
||||
return attribs
|
||||
ldap_name = "baseCert"
|
||||
|
||||
protected_issuer = [u'CAcert Class 3 Root', u'CA Cert Signing Authority']
|
||||
|
||||
_machine = None
|
||||
def __init__(self, *args, **kwargs):
|
||||
self._machine = None
|
||||
super(baseCert, self).__init__(*args, **kwargs)
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
if self['info']:
|
||||
|
@ -1562,14 +1600,6 @@ class baseCert(CransLdapObject):
|
|||
else:
|
||||
return "Certificat : xid=" + str(self['xid'][0])
|
||||
|
||||
def update_attribs(self):
|
||||
if "TLSACert" in self['objectClass']:
|
||||
self.attribs.extend(self.tlsa_attribs)
|
||||
if 'x509Cert' in self['objectClass']:
|
||||
self.attribs.extend(self.x509_attribs)
|
||||
if "privateKey" in self['objectClass']:
|
||||
self.attribs.extend(self.private_attribs)
|
||||
|
||||
def _check_setitem(self, attr, values):
|
||||
"""
|
||||
Vérifie des contraintes non liées à LDAP lors d'un __setitem__,
|
||||
|
@ -1589,7 +1619,7 @@ class baseCert(CransLdapObject):
|
|||
if u"privateKey" in self['objectClass']:
|
||||
return
|
||||
self._modifs['objectClass'].append(u"privateKey")
|
||||
self.attribs.extend(self.private_attribs)
|
||||
#self.attribs.extend(self.private_attribs)
|
||||
self['encrypted']=encrypted
|
||||
self['privatekey']=privatekey
|
||||
|
||||
|
@ -1599,7 +1629,7 @@ class baseCert(CransLdapObject):
|
|||
if u"TLSACert" in self['objectClass']:
|
||||
return
|
||||
self._modifs['objectClass'].append(u"TLSACert")
|
||||
self.attribs.extend(self.tlsa_attribs)
|
||||
#self.attribs.extend(self.tlsa_attribs)
|
||||
self['certificatUsage']=certificatUsage
|
||||
self['matchingType']=matchingType
|
||||
self['selector']=0
|
||||
|
@ -1610,7 +1640,7 @@ class baseCert(CransLdapObject):
|
|||
if u"x509Cert" in self['objectClass']:
|
||||
return
|
||||
self._modifs['objectClass'].append(u"x509Cert")
|
||||
self.attribs.extend(self.x509_attribs)
|
||||
#self.attribs.extend(self.x509_attribs)
|
||||
self['issuerCN'] = issuerCN
|
||||
self['start'] = start
|
||||
self['end'] = end
|
||||
|
@ -1639,6 +1669,7 @@ class baseCert(CransLdapObject):
|
|||
|
||||
@crans_object
|
||||
class service(CransLdapObject):
|
||||
__slots__ = ()
|
||||
ldap_name = "service"
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue