Go to the documentation of this file.00001 import xml.etree.ElementTree as ET
00002 import xml.dom.minidom
00003 from ros_topology import *
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 def parseFile(filename):
00018 return parseTree(ET.parse(filename))
00019
00020 def parseTree(tree):
00021 root = tree.getroot()
00022
00023 ros = RosSystemGraph()
00024
00025 for xmlNode in root.findall("node"):
00026
00027 node = Node(ros)
00028 node.name = xmlNode.attrib["name"].strip()
00029 node.location = xmlNode.attrib["location"].strip()
00030 node.pid = xmlNode.attrib["pid"].strip()
00031 print "Adding Node",node.name
00032
00033
00034
00035
00036 for xmlTopic in xmlNode.find("topics"):
00037 name = xmlTopic.attrib["name"]
00038 msgType = xmlTopic.attrib["type"]
00039
00040 topic = None
00041 if (name,msgType) not in ros.topics.keys():
00042 print "Adding Topic ",name,msgType
00043 topic = Topic(ros)
00044 topic.name = name
00045 topic.msgType = msgType
00046 else:
00047 topic = ros.topics[(name,msgType)]
00048
00049 if xmlTopic.tag == "publishes":
00050 print "Adding publisher",node.name,topic.name
00051 conn = Publisher(ros,node,topic)
00052 if xmlTopic.tag == "subscribes":
00053 print "Adding subscriber",node.name,topic.name
00054 conn = Subscriber(ros,node,topic)
00055 conn.bandwidth = int(xmlTopic.attrib["bw"].strip())
00056 conn.freq = int(xmlTopic.attrib["freq"].strip())
00057
00058 return ros