From fbfdd23c83f0a5a4899b4a801e13e9e931b15fa5 Mon Sep 17 00:00:00 2001 From: "pascale.noyret" Date: Mon, 25 Nov 2019 17:06:27 +0100 Subject: [PATCH] a moitie fait --- Efi2Xsd/AccasXsd.py | 153 +++++++++++++++++++++++++++----------------- 1 file changed, 95 insertions(+), 58 deletions(-) diff --git a/Efi2Xsd/AccasXsd.py b/Efi2Xsd/AccasXsd.py index 902e4ba3..5277c8d5 100755 --- a/Efi2Xsd/AccasXsd.py +++ b/Efi2Xsd/AccasXsd.py @@ -3,7 +3,7 @@ import sys,os import types import Accas -import inspect +import imp # CONTEXT est accessible (__init__.py de Noyau) @@ -29,11 +29,11 @@ from .balisesXSD import * class X_definition: # ----------------- - def getCode(self): - if hasattr(self,'code') : return + def getNomDuCodeDumpe(self): + if hasattr(self,'nomDuCodeDumpe') : return obj=self - while ( not hasattr(obj,'code') ): obj=obj.pere - self.code = obj.code + while ( not hasattr(obj,'nomDuCodeDumpe') ): obj=obj.pere + self.nomDuCodeDumpe = obj.nomDuCodeDumpe #def genealogie(self,n): # texte=self.nom @@ -57,6 +57,7 @@ class X_definition: self.aCreer = False if nom == 'T_Consigne' : return nom listePossible=cata.dictTypesXSD[nom] + print (listePossible) indice=0 while (indice < len(listePossible)) : objAComparer=listePossible[indice] @@ -103,7 +104,7 @@ class X_definitionComposee (X_definition): #print ('------------------------------------------------') if PourTraduction : print (self.nom) - self.getCode() + self.getNomDuCodeDumpe() self.nomDuTypePyxb = self.definitNomDuTypePyxb() self.texteSimple = "" # on n ajoute pas de type simple @@ -112,7 +113,7 @@ class X_definitionComposee (X_definition): # if self.aCreer : self.texteComplexe = debutTypeCompo.format(self.nomDuTypePyxb) - if inExtension : self.texteComplexe += debutEtension.format(self.code) + if inExtension : self.texteComplexe += debutEtension.format(self.nomDuCodeDumpe) self.texteComplexe += debutTypeCompoSeq texteComplexeVenantDesFils=self.CreeTexteComplexeVenantDesFils() self.texteComplexe = texteComplexeVenantDesFils + self.texteComplexe @@ -123,7 +124,7 @@ class X_definitionComposee (X_definition): else : self.texteComplexe = "" - self.texteElt=eltCompoDsSequence.format(self.nom,self.code,self.nomDuTypePyxb,self.minOccurs,self.maxOccurs) + self.texteElt=eltCompoDsSequence.format(self.nom,self.nomDuCodeDumpe,self.nomDuTypePyxb,self.minOccurs,self.maxOccurs) #print (self.texteComplexe) #print ('------------------------------------------------') @@ -180,7 +181,7 @@ class X_BLOC (X_definitionComposee): #print ('------------------------------------------------') #print ('dumpXsd de ' , self.nom) - self.getCode() + self.getNomDuCodeDumpe() self.nomDuTypePyxb = self.definitNomDuTypePyxb() self.texteSimple = "" # on n ajoute pas de type simple @@ -193,7 +194,7 @@ class X_BLOC (X_definitionComposee): else : self.texteComplexe = "" - self.texteElt=substDsSequence.format(self.code,self.nomDuTypePyxb,0,1) + self.texteElt=substDsSequence.format(self.nomDuCodeDumpe,self.nomDuTypePyxb,0,1) #print ('------------------------------------------------') @@ -216,7 +217,7 @@ class X_SIMP (X_definition): if PourTraduction : print (self.nom) #if self.nom == 'Fichier' : import traceback; traceback.print_stack() #print ('exploreObjet SIMP') - self.getCode() + self.getNomDuCodeDumpe() self.aCreer = True self.texteComplexe = "" self.texteSimple = "" @@ -239,13 +240,13 @@ class X_SIMP (X_definition): # a revoir pour les tuples avec defaut txtDefaut="" for val in self.defaut : txtDefaut+=str(val) +" " - self.texteElt = eltWithDefautDsSequence.format(nomUtil,self.code,self.nomDuTypePyxb,minOccurs,1,txtDefaut) + self.texteElt = eltWithDefautDsSequence.format(nomUtil,self.nomDuCodeDumpe,self.nomDuTypePyxb,minOccurs,1,txtDefaut) else : if str(self.defaut) == 'True' : txtDefaut = 'true' else : txtDefaut = str(self.defaut) - self.texteElt = eltWithDefautDsSequence.format(nomUtil,self.code,self.nomDuTypePyxb,minOccurs,1,txtDefaut) + self.texteElt = eltWithDefautDsSequence.format(nomUtil,self.nomDuCodeDumpe,self.nomDuTypePyxb,minOccurs,1,txtDefaut) - else : self.texteElt = eltDsSequence.format(nomUtil,self.code,self.nomDuTypePyxb,minOccurs,1) + else : self.texteElt = eltDsSequence.format(nomUtil,self.nomDuCodeDumpe,self.nomDuTypePyxb,minOccurs,1) # self.aCreer est mis a jour ds definitNomDuTypePyxb if not self.aCreer : return @@ -326,25 +327,40 @@ class X_JDC_CATA : def dumpXsd(self): cata = CONTEXT.getCurrentCata() - if self.fichierSource != self.module.__file__ : - self.texteXSD = self.dumpDifferenceModuleMetier() - return self.texteXSD + self.nomDuCodeDumpe=self.labelCode + + print ('self.implementing -------------------', self.implementing) + self.texteSimple = "" self.texteComplexe = "" - self.nomDuTypePyxb='T_'+self.code - self.texteCata = debutTypeCata.format(self.nomDuTypePyxb) - for commande in self.commandes : - commande.code=self.code - commande.dumpXsd() - self.texteSimple += commande.texteSimple - self.texteSimple += commande.texteComplexe - self.texteCata += commande.texteElt - self.texteSimple += TypeEtEltAbstraitCodeSpec.format(self.code) - self.texteCata += EltCodeSpecDsCata.format(self.code) + self.texteCata = "" + + if self.implementing == "" : + self.texteCata = texteDebut.format(self.nomDuCodeDumpe,self.nomDuCodeDumpe,self.nomDuCodeDumpe) + self.texteCata += includeCata.format(self.nomDuCodeDumpe) + self.inExtension = False + else : + self.inExtension = True + + self.texteElt = "" + self.nomDuTypePyxb = 'T_'+self.nomDuCodeDumpe + self.texteCata = debutTypeCata.format(self.nomDuTypePyxb) + + self.dumpLesCommandes() + + + #for commande in self.commandes : + # commande.nomDuCodeDumpe=self.nomDuCodeDumpe + # commande.dumpXsd() + # self.texteSimple += commande.texteSimple + # self.texteSimple += commande.texteComplexe + # self.texteCata += commande.texteElt + #self.texteSimple += TypeEtEltAbstraitCodeSpec.format(self.nomDuCodeDumpe) + #self.texteCata += EltCodeSpecDsCata.format(self.nomDuCodeDumpe) self.texteCata += finTypeCata - self.texteElt = eltCata.format(self.code,self.code, self.nomDuTypePyxb) + self.texteElt = eltCata.format(self.nomDuCodeDumpe,self.nomDuCodeDumpe, self.nomDuTypePyxb) - self.texteXSD = texteDebut.format(self.code,self.code,self.code,self.code) + self.texteXSD = texteDebut.format(self.nomDuCodeDumpe,self.nomDuCodeDumpe,self.nomDuCodeDumpe,self.nomDuCodeDumpe) #self.texteXSD += textDeclaration self.texteXSD += self.texteSimple self.texteXSD += self.texteCata @@ -367,37 +383,58 @@ class X_JDC_CATA : return self.texteXSD - def dumpDifferenceModuleMetier(self): - fichierSourceExt=os.path.basename(self.fichierSource) - fichierSource, extension=os.path.splitext(fichierSourceExt) - - allClassFromVimp=[] - o=__import__(fichierSource,{},{}) - for k,d in inspect.getmembers(o): - allClassFromVimp.append(k) - + def dumpLesCommandes(self): + cata = CONTEXT.getCurrentCata() + fichierCataSourceExt=os.path.basename(cata.cata.__file__) + fichierCataSource, extension=os.path.splitext(fichierCataSourceExt) + importCataSource=__import__(fichierCataSource,{},{}) + + texte="" + for m in sys.modules: + monModule=sys.modules[m] + try : + if m in ('os', 'sys', 'inspect', 'six', 'pickle', 'codecs') : continue + if m in ('cPickle', 'pprint', 'dis', '_sre', 'encodings.aliases'): continue + if m in ('numbers', 'optparse', 'binascii', 'posixpath') : continue + if m in ('_locale', '_sysconfigdata_nd', 'gc', 'functools') : continue + if m in ('posixpath', 'types', 'posix', 'prefs') : continue + if m in ('warnings', 'types', 'posix', 'prefs') : continue + if monModule.__name__[0:15] == '_sysconfigdata_' : continue + if monModule.__name__ == '__future__' : continue + if monModule.__name__[0:3] == 'Ihm' : continue + if monModule.__name__[0:5] == 'numpy' : continue + if monModule.__name__[0:5] == 'Noyau' : continue + if monModule.__name__[0:5] == 'Accas' : continue + if monModule.__name__[0:7] == 'convert' : continue + if monModule.__name__[0:7] == 'Efi2Xsd' : continue + if monModule.__name__[0:7] == 'Editeur' : continue + if monModule.__name__[0:9] == 'generator' : continue + if monModule.__name__[0:10] == 'Validation' : continue + if monModule.__name__[0:10] == 'Extensions' : continue + if monModule.__name__[0:12] == 'InterfaceQT4' : continue + if monModule.__name__ == fichierCataSource : continue + texte= texte + "try : import "+ monModule.__name__ + " \n" + texte= texte + "except : pass \n" + texte= texte + "try : from "+ monModule.__name__ + ' import * \n' + texte= texte + "except : pass \n" + except : + pass + + newModule=imp.new_module('__main__') + exec (texte, newModule.__dict__) allClassToDump=[] - for key, data in inspect.getmembers(self.module): - if key in allClassFromVimp : continue - if key != "modeleMetier" : allClassToDump.append(data) + for i in dir(importCataSource): + if i not in dir(newModule): + allClassToDump.append(importCataSource.__dict__[i]) + - self.texteSimple = "" - self.texteComplexe = "" - self.texteCata = texteDebut.format(self.code,self.code,self.code) - self.texteCata += includeCata.format(self.code) - self.texteElt = "" - + self.texteSimple = '' + self.texteElt = '' for c in allClassToDump : - if not(isinstance(c, Accas.OPER)) and not(isinstance(c, Accas.PROC)) : continue - c.code=self.code - c.dumpXsd(inExtension=True) + if not(isinstance(c, Accas.OPER)) and not(isinstance(c, Accas.PROC)) : continue + c.nomDuCodeDumpe=self.nomDuCodeDumpe + c.dumpXsd(self.inExtension) self.texteSimple += c.texteSimple self.texteSimple += c.texteComplexe - c.texteElt=eltCompoDsSequenceInExtension.format(c.nom,self.code,c.nomDuTypePyxb) - self.texteElt += c.texteElt - #print (self.texteCata) - #print (self.texteSimple) - #print (self.texteElt) - self.texteXSD = self.texteCata+'\n'+self.texteSimple+'\n'+self.texteElt+'\n'+texteFin+'\n' - #if not PourTraduction : print (self.texteXSD) - return self.texteXSD + c.texteElt=eltCompoDsSequenceInExtension.format(c.nom,self.nomDuCodeDumpe,c.nomDuTypePyxb) + self.texteCata += c.texteElt -- 2.39.2