1
1
# -*- coding: utf-8 -*-
3
3
#-------------------------------------------------------------------------------
5
# This file is part of the Code_Saturne User Interface, element of the
6
# Code_Saturne CFD tool.
8
# Copyright (C) 1998-2009 EDF S.A., France
10
# contact: saturne-support@edf.fr
12
# The Code_Saturne User Interface is free software; you can redistribute it
13
# and/or modify it under the terms of the GNU General Public License
14
# as published by the Free Software Foundation; either version 2 of
15
# the License, or (at your option) any later version.
17
# The Code_Saturne User Interface is distributed in the hope that it will be
18
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
19
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with the Code_Saturne Kernel; if not, write to the
24
# Free Software Foundation, Inc.,
25
# 51 Franklin St, Fifth Floor,
26
# Boston, MA 02110-1301 USA
5
# This file is part of Code_Saturne, a general-purpose CFD tool.
7
# Copyright (C) 1998-2011 EDF S.A.
9
# This program is free software; you can redistribute it and/or modify it under
10
# the terms of the GNU General Public License as published by the Free Software
11
# Foundation; either version 2 of the License, or (at your option) any later
14
# This program is distributed in the hope that it will be useful, but WITHOUT
15
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19
# You should have received a copy of the GNU General Public License along with
20
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
21
# Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
23
#-------------------------------------------------------------------------------
91
self.data['saved'] = "yes"
92
self.data['xmlfile'] = ""
93
self.data['mesh_path'] = ""
94
self.data['user_src_path'] = ""
95
self.data['data_path'] = ""
96
self.data['resu_path'] = ""
97
self.data['scripts_path'] = ""
98
self.data['relevant_subdir'] = "no"
99
self.data['case_path'] = ""
100
self.data['batchScript'] = {}
101
self.data['backupBatchScript'] = {}
102
self.data['computer'] = ""
85
self.data['saved'] = "yes"
86
self.data['xmlfile'] = ""
87
self.data['mesh_path'] = ""
88
self.data['user_src_path'] = ""
89
self.data['data_path'] = ""
90
self.data['resu_path'] = ""
91
self.data['scripts_path'] = ""
92
self.data['relevant_subdir'] = "no"
93
self.data['case_path'] = ""
94
self.data['batch'] = ""
95
self.data['batch_type'] = ""
103
96
self.data['no_boundary_conditions'] = False
104
self.data['salome'] = False
97
self.data['salome'] = False
98
self.data['package'] = None
107
101
def _errorExit(self, msg):
110
print 'CASE DICO ERROR'
111
raise ValueError, msg
104
print('CASE DICO ERROR')
105
raise ValueError(msg)
114
108
def __setitem__(self, key, name):
116
Store values in the data dictionary when the key existe
110
Store values in the data dictionary when the key exists
117
111
in the dictionary.
119
113
if hasattr(self, 'data'):
1169
1166
except IOError:
1170
1167
msg = "Error: unable to save the XML document file." ,
1171
1168
"(XMLengine module, Case class, xmlSaveDocument method)"
1174
## def xmlSaveDocument(self):
1176
## This method write the associated xml file.
1177
## See saveCase and saveCaseAs methods in the Main module.
1180
## file = open(self['xmlfile'], 'w')
1181
## file.write(self.toPrettyString())
1183
## self['new'] = "no"
1184
## self['saved'] = "yes"
1186
## msg = "Error: unable to save the XML document file." ,
1187
## "(XMLengine module, Case class, xmlSaveDocument method)"
1190
1172
#-------------------------------------------------------------------------------
1191
1173
# XMLengine test case
1739
1721
## root = ndoc.getAll("database")
1741
1723
## db = root[0]
1742
## print "Database:", db["name"]
1724
## print("Database:", db["name"])
1743
1725
## for table in db.getAll("table"):
1744
## print " Table:", table["name"]
1726
## print(" Table:", table["name"])
1745
1727
## for field in db.getAll("field"):
1746
## print " Field:", field["name"], "- Type:", field["type"]
1728
## print(" Field:", field["name"], "- Type:", field["type"])
1748
1730
## # It's object oriented
1749
## print XMLDocument("notice").add("text",format="plain").addText("Some text")
1731
## print(XMLDocument("notice").add("text",format="plain").addText("Some text"))
1751
1733
#-------------------------------------------------------------------------------
1761
print "------------------------------------------------------"
1762
print " Lightweight XML constructor and reader testing"
1763
print "------------------------------------------------------\n"
1743
print("------------------------------------------------------")
1744
print(" Lightweight XML constructor and reader testing")
1745
print("------------------------------------------------------\n")
1765
1747
# Example of dumping a database structure
1767
1749
xmldoc = XMLDocument("", "", "database", name="testdb")
1768
print "XMLDocument:\n", xmldoc
1750
print("XMLDocument:\n", xmldoc)
1770
1752
table = xmldoc.xmlAddChild("table", name="test")
1771
1753
table.xmlAddChild("field", name="counter", type="int")
1772
1754
table.xmlAddChild("field", name="name", type="varchar")
1773
1755
table.xmlAddChild("field", name="info", type="text")
1774
print "table:\n", table
1756
print("table:\n", table)
1776
print "name:", table.xmlGetAttribute("name")
1758
print("name:", table.xmlGetAttribute("name"))
1777
1759
table.xmlDelAttribute("name")
1778
1760
table.xmlCreateAttribute(truc="super", toto="méga")
1779
1761
table.xmlCreateAttribute(name="atchoum")
1780
1762
for field in table.xmlGetNodeList("field", "name", "type", type="text"):
1781
print "field:", field.toString()
1782
print "truc:", table.xmlGetAttribute("truc")
1763
print("field:", field.toString())
1764
print("truc:", table.xmlGetAttribute("truc"))
1783
1765
#table.xmlGetAttribute("tru") # Uncomment this line for testing
1784
1766
l = table.xmlGetNodeList("camion", "jacky", moquette="moche")
1786
1768
l = table.xmlAddChild("camion", jacky="", moquette="moche")
1787
print "child:", l.toString()
1769
print("child:", l.toString())
1788
1770
l = table.xmlInitNodeList("camion", "jacky", moquette="bêlle")[0]
1789
print "child:", l.toString()
1771
print("child:", l.toString())
1791
1773
l.xmlSetData("camion", "rétro")
1792
1774
l.xmlSetData("camion", "chèvre")
1793
1775
for i in table.xmlGetNodeList("camion"):
1794
print "List camion :", i.toString(), "\n"
1776
print("List camion :", i.toString(), "\n")
1795
1777
for i in table.xmlGetChildNodeList("camion"):
1796
print "Child camion:", i.toString(), "\n"
1778
print("Child camion:", i.toString(), "\n")
1798
1780
table.xmlAddComment("Ceci est un commentaire")
1799
1781
table.xmlInitNodeList('scalar', 'roue', 'box', auto='yes', type='model')
1811
1793
chaise = xmldoc.xmlAddChild("chaise", name="test")
1812
1794
p = chaise.xmlSetData("pieds", 4)
1813
print p[0].toString()
1814
print chaise.xmlGetStringList("pieds")
1815
print chaise.xmlGetIntList("pieds")
1816
print chaise.xmlGetString("pieds")
1817
print chaise.xmlGetInt("pieds")
1818
print chaise.xmlGetDouble("pieds")
1819
print p[0].xmlGetTextNode()
1795
print(p[0].toString())
1796
print(chaise.xmlGetStringList("pieds"))
1797
print(chaise.xmlGetIntList("pieds"))
1798
print(chaise.xmlGetString("pieds"))
1799
print(chaise.xmlGetInt("pieds"))
1800
print(chaise.xmlGetDouble("pieds"))
1801
print(p[0].xmlGetTextNode())
1823
1805
# Direct acces to node's methods
1824
#print dir(xmldoc.doc.documentElement)
1825
#print _encode(xmldoc.doc.documentElement.toxml())
1826
#print _encode(xmldoc.doc.documentElement.childNodes[0].childNodes[2].attributes.get("name").value)
1827
#print _encode(xmldoc.doc.firstChild.firstChild.childNodes[1].attributes.items())
1828
#print dir(xmldoc.doc.firstChild.firstChild.childNodes[1].attributes)
1806
#print(dir(xmldoc.doc.documentElement))
1807
#print(_encode(xmldoc.doc.documentElement.toxml()))
1808
#print(_encode(xmldoc.doc.documentElement.childNodes[0].childNodes[2].attributes.get("name").value))
1809
#print(_encode(xmldoc.doc.firstChild.firstChild.childNodes[1].attributes.items()))
1810
#print(dir(xmldoc.doc.firstChild.firstChild.childNodes[1].attributes))
1830
1812
# Simulate reading a XML file
1831
1813
ndoc = XMLDocument("", "")
1832
print "XML DOC:", ndoc.toString()
1814
print("XML DOC:", ndoc.toString())
1833
1815
ndoc.parseString(str(xmldoc))
1834
print "XML DOC:", ndoc.toString()
1816
print("XML DOC:", ndoc.toString())
1835
1817
root = ndoc.xmlGetNodeList("database")
1838
print "Database:", db.xmlGetAttribute("name")
1820
print("Database:", db.xmlGetAttribute("name"))
1839
1821
for table in db.xmlGetNodeList("table"):
1840
print " Table:", table.xmlGetAttribute("name")
1822
print(" Table:", table.xmlGetAttribute("name"))
1841
1823
for field in table.xmlGetNodeList("field"):
1842
print " Field:", field.xmlGetAttribute("name"), \
1843
"- Type:", field.xmlGetAttribute("type")
1824
print(" Field:", field.xmlGetAttribute("name"), \
1825
"- Type:", field.xmlGetAttribute("type"))
1846
1828
ndoc.parseString('<?xml version="2.0" encoding="utf-8" ?><foo><baré/></foo>')
1847
print "1 XML DOC:\n", ndoc
1829
print("1 XML DOC:\n", ndoc)
1849
1831
ndoc.parse("../misc/foo.txt")
1850
print "2 XML DOC:\n", ndoc
1853
print "------------------------------------------------------"
1854
print " Case class testing"
1855
print "------------------------------------------------------\n"
1832
print("2 XML DOC:\n", ndoc)
1835
print("------------------------------------------------------")
1836
print(" Case class testing")
1837
print("------------------------------------------------------\n")
1858
1840
case['new'] = 'toto'
1859
print "case:", case['new']
1841
print("case:", case['new'])
1860
1842
models = case.xmlGetNodeList('thermophysical_models')[0]
1861
1843
models = case.xmlInitNodeList('thermophysical_models')[0]
1862
#print "models :", dir(models)
1844
#print("models :", dir(models))
1863
1845
variables = models.xmlGetNodeList('variable')
1864
1846
for var in variables:
1865
1847
name = var['name']
1866
print var.toString(), name
1848
print(var.toString(), name)
1867
1849
var['label'] = name
1868
1850
#var.xmlSetAttribute(label='truc')
1871
1853
#case.xmlRemoveChild('variable')
1875
1857
#-------------------------------------------------------------------------------