launch.py
Go to the documentation of this file.
00001 from xml.dom.minidom import parse
00002 from xml.parsers.expat import ExpatError
00003 import re
00004 
00005 
00006 class Launch:
00007     def __init__(self, rel_fn, file_path):
00008         self.rel_fn = rel_fn
00009         self.file_path = file_path
00010         try:
00011             self.tree = parse(self.file_path)
00012             self.test = len(self.tree.getElementsByTagName('test')) > 0
00013         except ExpatError:  # this is an invalid xml file
00014             self.test = False
00015 
00016     def get_node_pkgs(self):
00017         s = set()
00018         for node in self.tree.getElementsByTagName('node'):
00019             s.add(str(node.getAttribute('pkg')))
00020         return sorted(list(s))
00021 
00022     def get_include_pkgs(self):
00023         s = set()
00024         for node in self.tree.getElementsByTagName('include'):
00025             el = node.getAttribute('file')
00026             if 'find' in el:
00027                 i = el.index('find')
00028                 i2 = el.index(')', i)
00029                 s.add(el[i + 5:i2])
00030         return sorted(list(s))
00031 
00032     def get_misc_pkgs(self):
00033         s = set()
00034         xml_str = self.tree.toxml()
00035         for x in re.finditer('\$\(find ([^\)]*)\)', xml_str):
00036             s.add(x.group(1))
00037         # rosrun PKG (e.g. <param command="rosrun xacro xacro.py xacrofile.xacro" />
00038         for x in re.finditer('rosrun\s+(\w+)\s', xml_str):
00039             s.add(x.group(1))
00040         return s
00041 
00042     def get_dependencies(self):
00043         d = set()
00044         d.update(self.get_node_pkgs())
00045         d.update(self.get_include_pkgs())
00046         d.update(self.get_misc_pkgs())
00047         return sorted(list(d))
00048 
00049     def __repr__(self):
00050         return self.rel_fn


ros_introspection
Author(s):
autogenerated on Wed Jun 19 2019 19:21:34