X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=convert%2Fconvert_TELEMAC.py;h=250a560470606ab2d43d1b61661fc390484a2bad;hb=217a9ce2f303b098ad28d282bb0df2dfeeeed3c2;hp=6bbb49995a55dd4d000bbfa1b64e2a6b697cb74d;hpb=d550ecdf7905edf591133967a6eacaf510afa563;p=tools%2Feficas.git diff --git a/convert/convert_TELEMAC.py b/convert/convert_TELEMAC.py index 6bbb4999..250a5604 100644 --- a/convert/convert_TELEMAC.py +++ b/convert/convert_TELEMAC.py @@ -16,11 +16,20 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -import re, string +from __future__ import absolute_import + + +import re from Extensions.i18n import tr -from convert_python import PythonParser +from .convert_python import PythonParser +import six +from six.moves import range +try: + basestring +except NameError: + basestring = str pattern_comment_slash = re.compile(r"^\s*/") pattern_eta = re.compile(r".*&ETA.*") @@ -63,8 +72,6 @@ except : from Extensions import localisation -from determine import monEnvQT5 - def entryPoint(): @@ -72,7 +79,7 @@ def entryPoint(): Return a dictionary containing the description needed to load the plugin """ return { - 'name' : 'TELEMAC3', + 'name' : 'TELEMAC', 'factory' : TELEMACParser } @@ -94,13 +101,13 @@ class TELEMACParser(PythonParser): if appli.langue=='fr' : from enumDicoTelemac import DicoEnumCasFrToEnumCasEn - for k in DicoEnumCasFrToEnumCasEn.keys() : + for k in DicoEnumCasFrToEnumCasEn : TelemacdicoEn[k]=DicoEnumCasFrToEnumCasEn[k] text="" self.dictSimp={} - l_lignes_texte_all = string.split(self.text,'\n') + l_lignes_texte_all = self.text.split('\n') l_lignes_texte = [] for l in l_lignes_texte_all : if not(pattern_comment_slash.match(l)): l_lignes_texte.append(l) @@ -145,9 +152,9 @@ class TELEMACParser(PythonParser): m=pattern_ligne.match(finLigne) if m == None : - #print "________________________________________________" - print 'pb avec ****', finLigne , '**** dans ', ligne - #print "________________________________________________" + #print( "________________________________________________") + print ('pb avec ****', finLigne , '**** dans ', ligne) + #print( "________________________________________________") break simpCas=self.traiteIdent(m.group('ident')) @@ -170,10 +177,10 @@ class TELEMACParser(PythonParser): elif pattern_texteSimple.match(finLigne): m=pattern_texteSimple.match(finLigne) else : - #print "________________________________________________" - print 'pb avec ****', finLigne , '**** dans ', ligne - print "non match" - #print "________________________________________________" + #print ("________________________________________________") + print ('pb avec ****', finLigne , '**** dans ', ligne) + print ("non match") + #print ("________________________________________________") break @@ -190,23 +197,21 @@ class TELEMACParser(PythonParser): finLigne=m.group('reste') self.dictSimp[simpCas]=valeur - #print self.dictSimp - if 'TITLE' not in self.dictSimp.keys() : + if 'TITLE' not in self.dictSimp : import os #self.dictSimp['TITLE']=os.path.basename(self.filename) dicoParMC={} - for simp in self.dictSimp.keys(): - if simp in TELEMACParser.__dict__.keys() : apply(TELEMACParser.__dict__[simp],(self,)) + for simp in self.dictSimp: + if simp in TELEMACParser.__dict__ : TELEMACParser.__dict__[simp],(self,) - for simp in self.dictSimp.keys(): + for simp in self.dictSimp: if simp in ListeSupprimeCasToEficas: continue - if simp not in self.dicoInverse.keys() : - #print "************" - print "pb avec dans dicoInverse", simp,'------' - #print "************" - #print poum + if simp not in self.dicoInverse : + #print ( "************") + print ("pb avec dans dicoInverse", simp,'------') + #print ("************") continue listeGenea=self.dicoInverse[simp] listeGeneaReverse=[] @@ -216,28 +221,22 @@ class TELEMACParser(PythonParser): listeGeneaReverse.reverse() dicoTravail=dicoParMC i=0 - #print (listeGeneaReverse[0:-1]) while i < len(listeGeneaReverse[0:-1]) : mot=listeGeneaReverse[i] i=i+1 - if mot not in dicoTravail.keys(): dicoTravail[mot]={} + if mot not in dicoTravail: dicoTravail[mot]={} dicoTravail=dicoTravail[mot] dicoTravail[simp]=self.dictSimp[simp] self.textePy="" - #print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" - #print dicoParMC - #print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" - listeMC=self.tri(dicoParMC.keys()) + listeMC=self.tri(list(dicoParMC.keys())) for k in listeMC : - #print "----------- traitement de " , k self.textePy += str(k )+ "(" self.traiteMC(dicoParMC[k]) self.textePy += ");\n" - #print "----------- " - appli.listeTelemac=self.dictSimp.keys() + appli.listeTelemac=self.dictSimp return self.textePy @@ -246,34 +245,31 @@ class TELEMACParser(PythonParser): # enleve les espaces de part et autre # traduit du langage Telemac vers le langage Catalogue #---------------------------------------- - #print ident while ident[-1] == " " or ident[-1] == '\t' : ident=ident[0:-1] while ident[0] == " " or ident[0] == '\t' : ident=ident[1:] try : identCata=self.dicoCasToCata[ident] except : - print "---> ", "pb mot clef pour", ident + print ( "---> ", "pb mot clef pour", ident) identCata=None return identCata def traiteMC(self,dico) : from Accas import A_BLOC, A_FACT, A_SIMP - for k in dico.keys() : + for k in dico : valeur= dico[k] - if k not in self.dicoMC.keys() : kA=self.dicoFrancaisAnglais[k] + if k not in self.dicoMC : kA=self.dicoFrancaisAnglais[k] else : kA=k obj=self.dicoMC[kA] if isinstance(obj,A_FACT.FACT): self.convertFACT(obj,kA,valeur) elif isinstance(obj,A_BLOC.BLOC): self.convertBLOC(obj,kA,valeur) elif isinstance(obj,A_SIMP.SIMP): self.convertSIMP(obj,kA,valeur) - else : print "%%%%%%%%%%%\n", "pb conversion type pour", k, obj, "\n%%%%%%%%%%%" + else : print ("%%%%%%%%%%%\n", "pb conversion type pour", k, obj, "\n%%%%%%%%%%%") - #print "_____________" def convertFACT(self,obj,nom,valeur): - #print "convertFACT", nom,valeur - if nom in TELEMACParser.__dict__.keys() : - apply(TELEMACParser.__dict__[nom],(self,)) + if nom in TELEMACParser.__dict__ : + TELEMACParser.__dict__[nom],(self,) return self.textePy += nom + "=_F( " self.traiteMC(valeur) @@ -281,8 +277,8 @@ class TELEMACParser(PythonParser): def convertBLOC(self,obj,nom,valeur): - print "BLOC " - print nom + print ("ANOMALIE _________ BLOC ") + print (nom) def convertSIMP(self,obj,nom,valeur): #print 'in convertSIMP', nom,valeur @@ -314,7 +310,7 @@ class TELEMACParser(PythonParser): try : valeur=eval(valeur,{}) except : pass - if nom in TelemacdicoEn.keys(): + if nom in TelemacdicoEn: try : valeur=TelemacdicoEn[nom][valeur] self.textePy += nom + "= '" + str(valeur) +"'," @@ -335,7 +331,7 @@ class TELEMACParser(PythonParser): break except: if valeur != None : - print "pb avec le type de ", obj.nom, obj.type, 'et la valeur ', valeur + print ("pb avec le type de ", obj.nom, obj.type, 'et la valeur ', valeur) if 'Fichier' in obj.type or 'TXM' in obj.type or 'Repertoire' in obj.type : valeur=str(valeur) @@ -373,7 +369,7 @@ class TELEMACParser(PythonParser): # Attention : on attend une liste mais on a une seule valeur! try : oldValeur=eval(oldValeur,{}) except : pass - if nom in TelemacdicoEn.keys() : + if nom in TelemacdicoEn : v=TelemacdicoEn[nom][oldValeur] self.textePy += nom + "= ('" + str(v) +"',)," else : @@ -386,8 +382,7 @@ class TELEMACParser(PythonParser): for v in valeur : try : v=eval(v,{}) except : pass - if nom in TelemacdicoEn.keys(): - #print "est dans le dico des enum, valeurs multiples" + if nom in TelemacdicoEn: try : v=TelemacdicoEn[nom][v] except : pass newVal.append(v) @@ -398,7 +393,6 @@ class TELEMACParser(PythonParser): def tri(self, listeIn): if len(listeIn) == 1 : return listeIn if self.Ordre_Des_Commandes == None : return listeIn - #print listeIn listeOut=[listeIn[0],] for k in listeIn[1:]: #k=str(self.dicoFrancaisAnglais[kF]) @@ -414,19 +408,18 @@ class TELEMACParser(PythonParser): return listeOut def LIQUID_BOUNDARIES(self): - print 'Liquid Boundaries' texte_Boundaries="LIQUID_BOUNDARIES=( " - if 'PRESCRIBED_ELEVATIONS' in self.dictSimp.keys(): + if 'PRESCRIBED_ELEVATIONS' in self.dictSimp: valeursPE=self.dictSimp["PRESCRIBED_ELEVATIONS"] if not type(valeursPE)==list : valeursPE = (valeursPE,) longueur=len(self.dictSimp["PRESCRIBED_ELEVATIONS"]) else : valeursPE=None - if 'PRESCRIBED_FLOWRATES' in self.dictSimp.keys(): + if 'PRESCRIBED_FLOWRATES' in self.dictSimp: valeursPF=self.dictSimp["PRESCRIBED_FLOWRATES"] if not type(valeursPF)==list : valeursPF = (valeursPF,) longueur=len(self.dictSimp["PRESCRIBED_FLOWRATES"]) else : valeursPF=None - if 'PRESCRIBED_VELOCITIES' in self.dictSimp.keys(): + if 'PRESCRIBED_VELOCITIES' in self.dictSimp: valeursPV=self.dictSimp["PRESCRIBED_VELOCITIES"] if not type(valeursPV)==list : valeursPV = (valeursPV,) longueur=len(self.dictSimp["PRESCRIBED_VELOCITIES"]) @@ -445,7 +438,6 @@ class TELEMACParser(PythonParser): if valeursPF == None : valeursPF = listNulle if valeursPV == None : valeursPV = listNulle - #print valeursPE,valeursPF,valeursPV for e in range(len(valeursPE)): if valeursPE[e] != "" or valeursPE[e] != "\n" : @@ -465,7 +457,7 @@ class TELEMACParser(PythonParser): texte_Boundaries += "_F( BOUNDARY_TYPE= 'Prescribed Velocity',\n" texte_Boundaries += "PRESCRIBED_VELOCITIES = " + str(valeursPV[e]) + "),\n" continue - print "pb texte_Boundaries avec la valeur numero ", e + print ("pb texte_Boundaries avec la valeur numero ", e) texte_Boundaries +="),\n" self.textePy += texte_Boundaries