Salome HOME
Add COPYING license file
[tools/eficas.git] / Editeur / cata2Xml.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2021   EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 from __future__ import absolute_import
23 from __future__ import print_function
24 try :
25     from builtins import str
26     from builtins import object
27 except :
28     pass
29 import sys,os
30 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),'..'))
31 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),'../InterfaceQT4'))
32 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),'../UiQT4'))
33 from Extensions.i18n import tr
34 from string import split,strip,lowercase,uppercase
35 import re,string
36
37 import xml.etree.ElementTree as ET
38 from xml.dom import minidom
39
40 from PyQt4.QtGui import *
41
42 def prettify(elem):
43     """Return a pretty-printed XML string for the Element.
44     """
45     rough_string = ET.tostring(elem, 'iso-8859-1')
46     reparsed = minidom.parseString(rough_string)
47     return reparsed.toprettyxml(indent="  ")
48
49
50 class CatalogueXML(object):
51     def __init__(self,cata,cataName):
52         self.fichier="/tmp/XML/"+cataName+".xml"
53         self.cata=cata
54         self.first=ET.Element('cata')
55         comment=ET.Comment("catalogue "+str(cataName))
56         self.first.append(comment)
57         self.reglesUtilisees=[]
58         self.validatorsUtilises=[]
59         self.constrListTxtCmd()
60         self.ecrire_fichier()
61
62
63     def ecrire_fichier(self):
64         try :
65             import codecs
66             f = codecs.open(self.fichier, "w", "ISO-8859-1")
67             #print prettify(self.first)
68             f.write(prettify(self.first))
69             f.close()
70         except :
71             print(("Impossible d'ecrire le fichier : "+ str(self.fichier)))
72
73     def constrListTxtCmd(self):
74         mesCommandes=self.cata.JdC.commandes
75         self.commandes=ET.SubElement(self.first,'commandes')
76         for maCommande in mesCommandes:
77             maCommande.enregistreXMLStructure(self.commandes,self)
78
79
80 if __name__ == "__main__" :
81     #monCata="/local/noyret/Install_Eficas/MAP/mapcata.py"
82     #monCata="/local/noyret/Install_Eficas/Aster/Cata/cataSTA11/cata.py"
83     #monCata="/local/noyret/Install_Eficas/MAP/mapcata.py"
84     #monCata="/local/noyret/Install_Eficas/MAP/mapcata.py"
85     code="Aster"
86     version=None
87
88     from Editeur  import session
89     options=session.parse(sys.argv)
90     if options.code!= None :    code=options.code
91     if options.cata!= None : monCata=options.cata
92     if options.ssCode!= None :  ssCode=options.ssCode
93
94     sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),'..',code))
95
96     from InterfaceQT4.ssIhm  import QWParentSSIhm, appliEficasSSIhm
97     Eficas=appliEficasSSIhm(code=code)
98     parent=QWParentSSIhm(code,Eficas,version)
99
100     import readercata
101     monreadercata  = readercata.READERCATA( parent, parent )
102     Eficas.readercata=monreadercata
103     monCata=monreadercata.cata
104
105     monCataXML=CatalogueXML(monCata,code)