1 #@ MODIF ascheckers Noyau DATE 28/11/2007 AUTEUR COURTOIS M.COURTOIS
2 # -*- coding: iso-8859-1 -*-
3 # CONFIGURATION MANAGEMENT OF EDF VERSION
4 # ======================================================================
5 # COPYRIGHT (C) 1991 - 2007 EDF R&D WWW.CODE-ASTER.ORG
6 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
7 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
8 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
9 # (AT YOUR OPTION) ANY LATER VERSION.
11 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
12 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
13 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
14 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
16 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
17 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
18 # 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
19 # ======================================================================
22 """Classe qui exprime une contrainte multiple pour un attribut"""
23 def __init__(self, *args):
24 self.values = list(args)
26 def add_value(self, value ):
27 if value not in self.values:
28 self.values.append( value )
30 def __call__(self, obj, name, value, log ):
31 if value not in self.values:
32 log.err( obj, "l'attribut %s=%r n'est pas dans %r" % (name, value, self.values) )
36 g = [ repr(v) for v in self.values ]
37 l.append( ", ".join(g) )
41 class CheckLog(object):
42 """Un validateur qui enregistre toutes les erreurs trouvées.
43 checkedXXX répond True si la "marq" courante est inférieure ou égale
44 à la celle de la dernière vérification.
45 Si on incrémentait "marq" à chaque étape, on revérifie à chaque fois.
52 self._lastmarq = self._marq
55 def log(self, level, obj, msg ):
57 self.msg.append( (level, obj.nomj(), msg) )
59 self.msg.append( (level, 'None', msg) )
61 def err(self, obj, msg ):
62 self.log( 0, obj, msg )
64 def warn(self, obj, msg ):
65 self.log( 1, obj, msg )
67 def visitOJB(self, obj):
69 self.names[key] = self._marq
71 def visitAsBase(self, obj):
72 key = (obj.nomj(), obj.__class__.__name__)
73 self.names[key] = self._marq
75 def force(self, force=False):
80 self._marq = self._lastmarq
82 def checkedOJB(self, obj):
84 res = self.names.get(key, 0) >= self._marq
85 self.help_dbg([key,], res)
88 def checkedAsBase(self, obj):
89 key = (obj.nomj(), obj.__class__.__name__)
90 res = self.names.get(key, 0) >= self._marq
91 self.help_dbg(key, res)
94 def help_dbg(self, key, res):
100 print '#DBG %6d %s : %s' % (self._marq, s, ', '.join(key))
103 d = { 0: "E", 1:"W" }
104 return "\n".join( [ "%s:%s: %s" % (d[l],n,m)
105 for l,n,m in self.msg ])
107 class CheckFail(CheckLog):
108 """Un validateur qui lève une exception
109 dès la première erreur"""
110 def err(self, obj, msg ):
111 raise AssertionError("%s: %s" % (obj.nomj(), msg) )