package.py
Go to the documentation of this file.
1 import collections
2 
3 from .cmake_parser import parse_file
4 from .launch import Launch
5 from .package_structure import get_package_structure
6 from .package_xml import PackageXML
7 from .plugin_xml import PluginXML
8 from .ros_generator import ROSGenerator
9 from .setup_py import SetupPy
10 from .source_code import SourceCode
11 from .urdf import UrdfFile
12 
13 
14 class Package:
15  def __init__(self, root):
16  self.root = root
17  self.manifest = PackageXML(self.root + '/package.xml')
18  self.name = self.manifest.name
19  self.cmake = parse_file(self.root + '/CMakeLists.txt')
20 
21  package_structure = get_package_structure(root)
22  self.source_code = SourceCode(package_structure['source'], self.name)
23  self.source_code.setup_tags(self.cmake)
24 
25  self.launches = []
26  self.plugin_configs = []
27  self.urdf_files = []
28  for rel_fn, file_path in package_structure['launch'].items():
29  self.launches.append(Launch(rel_fn, file_path))
30  for rel_fn, file_path in package_structure['plugin_config'].items():
31  self.plugin_configs.append(PluginXML(rel_fn, file_path))
32  for rel_fn, file_path in package_structure['urdf'].items():
33  self.urdf_files.append(UrdfFile(rel_fn, file_path))
34 
35  self.setup_py = None
36  if 'setup.py' in package_structure['key']:
37  self.setup_py = SetupPy(self.name, package_structure['key']['setup.py'])
38  self.generators = collections.defaultdict(list)
39  for rel_fn, path in package_structure['generators'].items():
40  gen = ROSGenerator(rel_fn, path)
41  self.generators[gen.type].append(gen)
42  self.dynamic_reconfigs = package_structure['cfg'].keys()
43  self.urdf_files = []
44  for rel_fn, path in package_structure['urdf'].items():
45  self.urdf_files.append(UrdfFile(rel_fn, path))
46  self.misc_files = list(package_structure[None].keys())
47 
48  def is_metapackage(self):
49  return self.manifest.is_metapackage() or self.cmake.is_metapackage()
50 
52  return self.source_code.get_build_dependencies()
53 
55  packages = set()
56  for launch in self.launches:
57  if launch.test:
58  continue
59  packages.update(launch.get_dependencies())
60 
61  for urdf in self.urdf_files:
62  packages.update(urdf.get_dependencies())
63 
64  if self.name in packages:
65  packages.remove(self.name)
66  return packages
67 
69  packages = set()
70  packages.update(self.source_code.get_test_dependencies())
71  for launch in self.launches:
72  if not launch.test:
73  continue
74  packages.add('rostest')
75  packages.update(launch.get_dependencies())
76  if self.name in packages:
77  packages.remove(self.name)
78  return packages
79 
80  def get_all_generators(self):
81  for gens in self.generators.values():
82  for gen in gens:
83  yield gen
84 
86  packages = set()
87  for gen in self.get_all_generators():
88  packages.update(gen.dependencies)
89  return packages
90 
91  def write(self):
92  self.manifest.write()
93  self.cmake.write()
94  for plugin_config in self.plugin_configs:
95  plugin_config.write()
96  if self.setup_py:
97  self.setup_py.write()
98  for gen in self.get_all_generators():
99  gen.write()
100  for src in self.source_code.sources.values():
101  src.write()
102 
103  def __repr__(self):
104  s = '== {} ========\n'.format(self.name)
105  s += ' package.xml\n'
106  s += ' CMakeLists.txt\n'
107  if self.setup_py:
108  s += ' setup.py\n'
109  components = {'source': str(self.source_code),
110  'launch': '\n'.join(map(str, self.launches)),
111  'dynamic reconfigure configs': '\n'.join(self.dynamic_reconfigs),
112  'plugin configs': '\n'.join([cfg.rel_fn for cfg in self.plugin_configs]),
113  'urdf models': '\n'.join(map(str, self.urdf_files)),
114  '{misc}': '\n'.join(self.misc_files)
115  }
116  for ext in self.generators:
117  components[ext] = '\n'.join(map(str, self.generators[ext]))
118  for name, c_str in sorted(components.items()):
119  if len(c_str) == 0:
120  continue
121  s += ' {}\n'.format(name)
122  for line in c_str.split('\n'):
123  s += ' ' + line + '\n'
124  return s


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