-#@ MODIF asojb Noyau DATE 28/06/2011 AUTEUR COURTOIS M.COURTOIS
-# -*- coding: iso-8859-1 -*-
-# RESPONSABLE COURTOIS M.COURTOIS
-# CONFIGURATION MANAGEMENT OF EDF VERSION
+# coding=utf-8
+# person_in_charge: mathieu.courtois at edf.fr
# ======================================================================
-# COPYRIGHT (C) 1991 - 2011 EDF R&D WWW.CODE-ASTER.ORG
+# COPYRIGHT (C) 1991 - 2015 EDF R&D WWW.CODE-ASTER.ORG
# THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
# IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
# THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
from basetype import Type
from asnom import SDNom
from ascheckers import CheckLog
-import traceback,sys
+import traceback
+import sys
# pour utilisation dans eficas
try:
- import aster
- from Utilitai.Utmess import UTMESS
+ import aster
+ from Utilitai.Utmess import UTMESS
except:
- pass
+ pass
# -----------------------------------------------------------------------------
+
+
class AsBase(Type):
nomj = SDNom()
optional = False
- def __init__(self, nomj=None, *args, **kwargs ):
- super(AsBase,self).__init__( nomj, *args, **kwargs )
+ def __init__(self, nomj=None, *args, **kwargs):
+ super(AsBase, self).__init__(nomj, *args, **kwargs)
assert self.nomj is not self.__class__.nomj
- if isinstance( nomj, str ):
+ if isinstance(nomj, str):
self.nomj.nomj = nomj
- elif isinstance( nomj, SDNom ):
- self.nomj.update( nomj.__getstate__() )
+ elif isinstance(nomj, SDNom):
+ self.nomj.update(nomj.__getstate__())
def set_name(self, nomj):
"""Positionne le nomj de self
"""
- assert isinstance( self.nomj.nomj, str ), "uniquement pour les concepts"
+ assert isinstance(self.nomj.nomj, str), "uniquement pour les concepts"
self.nomj.nomj = nomj
def check(self, checker=None):
if checker is None:
checker = CheckLog()
- # vérif déjà faite ? (en tenant compte du type)
+ # vérif déjà faite ? (en tenant compte du type)
if checker.checkedAsBase(self):
return checker
- checker.visitAsBase( self )
+ checker.visitAsBase(self)
- # vérifie les enfants :
+ # vérifie les enfants :
optional = checker.optional
checker.optional = checker.optional or self.optional
for name in self._subtypes:
v = getattr(self, name)
- if isinstance( v, (OJB,AsBase) ):
+ if isinstance(v, (OJB, AsBase)):
v.check(checker)
for name in dir(self):
- if name.startswith( 'check_' ):
+ if name.startswith('check_'):
v = getattr(self, name)
if callable(v):
- try :
- v( checker )
- except :
- mess=60*'-'+'\n'
- mess=mess+'Erreur SDVERI (Attention : vérification incomplète)'+'\n'
- mess=mess.join(traceback.format_tb(sys.exc_traceback))
- checker.err(self,mess)
+ try:
+ v(checker)
+ except:
+ mess = 60 * '-' + '\n'
+ mess = mess + \
+ 'Erreur SDVERI (Attention : vérification incomplète)' + \
+ '\n'
+ mess = mess.join(
+ traceback.format_tb(sys.exc_traceback))
+ checker.err(self, mess)
checker.optional = optional
return checker
- def members( self ):
- pass
-
def dump(self, indent=""):
import pydoc
l = []
f = "(f)"
else:
f = "(o)"
- l.append( f+" "+nomj )
- #l.append( '-'*(len(nomj)+3) )
+ l.append(f + " " + nomj)
for name in self._subtypes:
obj = getattr(self, name)
- if isinstance(obj,(AsBase,OJB)):
- l.append( obj.dump(indent) )
+ if isinstance(obj, (AsBase, OJB)):
+ l.append(obj.dump(indent))
for name in dir(self):
- if name.startswith( 'check_' ):
+ if name.startswith('check_'):
obj = getattr(self, name)
if callable(obj) and name.startswith("check_"):
- checkers.append( obj )
+ checkers.append(obj)
- indent = " "*len(nomj)
+ indent = " " * len(nomj)
for checker in checkers:
- doc = pydoc.text.document( checker )
+ doc = pydoc.text.document(checker)
for line in doc.splitlines():
- l.append( indent + line )
- return "\n".join( l )
+ l.append(indent + line)
+ return "\n".join(l)
def short_repr(self):
- return "<%s(%x,%r)>" % (self.__class__.__name__, id(self), self.nomj() )
+ return "<%s(%x,%r)>" % (self.__class__.__name__, id(self), self.nomj())
def long_repr(self):
if not hasattr(self, "accessible") or not self.accessible():
- # hors Aster ou en par_lot='oui'
- return self.short_repr()
+ # hors Aster ou en par_lot='oui'
+ return self.short_repr()
else:
- from Cata.cata import IMPR_CO, _F
- IMPR_CO(CONCEPT=_F(NOM=self.nom), UNITE=6)
- return ''
+ from Cata.cata import IMPR_CO, _F
+ IMPR_CO(CONCEPT=_F(NOM=self.nom), UNITE=6)
+ return ''
def __repr__(self):
- # par défaut, on fait court !
+ # par défaut, on fait court !
return self.short_repr()
# -----------------------------------------------------------------------------
class JeveuxAttr(object):
+
"""Un attribut jeveux"""
+
def __init__(self, name):
self.name = name
def __get__(self, obj, klass):
raise NotImplementedError
- def check(self, attrname, obj, log ):
- checker = getattr(obj, "_"+attrname, None )
+ def check(self, attrname, obj, log):
+ checker = getattr(obj, "_" + attrname, None)
if checker is None:
return True
- val = self.__get__( obj, obj.__class__ )
- if callable( checker ):
- return checker( obj, attrname, val, log )
+ val = self.__get__(obj, obj.__class__)
+ if callable(checker):
+ return checker(obj, attrname, val, log)
+ elif val == checker:
+ return True
else:
- test = val == checker
- if not test:
- log.err( obj, "Attribut incorrect %s %r!=%r" % (self.name, val, checker ) )
- return test
+ log.err(obj, "Attribut incorrect %s %r!=%r" %
+ (self.name, val, checker))
+ return False
# -----------------------------------------------------------------------------
+
+
class JeveuxExists(JeveuxAttr):
+
def __init__(self):
pass
if obj is None:
return self
nomj = obj.nomj()
- if len(nomj)!=24:
+ if len(nomj) != 24:
raise AssertionError(repr(nomj))
- return aster.jeveux_exists( nomj.ljust(24) )
+ return aster.jeveux_exists(nomj.ljust(24))
# -----------------------------------------------------------------------------
+
+
class JeveuxIntAttr(JeveuxAttr):
+
def __get__(self, obj, klass):
if obj is None:
return self
nomj = obj.nomj()
- if aster.jeveux_exists( nomj ):
- return aster.jeveux_getattr( nomj, self.name )[0]
- else :
+ if aster.jeveux_exists(nomj):
+ return aster.jeveux_getattr(nomj, self.name)[0]
+ else:
return None
# -----------------------------------------------------------------------------
+
+
class JeveuxStrAttr(JeveuxAttr):
+
def __get__(self, obj, klass):
if obj is None:
return self
nomj = obj.nomj()
- if aster.jeveux_exists( nomj ):
- return aster.jeveux_getattr( nomj, self.name )[1].strip()
- else :
+ if aster.jeveux_exists(nomj):
+ return aster.jeveux_getattr(nomj, self.name)[1].strip()
+ else:
return None
# -----------------------------------------------------------------------------
+
+
class OJB(AsBase):
_clas = None
_genr = None
xous = JeveuxStrAttr("XOUS")
docu = JeveuxStrAttr("DOCU")
exists = JeveuxExists()
- #optional = False
nomj = SDNom()
def __init__(self, nomj=None, **attrs):
- super(OJB,self).__init__( nomj, **attrs )
- self.foreachattr( self.setattribute, attrs )
+ super(OJB, self).__init__(nomj, **attrs)
+ self.foreachattr(self.setattribute, attrs)
self.optional = attrs.get('optional', False)
- def setattribute( self, name, prop, attrs ):
- _name = "_"+name
+ def setattribute(self, name, prop, attrs):
+ _name = "_" + name
if name in attrs:
- setattr( self, _name, attrs[name] )
+ setattr(self, _name, attrs[name])
def get(self):
nomj = self.nomj()
- if aster.jeveux_exists( nomj ):
- obj_simple = aster.jeveux_getattr( nomj, 'XOUS')[1].strip() == 'S'
- if obj_simple :
- return aster.getvectjev( nomj )
- else :
- return aster.getcolljev( nomj )
+ if aster.jeveux_exists(nomj):
+ obj_simple = aster.jeveux_getattr(nomj, 'XOUS')[1].strip() == 'S'
+ if obj_simple:
+ return aster.getvectjev(nomj)
+ else:
+ return aster.getcolljev(nomj)
else:
return None
+ def changeJeveuxValues(self, nbval, indices, reel, imag, num = 1):
+ """Modify values of existing data structures"""
+ nomj = self.nomj()
+ if aster.jeveux_exists(nomj):
+ obj_simple = aster.jeveux_getattr(nomj, 'XOUS')[1].strip() == 'S'
+ if obj_simple:
+ assert num==1,"""For vectors last argument must be set to 1"""
+ # aster.putvectjev can be used for vectors (num=1) and collections
+ aster.putvectjev(nomj, nbval, indices, reel, imag, num)
+
def get_stripped(self):
- """Fonction utilitaire, renvoie une liste de chaines 'strippées'"""
+ """Fonction utilitaire, renvoie une liste de chaines 'strippées'"""
data = self.get()
if data is not None:
- return [ x.strip() for x in data ]
+ return [x.strip() for x in data]
else:
return []
- def foreachattr(self, callable, *args, **kwargs):
+ def foreachattr(self, callback, *args, **kwargs):
klass = self.__class__
for k in dir(klass):
- v = getattr( klass, k )
+ v = getattr(klass, k)
if isinstance(v, JeveuxAttr):
- callable( k, v, *args, **kwargs )
+ callback(k, v, *args, **kwargs)
def check(self, checker=None):
if checker is None:
checker = CheckLog()
- # l'objet a déjà été vérifié, on ne fait rien
+ # l'objet a déjà été vérifié, on ne fait rien
if checker.checkedOJB(self):
- return checker
- checker.visitOJB( self )
+ return checker
+ checker.visitOJB(self)
if self.exists:
- self.foreachattr( lambda k,v,obj,c: v.check(k, obj, c),
- self, checker )
+ self.foreachattr(lambda k, v, obj, c: v.check(k, obj, c),
+ self, checker)
else:
- if not self.optional and not checker.optional :
- checker.err( self, "n'existe pas (%r)" %self._parent )
+ if not self.optional and not checker.optional:
+ checker.err(self, "n'existe pas (%r)" % self._parent)
return checker
def dump(self, indent=""):
f = "(f)"
else:
f = "(o)"
- return f +" "+ self.nomj() +" "+ str(self.exists)
+ return f + " " + self.nomj() + " " + str(self.exists)
# -----------------------------------------------------------------------------
-def Facultatif( ojb ):
+
+
+def Facultatif(ojb):
ojb.optional = True
return ojb
# -----------------------------------------------------------------------------
+
+
class OJBVect(OJB):
lonmax = JeveuxIntAttr("LONMAX")
lonuti = JeveuxIntAttr("LONUTI")
_genr = "V"
# -----------------------------------------------------------------------------
+
+
class OJBPtnom(OJB):
nommax = JeveuxIntAttr("NOMMAX")
nomuti = JeveuxIntAttr("NOMUTI")
_type = "K"
# -----------------------------------------------------------------------------
+
+
class OJBCollec(OJB):
stockage = JeveuxStrAttr("STOCKAGE")
- nutioc = JeveuxIntAttr( "NUTIOC" )
- acces = JeveuxStrAttr( "ACCES" )
- modelong = JeveuxStrAttr( "MODELONG" )
- nmaxoc = JeveuxIntAttr( "NMAXOC" )
+ nutioc = JeveuxIntAttr("NUTIOC")
+ acces = JeveuxStrAttr("ACCES")
+ modelong = JeveuxStrAttr("MODELONG")
+ nmaxoc = JeveuxIntAttr("NMAXOC")
# -----------------------------------------------------------------------------
+
+
class AsVI(OJBVect):
_type = "I"
# -----------------------------------------------------------------------------
+
+
class AsVS(OJBVect):
_type = "S"
# -----------------------------------------------------------------------------
+
+
class AsVR(OJBVect):
_type = "R"
# -----------------------------------------------------------------------------
+
+
class AsVC(OJBVect):
_type = "C"
# -----------------------------------------------------------------------------
+
+
class AsVL(OJBVect):
_type = "L"
# -----------------------------------------------------------------------------
+
+
class AsVK8(OJBVect):
_type = "K"
_ltyp = 8
# -----------------------------------------------------------------------------
+
+
class AsVK16(OJBVect):
_type = "K"
_ltyp = 16
# -----------------------------------------------------------------------------
+
+
class AsVK24(OJBVect):
_type = "K"
_ltyp = 24
# -----------------------------------------------------------------------------
+
+
class AsVK32(OJBVect):
_type = "K"
_ltyp = 32
# -----------------------------------------------------------------------------
+
+
class AsVK80(OJBVect):
_type = "K"
_ltyp = 80
# Pour compatibilite
AsObject = OJB
-AsColl = OJBCollec
-AsPn = OJBPtnom
-AsVect = OJBVect
+AsColl = OJBCollec
+AsPn = OJBPtnom
+AsVect = OJBVect