# -*- coding: utf-8 -*-
+# Copyright (C) 2007-2013 EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
import os
-import parseur
-from mocles import parseKeywords
+import re
+from Traducteur import parseur
+from Traducteur.mocles import parseKeywords
+import sets
+jdcSet=sets.Set()
-JDCdict={}
-class JDC:
+class JDCTrad:
"""Cet objet conserve toutes les informations relatives à un fichier de commandes .comm"""
- def __init__(self,filename,src,atraiter):
+ def __init__(self,src,atraiter):
#----------------------------------------
- self.filename = os.path.abspath(filename)
self.atraiter=atraiter
self.init(src,atraiter)
+ commands= self.root.childNodes[:]
+ commands.reverse()
+ for c in commands:
+ jdcSet.add(c.name)
def init(self,src,atraiter):
#---------------------------
# construction de self.lines
- self.root=parseur.parser(src,atraiter)
+ self.root=parseur.Parser(src,atraiter)
self.lines=src.splitlines(1)
def parseKeywords(self):
Lmilieu=[ligne,]
Lfin=self.lines[numero:]
self.lines=Ldebut+Lmilieu+Lfin
- src=self.getSource()
- self.reset(src)
+
def splitLine(self,numeroLigne,numeroColonne) :
#----------------------------------------------
Lmilieu=[LigneSplitDebut,LigneSplitFin]
self.lines=Ldebut+Lmilieu+Lfin
- src=self.getSource()
- self.reset(src)
def joinLineandNext(self,numeroLigne) :
#--------------------------------------
Lmilieu=[ligneMilieuDeb+ligneMilieuFin,]
self.lines=Ldebut+Lmilieu+Lfin
- src=self.getSource()
- self.reset(src)
+
+ def supLignes(self,debut,fin):
+ #------------------------
+ Ldebut=self.lines[0:debut-1]
+ Lfin=self.lines[fin:]
+ self.lines=Ldebut+Lfin
+
+ def remplaceLine(self,numeroLigne,nouveauTexte) :
+ #------------------------------------------------
+ self.lines[numeroLigne]=nouveauTexte
def getJDC(filename,atraiter):
-#---------------------------_
+#----------------------------
# lit le JDC
- jdc=JDCdict.get(filename)
- if not jdc:
- f=open(filename)
- src=f.read()
- f.close()
- jdc=JDC(filename,src,atraiter)
- JDCdict[filename]=jdc
+ f=open(filename)
+ src=f.read()
+ f.close()
+ jdc=JDCTrad(src,atraiter)
return jdc
+def getJDCFromTexte(texte,atraiter):
+#-----------------------------------
+# lit le JDC
+ jdc=JDCTrad(texte,atraiter)
+ return jdc