Salome HOME
menage
[tools/eficas.git] / Editeur / cata2Xml.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2013   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 import sys,os
23 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),'..'))
24 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),'../InterfaceQT4'))
25 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),'../UiQT4'))
26 from Extensions.i18n import tr
27 from string import split,strip,lowercase,uppercase
28 import re,string
29
30 import xml.etree.ElementTree as ET
31 from xml.dom import minidom
32
33 from PyQt4.QtGui import *
34
35 def prettify(elem):
36     """Return a pretty-printed XML string for the Element.
37     """
38     rough_string = ET.tostring(elem, 'iso-8859-1')
39     reparsed = minidom.parseString(rough_string)
40     return reparsed.toprettyxml(indent="  ")
41
42                 
43 class CatalogueXML:
44         def __init__(self,cata,cataName):
45                 self.fichier="/tmp/XML/"+cataName+".xml"
46                 self.cata=cata
47                 self.first=ET.Element('cata')
48                 comment=ET.Comment("catalogue "+str(cataName))
49                 self.first.append(comment)
50                 self.reglesUtilisees=[]
51                 self.validatorsUtilises=[]
52                 self.constr_list_txt_cmd()
53                 self.ecrire_fichier()
54
55
56         def ecrire_fichier(self):
57                 try :
58                    import codecs
59                    f = codecs.open(self.fichier, "w", "ISO-8859-1")
60                    #print prettify(self.first)
61                    f.write(prettify(self.first))
62                    f.close()
63                 except :
64                    print ("Impossible d'ecrire le fichier : "+ str(self.fichier))
65
66         def constr_list_txt_cmd(self):
67                 mesCommandes=self.cata.JdC.commandes
68                 self.commandes=ET.SubElement(self.first,'commandes')
69                 for maCommande in mesCommandes:
70                     maCommande.enregistreXMLStructure(self.commandes,self)
71
72
73 if __name__ == "__main__" :
74         #monCata="/local/noyret/Install_Eficas/MAP/mapcata.py"
75         #monCata="/local/noyret/Install_Eficas/Aster/Cata/cataSTA11/cata.py"
76         #monCata="/local/noyret/Install_Eficas/MAP/mapcata.py"
77         #monCata="/local/noyret/Install_Eficas/MAP/mapcata.py"
78         code="Aster"
79         version=None
80
81         from Editeur  import session
82         options=session.parse(sys.argv)
83         if options.code!= None :    code=options.code
84         if options.cata!= None : monCata=options.cata
85         if options.ssCode!= None :  ssCode=options.ssCode
86
87         sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),'..',code))
88
89         from InterfaceQT4.ssIhm  import QWParentSSIhm, appliEficasSSIhm
90         Eficas=appliEficasSSIhm(code=code)
91         parent=QWParentSSIhm(code,Eficas,version)
92
93         import readercata
94         monreadercata  = readercata.READERCATA( parent, parent )
95         Eficas.readercata=monreadercata
96         monCata=monreadercata.cata[0]
97
98         monCataXML=CatalogueXML(monCata,code)
99
100
101
102