def __init__(self, pkgdir): HtmlElement.__init__(self, tag=html.Sections.section, attrib={"class":"package"}) self._h2_index = 0 self._dep_pkg = None pkg_xml = None # Load and read package.xml ressource pkg_xml_dir = pkgdir+'/package.xml' if os.access(pkg_xml_dir, os.R_OK): pkg_xml = html.loadHtml(pkg_xml_dir) self._read_pkg_xml(pkgdir, pkg_xml) else: html.HTMLException("Cannot found %s !"%pkg_xml_dir, self) # Load and read CMakeLists.txt ressource cmakelists_dir = pkgdir+'/CMakeLists.txt' if os.access(cmakelists_dir, os.R_OK): with open(cmakelists_dir) as fp: cmakelists = fp.read() self._read_cmakelists(pkgdir, cmakelists) else: html.HTMLException("Cannot found %s !"%cmakelists_dir, self) if pkg_xml is not None: self._read_agi_doc_xml(pkgdir, pkg_xml)
def _read_topics(self, node, digraph): if node is None or node.tag != "topics": html.HTMLException("Invalid topics container !", self) return subs_dot_model = SubscribersModel() pubs_dot_model = PublishersModel() has_pub = False has_sub = False for child in node: if child.tag == "publisher": pubs_dot_model.addPublisher(child.attrib["name"], child.attrib["msg"]) has_pub = True elif child.tag == "subscriber": subs_dot_model.addSubscriber(child.attrib["name"], child.attrib["msg"]) has_sub = True else: print "Unknown topics tag '%s' !" % child.tag if has_pub is True: digraph.addNode(pubs_dot_model) digraph.connect(digraph.getRootNode(), pubs_dot_model) if has_sub is True: digraph.addNode(subs_dot_model) digraph.connect(subs_dot_model, digraph.getRootNode())
def _read_actionlibs(self, node, digraph): if node is None or node.tag != "actionlib": html.HTMLException("Invalid actionlib container !", self) return for child in node: if child.tag == "client": try: ns = ActionClientModel(child.attrib["name"], child.attrib["action"]) digraph.addNode(ns) digraph.connect(digraph.getRootNode(), ns, Edge(Edge.DIR, "both")) except: continue elif child.tag == "server": try: nc = ActionServerModel(child.attrib["name"], child.attrib["action"]) digraph.addNode(nc) digraph.connect(nc, digraph.getRootNode(), Edge(Edge.DIR, "both")) except: continue else: print "Unknown actionlibs tag '%s' !" % child.tag
def _read_agi_doc_xml(self, pkgdir, pkg_xml): agidoc_elem = pkg_xml.find("./export/agidoc") if agidoc_elem is not None: if 'src' in agidoc_elem.attrib: fdoc = os.path.join(pkgdir, agidoc_elem.attrib['src']) if os.path.isfile(fdoc): agi = AgiDoc() if agi.read(pkgdir, html.loadHtml(fdoc), self._h2_index+1) is True: title = HtmlElement(html.Sections.h2) title.text = "%i. More description"%self.index_h2() self.append(title) self.append(agi) else: html.HTMLException("Cannot open agidoc '%s'"%fdoc, self) else: html.HTMLException("AGI documentation not found !", self)
def _parse(self, launch_file, digraph): launch_name = launch_file.split('/')[-1].split('.')[0] root = None try: root = ElementTree.parse(launch_file) except Exception as ex: html.HTMLException(ex, self) return tree = root.getroot() for elem in tree: #<include file="$(find pma_startup)/launch/pma1_driver.launch" /> if elem.tag == 'include': include_split = elem.attrib["file"].split(")") prefix = include_split[0] pkg_name = prefix.split(" ")[-1] child = include_split[-1].split("/")[-1].split('.')[0] n1 = NODE(launch_name) n1.setAttrib(NODE.SHAPE, SHAPE.Box) n1.setAttrib(NODE.STYLE, STYLE.FILLED) n1.setAttrib(NODE.COLOR, RgbColor.LightGray) digraph.addNode(n1) n2 = NODE(child) n2.setAttrib(NODE.SHAPE, SHAPE.Box) n2.setAttrib(NODE.STYLE, STYLE.FILLED) n2.setAttrib(NODE.COLOR, RgbColor.LightGray) digraph.addNode(n2) digraph.connect(n1, n2) sub_launch = get_pkg_dir(pkg_name) + include_split[-1] self._parse(sub_launch, digraph) #<node name="map_server_high_res" pkg="map_server" type="map_server" args="$(arg map_file_high_res)" respawn="false"> elif elem.tag == "node": parent = launch_name child = Prefix.arg(elem.attrib["name"], tree) if parent == child: child += "_node" nd = NODE(child) nd.setAttrib(NODE.SHAPE, SHAPE.Ellipse) nd.setAttrib(NODE.STYLE, STYLE.FILLED) nd.setAttrib(NODE.COLOR, RgbColor.LightSeaGreen) digraph.addNode(nd) digraph.connect(parent, nd)
def __init__(self, index, pkg_dir, pkg_name): HtmlElementTree.__init__(self, index.getroot()) self._pkg_name = pkg_name div = self.getroot().find("./body/div") try: pkg = RosPackage(pkg_dir) div.append(pkg) except Exception as ex: html.HTMLException(ex, div)
def read(self, node_name, node_xml, isection, iarticle): item_index = 0 try: node_desc = NodeDescription() if node_desc.read(node_name, node_xml) is True: item_index += 1 title = HtmlElement(html.Sections.h4) title.text = "%i.%i.%i. Description"%(isection, iarticle, item_index) self.append(title) self.append(node_desc) except Exception as ex: html.HTMLException(ex,self) try: node_io = NodeInputOutput() if node_io.read(node_name, node_xml) is True: item_index += 1 title = HtmlElement(html.Sections.h4) title.text = "%i.%i.%i. Input/Output"%(isection, iarticle, item_index) self.append(title) self.append(node_io) except Exception as ex: html.HTMLException(ex,self) try: node_params = NodeParameters() if node_params.read(node_name, node_xml) is True: item_index += 1 title = HtmlElement(html.Sections.h4) title.text = "%i.%i.%i. Parameter(s)"%(isection, iarticle, item_index) self.append(title) self.append(node_params) except Exception as ex: html.HTMLException(ex,self) if item_index is 0: return False else: return True
def _read_pkg_xml(self, pkgdir, pkg_xml): pkg_name = HtmlElement(html.Sections.h1) pkg_name.text = pkg_xml.find("./name").text self.append(pkg_name) p = HtmlElement(html.Grouping.p) p.set("align","center") img = HtmlElement(html.EmbeddedContent.img) img.set("src","../dot/gen/%s.png"%pkg_xml.find("./name").text) p.append(img) self.append(p) pkg_summary_title = HtmlElement(html.Sections.h2) pkg_summary_title.text = "%i. Package Summary"%self.index_h2() self.append(pkg_summary_title) try: self.append(PackageSummary(pkgdir, pkg_xml)) except Exception as ex: html.HTMLException(ex, self) pkg_desc_title = HtmlElement(html.Sections.h2) pkg_desc_title.text = "%i. Package description"%self.index_h2() self.append(pkg_desc_title) try: self.append(PackageDescription(pkgdir, pkg_xml)) except Exception as ex: html.HTMLException(ex, self) pkg_dep_title = HtmlElement(html.Sections.h2) pkg_dep_title.text = "%i. Package dependencies"%self.index_h2() self.append(pkg_dep_title) try: self._dep_pkg = PackageDependencies(pkgdir, pkg_xml) self.append(self._dep_pkg) except Exception as ex: html.HTMLException(ex, self)
def _read_cmakelists(self, pkgdir, cmakefile): try: pkg = PackageGenerations() dep_list = self._dep_pkg.get_dependencies_lists() if pkg.read(pkgdir, cmakefile, dep_list) is True: pkg_build_title = HtmlElement(html.Sections.h2) pkg_build_title.text = "%i. Package generation(s)"%self.index_h2() self.append(pkg_build_title) self.append(pkg) except Exception as ex: html.HTMLException(ex, self)
def _read_services(self, node, digraph): if node is None or node.tag != "services": html.HTMLException("Invalid services container !", self) return for child in node: if child.tag == "client": print "Service client : ", child.attrib elif child.tag == "server": print "Service server : ", child.attrib else: print "Unknown services tag '%s' !" % child.tag
def __init__(self, index, packages_dir): HtmlElementTree.__init__(self, index.getroot()) div = self.getroot().find("./body/div") section = HtmlElement(html.Sections.section) #{ title = HtmlElement(html.Sections.h2) title.text = "1. Overview" section.append(title) aros_title = HtmlElement(html.Sections.h3) aros_title.text = "1.1 About ROS" section.append(aros_title) aros_article = HtmlElement(html.Sections.article) aros_article.text = """The Robot Operating System (ROS) is a flexible framework for writing robot software. It is a collection of tools, libraries, and conventions that aim to simplify the task of creating complex and robust robot behavior across a wide variety of robotic platforms.""" section.append(aros_article) ws_title = HtmlElement(html.Sections.h3) ws_title.text = "1.2 AGI ROS Workspace" section.append(ws_title) try: section.append(RosWorkspace(packages_dir)) except Exception as ex: html.HTMLException(ex, section) dev_title = HtmlElement(html.Sections.h3) dev_title.text = "1.3 Team" section.append(dev_title) ref_title = HtmlElement(html.Sections.h3) ref_title.text = "1.4 References" section.append(ref_title) #} div.append(section)
def read(self, pkgdir, agi_xml, index): index_node=0 for node_xml in agi_xml.iter('node'): index_node+=1 title = HtmlElement(html.Sections.h3) node_name = node_xml.attrib['name'] title.text = "%i.%i. %s"%(index, index_node, node_name) self.append(title) try: ros_node = RosNode() if ros_node.read(node_name, node_xml, index, index_node) is True: self.append(ros_node) except Exception as ex: html.HTMLException(ex, self) if index_node is 0: return False else: return True
def read(self, node_name, node_xml): digraph = self._create_digraph(node_name) for child in node_xml.find('io'): if child.tag == "topics": try: self._read_topics(child, digraph) except: continue elif child.tag == "actionlib": try: self._read_actionlibs(child, digraph) except: continue elif child.tag == "services": try: self._read_services(child, digraph) except: continue else: html.HTMLException( "Unknown io tag '%s' from node %s !" % (child.tag, node_name), self) digraph.saveDot(env.ROSDOC_DOT + "/io/%s.dot" % node_name) digraph.dotToPng(env.ROSDOC_DOT + "/io/%s.png" % node_name) p = HtmlElement(html.Grouping.p) p.set("align", "center") img = HtmlElement(html.EmbeddedContent.img) img.set("src", "../dot/io/%s.png" % node_name) p.append(img) self.append(p) return True
def __init__(self, index, launch_file): HtmlElementTree.__init__(self, index.getroot()) self._filename = launch_file.split("/")[-1] div = self.getroot().find("./body/div") section = HtmlElement(html.Sections.section) #{ title = HtmlElement(html.Sections.h1) title.text = self._filename.replace(".launch", "") section.append(title) diagram_title = HtmlElement(html.Sections.h2) diagram_title.text = "1. Launch diagram" section.append(diagram_title) roslaunch = HtmlElement(html.Grouping.p) roslaunch.text = """roslaunch is a tool for easily launching multiple ROS nodes locally and remotely via SSH, as well as setting parameters on the Parameter Server. It includes options to automatically respawn processes that have already died. roslaunch takes in one or more XML configuration files (with the .launch extension) that specify the parameters to set and nodes to launch, as well as the machines that they should be run on.""" section.append(roslaunch) try: launch_dot_generator = ConfigLaunch() launch_dot_generator.read(launch_file) section.append(launch_dot_generator) except Exception as ex: html.HTMLException(ex, section) #} div.append(section)
def read(self, pkgdir, f_cmake, dep_pkg_list): index = 0 pkg_name = pkgdir.split('/')[-1] digraph = self._create_digraph(pkg_name, dep_pkg_list) # p = HtmlElement(html.Grouping.p) # img = HtmlElement(html.EmbeddedContent.img) # img.set("src","resources/dot/gen/%s.png"%pkg_name) # # p.append(img) # self.append(p) try: msgs = MessageFilesGeneration() if msgs.read(pkgdir, f_cmake, digraph) is True: index += 1 title = HtmlElement(html.Sections.h3) title.text = "4.%i Message(s)" % index self.append(title) self.append(msgs) except Exception as ex: html.HTMLException(ex, self) try: ac = ActionFilesGeneration() if ac.read(pkgdir, f_cmake, digraph) is True: index += 1 title = HtmlElement(html.Sections.h3) title.text = "4.%i Action(s)" % index self.append(title) self.append(ac) except Exception as ex: html.HTMLException(ex, self) try: srv = ServiceFilesGeneration() if srv.read(pkgdir, f_cmake, digraph) is True: index += 1 title = HtmlElement(html.Sections.h3) title.text = "4.%i Service(s)" % index self.append(title) self.append(srv) except Exception as ex: html.HTMLException(ex, self) try: lib = LibrarieGeneration() if lib.read(pkgdir, f_cmake, digraph) is True: index += 1 title = HtmlElement(html.Sections.h3) title.text = "4.%i Librarie(s)" % index self.append(title) self.append(lib) except Exception as ex: html.HTMLException(ex, self) try: exe = ExecutableGeneration() if exe.read(pkgdir, f_cmake, digraph) is True: index += 1 title = HtmlElement(html.Sections.h3) title.text = "4.%i Executable(s)" % index self.append(title) self.append(exe) except Exception as ex: html.HTMLException(ex, self) try: pyexe = PyExecutableGeneration() if pyexe.read(pkgdir, pkg_name, digraph) is True: index += 1 title = HtmlElement(html.Sections.h3) title.text = "4.%i Python executable(s)" % index self.append(title) self.append(pyexe) except Exception as ex: html.HTMLException(ex, self) digraph.saveDot(env.ROSDOC_DOT + "/gen/%s.dot" % pkg_name) digraph.dotToPng(env.ROSDOC_DOT + "/gen/%s.png" % pkg_name) if index is 0: return False else: return True