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


ros_introspection
Author(s):
autogenerated on Wed Jun 19 2019 19:56:52