package.py
Go to the documentation of this file.
00001 import collections
00002 from package_structure import get_package_structure
00003 from package_xml import PackageXML
00004 from cmake_parser import parse_file
00005 from source_code import SourceCode
00006 from ros_generator import ROSGenerator
00007 from setup_py import SetupPy
00008 from launch import Launch
00009 from plugin_xml import PluginXML
00010 
00011 
00012 class Package:
00013     def __init__(self, root):
00014         self.root = root
00015         self.manifest = PackageXML(self.root + '/package.xml')
00016         self.name = self.manifest.name
00017         self.cmake = parse_file(self.root + '/CMakeLists.txt')
00018 
00019         package_structure = get_package_structure(root)
00020         self.source_code = SourceCode(package_structure['source'], self.name)
00021         self.source_code.setup_tags(self.cmake)
00022 
00023         self.launches = []
00024         self.plugin_configs = []
00025         for rel_fn, file_path in package_structure['launch'].iteritems():
00026             self.launches.append(Launch(rel_fn, file_path))
00027         for rel_fn, file_path in package_structure['plugin_config'].iteritems():
00028             self.plugin_configs.append(PluginXML(rel_fn, file_path))
00029 
00030         self.setup_py = None
00031         if 'setup.py' in package_structure['key']:
00032             self.setup_py = SetupPy(self.name, package_structure['key']['setup.py'])
00033         self.generators = collections.defaultdict(list)
00034         for rel_fn, path in package_structure['generators'].iteritems():
00035             gen = ROSGenerator(rel_fn, path)
00036             self.generators[gen.type].append(gen)
00037         self.dynamic_reconfigs = package_structure['cfg'].keys()
00038         self.misc_files = package_structure[None].keys()
00039 
00040     def get_build_dependencies(self):
00041         return self.source_code.get_build_dependencies()
00042 
00043     def get_run_dependencies(self):
00044         packages = set()
00045         for launch in self.launches:
00046             if launch.test:
00047                 continue
00048             packages.update(launch.get_dependencies())
00049 
00050         if self.name in packages:
00051             packages.remove(self.name)
00052         return packages
00053 
00054     def get_test_dependencies(self):
00055         packages = set()
00056         packages.update(self.source_code.get_test_dependencies())
00057         for launch in self.launches:
00058             if not launch.test:
00059                 continue
00060             packages.add('rostest')
00061             packages.update(launch.get_dependencies())
00062         if self.name in packages:
00063             packages.remove(self.name)
00064         return packages
00065 
00066     def get_all_generators(self):
00067         for gens in self.generators.values():
00068             for gen in gens:
00069                 yield gen
00070 
00071     def get_dependencies_from_msgs(self):
00072         packages = set()
00073         for gen in self.get_all_generators():
00074             packages.update(gen.dependencies)
00075         return packages
00076 
00077     def write(self):
00078         self.manifest.write()
00079         self.cmake.write()
00080         for plugin_config in self.plugin_configs:
00081             plugin_config.write()
00082         if self.setup_py:
00083             self.setup_py.write()
00084         for gen in self.get_all_generators():
00085             gen.write()
00086         for src in self.source_code.sources.values():
00087             src.write()
00088 
00089     def __repr__(self):
00090         s = '== {} ========\n'.format(self.name)
00091         s += '  package.xml\n'
00092         s += '  CMakeLists.txt\n'
00093         if self.setup_py:
00094             s += '  setup.py\n'
00095         components = {'source': str(self.source_code),
00096                       'launch': '\n'.join(map(str, self.launches)),
00097                       'dynamic reconfigure configs': '\n'.join(self.dynamic_reconfigs),
00098                       'plugin configs': '\n'.join([cfg.rel_fn for cfg in self.plugin_configs]),
00099                       '{misc}': '\n'.join(self.misc_files)
00100                       }
00101         for ext in self.generators:
00102             components[ext] = '\n'.join(map(str, self.generators[ext]))
00103         for name, c_str in sorted(components.iteritems()):
00104             if len(c_str) == 0:
00105                 continue
00106             s += '  {}\n'.format(name)
00107             for line in c_str.split('\n'):
00108                 s += '    ' + line + '\n'
00109         return s


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