21 from omniORB
import CORBA
22 from xml.dom.minidom
import parse
23 from xml.dom.minidom
import getDOMImplementation
25 import RtmDtdValidator
36 self.outfilename = outfilename
38 print "outfilename:",self.outfilename
39 self.outfile = open(self.outfilename,
"w")
40 self.outfile.write(self.cur_node.toxml())
41 self.outfile.write(
"\n")
48 print(self.cur_node.toxml())
53 return self.the_root_node
63 self.cur_node = self.the_root_node
67 self.node_list = self.cur_node.childNodes
71 self.node_list = self.cur_node.getElementsByTagName(tg)
76 nodes = self.cur_node.childNodes
79 if node.nodeType == node.TEXT_NODE:
84 tmp_node = self.dom.createTextNode(txt)
85 self.cur_node.childNodes = [tmp_node]
89 nodes = self.cur_node.getElementsByTagName(tg)[0]
92 rc = self.getText(nodes.childNodes)
97 nodes = self.cur_node.getElementsByTagName(tg)
99 tmp_node = self.dom.createTextNode(txt)
100 tmp_root.childNodes = [tmp_node]
105 self.cur_node.removeChild(nd)
109 tmp_elem = self.dom.createElement(tg)
110 tmp_txt = self.dom.createTextNode(txt)
111 tmp_elem.appendChild(tmp_txt)
112 self.cur_node.appendChild(tmp_elem)
117 tmp_elem = self.dom.createElement(tg)
118 self.cur_node.appendChild(tmp_elem)
125 self.tmp_node_list = lst
129 return self.tmp_node_list[idx];
136 comp_list = self.the_root_node.getElementsByTagName(
"rt_component")
144 for comp_node
in comp_list:
146 tmp1 = comp_node.getElementsByTagName(
"host_name")[0]
147 tmp1 = self.getText(tmp.childNodes)
148 tmp2 = comp_node.getElementsByTagName(
"manager_name")[0]
149 tmp2 = self.getText(tmp.childNodes)
150 tmp3 = comp_node.getElementsByTagName(
"category")[0]
151 tmp3 = self.getText(tmp.childNodes)
152 tmp4 = comp_node.getElementsByTagName(
"module_name")[0]
153 tmp4 = self.getText(tmp.childNodes)
154 tmp5 = comp_node.getElementsByTagName(
"component_name")[0]
155 tmp5 = self.getText(tmp.childNodes)
157 tmp = tmp1 +
"/" + tmp2 +
"/" + tmp3 +
"/" + tmp4 +
"/" + tmp5
162 if tmp1 ==
'' or tmp2 ==
'' or tmp3 ==
'' or tmp4 ==
'' or tmp5 ==
'':
164 print "Component Name is not an" 165 print self.infilename
167 self.cur_node = comp_node
173 comp_list = self.the_root_node.getElementsByTagName(
"rt_component")
175 save_node = self.get_cur_node()
176 for comp_node
in comp_list:
177 self.set_cur_node(comp_node)
178 tmp = self.getTaggedText(
"component_name")
180 self.set_cur_node(save_node)
185 comp_list = self.the_root_node.getElementsByTagName(
"rt_component")
187 save_node = self.get_cur_node()
188 for comp_node
in comp_list:
189 self.set_cur_node(comp_node)
190 tmp = self.getTaggedText(
"component_name")
192 tmp1 = self.getTaggedText(
"host_name")
193 tmp2 = self.getTaggedText(
"manager_name")
194 tmp3 = self.getTaggedText(
"category")
195 tmp4 = self.getTaggedText(
"module_name")
196 tmp5 = self.getTaggedText(
"component_name")
197 nam = tmp1 +
"/" + tmp2 +
"/" + tmp3 +
"/" + tmp4 +
"/" + tmp5
200 self.set_cur_node(save_node)
207 self.infilename = in_name
209 self.dom = parse(self.infilename)
210 self.the_root_node = self.dom
216 rtc_list = self.getTaggedNodes(
'rtc_list')[0]
217 self.set_cur_node(rtc_list)
218 comp_list = self.getChildNodes()
219 for comp_node
in comp_list:
220 self.set_cur_node(comp_node)
221 name = self.getTaggedText(
'name')
222 name_elem = self.getTaggedNodes(
'name')[0]
223 x = string.atof(name_elem.getAttribute(
'x'))
224 y = string.atof(name_elem.getAttribute(
'y'))
225 rot = name_elem.getAttribute(
'rot')
227 dict[
'rtc'][name] = {}
228 dict[
'rtc'][name][
'x'] = x
229 dict[
'rtc'][name][
'y'] = y
230 dict[
'rtc'][name][
'rot'] = rot
233 line_list = self.getTaggedNodes(
'line_list')[0]
234 self.set_cur_node(line_list)
235 lines = self.getChildNodes()
236 for line_node
in lines:
237 self.set_cur_node(line_node)
238 pos = self.getTaggedText(
'pos')
239 inp_comp = self.getTaggedText(
'inp-comp')
240 inp_name = self.getTaggedText(
'inp-name')
241 outp_comp = self.getTaggedText(
'outp-comp')
242 outp_name = self.getTaggedText(
'outp-name')
245 tmp[
'in-comp'] = inp_comp
246 tmp[
'in-name'] = inp_name
247 tmp[
'out-comp'] = outp_comp
248 tmp[
'out-name'] = outp_name
256 impl = getDOMImplementation()
257 doc = impl.createDocument(
None,
"rt_system",
None)
258 top_elem = doc.documentElement
264 comp_list = dict[
'rtc'].
keys()
265 elemRtcList = doc.createElement(
"rtc_list")
266 top_elem.appendChild(elemRtcList)
267 for comp_name
in comp_list:
268 elem = doc.createElement(
"rt_component")
269 elemRtcList.appendChild(elem)
270 elemName = doc.createElement(
"name")
271 elem.appendChild(elemName)
272 child = doc.createTextNode(comp_name)
273 elemName.appendChild(child)
274 elemName.setAttribute(
'x',
'%f'%dict[
'rtc'][comp_name][
'x'])
275 elemName.setAttribute(
'y',
'%f'%dict[
'rtc'][comp_name][
'y'])
276 elemName.setAttribute(
'rot',dict[
'rtc'][comp_name][
'rot'])
278 elemLineList = doc.createElement(
"line_list")
279 top_elem.appendChild(elemLineList)
280 line_list = dict[
'line']
281 for line
in line_list:
282 elem = doc.createElement(
"line")
283 elemLineList.appendChild(elem)
285 for pos
in line[
'pos']:
286 str +=
'%f,%f,'%(pos[0],pos[1])
288 elemPos = doc.createElement(
"pos")
289 elem.appendChild(elemPos)
290 child = doc.createTextNode(str)
291 elemPos.appendChild(child)
293 elemInComp = doc.createElement(
"inp-comp")
294 elemInName = doc.createElement(
"inp-name")
295 elem.appendChild(elemInComp)
296 elem.appendChild(elemInName)
297 child = doc.createTextNode(line[
'in-comp'])
298 elemInComp.appendChild(child)
299 child = doc.createTextNode(line[
'in-name'])
300 elemInName.appendChild(child)
302 elemOutComp = doc.createElement(
"outp-comp")
303 elemOutName = doc.createElement(
"outp-name")
304 elem.appendChild(elemOutComp)
305 elem.appendChild(elemOutName)
306 child = doc.createTextNode(line[
'out-comp'])
307 elemOutComp.appendChild(child)
308 child = doc.createTextNode(line[
'out-name'])
309 elemOutName.appendChild(child)
313 outfile = open(filename,
"w")
314 doc.writexml(outfile)
320 self.infilename =
None 321 self.outfilename =
None
def dump2file(self, outfilename=None)
def readXML(self, in_name)
def getComponentKeys(self)
def getComponentNames(self)
def getComponentNode(self, comp_key)
def appendChildTagged(self, tg)
def appendChildTaggedText(self, tg, txt)
void append(SDOPackage::NVList &dest, const SDOPackage::NVList &src)
Append an element to NVList.
def set_cur_node(self, nd)
def getTaggedText(self, tg)
def removeChildNode(self, nd)
def writeXML(self, filename, dict)
def getText(self, nodes=None)
def replaceText(self, txt)
def set_tmplist(self, lst)
def replaceTaggedText(self, tg, txt)
def getTaggedNodes(self, tg)