launch.py
Go to the documentation of this file.
1 import re
2 from xml.dom.minidom import parse
3 from xml.parsers.expat import ExpatError
4 
5 
6 class Launch:
7  def __init__(self, rel_fn, file_path):
8  self.rel_fn = rel_fn
9  self.file_path = file_path
10  try:
11  self.tree = parse(self.file_path)
12  self.test = len(self.tree.getElementsByTagName('test')) > 0
13  except ExpatError: # this is an invalid xml file
14  self.test = False
15 
16  def get_node_pkgs(self):
17  s = set()
18  for node in self.tree.getElementsByTagName('node'):
19  s.add(str(node.getAttribute('pkg')))
20  return sorted(s)
21 
22  def get_include_pkgs(self):
23  s = set()
24  for node in self.tree.getElementsByTagName('include'):
25  el = node.getAttribute('file')
26  if 'find' in el:
27  i = el.index('find')
28  i2 = el.index(')', i)
29  s.add(el[i + 5:i2])
30  return sorted(s)
31 
32  def get_misc_pkgs(self):
33  s = set()
34  xml_str = self.tree.toxml()
35  for x in re.finditer(r'\$\(find ([^\)]*)\)', xml_str):
36  s.add(x.group(1))
37  # rosrun PKG (e.g. <param command="rosrun xacro xacro.py xacrofile.xacro" />
38  for x in re.finditer(r'rosrun\s+(\w+)\s', xml_str):
39  s.add(x.group(1))
40  return s
41 
42  def get_dependencies(self):
43  d = set()
44  d.update(self.get_node_pkgs())
45  d.update(self.get_include_pkgs())
46  d.update(self.get_misc_pkgs())
47  return sorted(d)
48 
49  def __repr__(self):
50  return self.rel_fn
def __init__(self, rel_fn, file_path)
Definition: launch.py:7


ros_introspection
Author(s):
autogenerated on Wed Mar 3 2021 03:56:00