source_code.py
Go to the documentation of this file.
00001 import os.path
00002 from source_code_file import SourceCodeFile
00003 
00004 
00005 class SourceCode:
00006     def __init__(self, filenames, pkg_name):
00007         self.pkg_name = pkg_name
00008         self.sources = {}
00009         for rel_fn, file_path in filenames.iteritems():
00010             self.sources[rel_fn] = SourceCodeFile(rel_fn, file_path)
00011 
00012     def has_header_files(self):
00013         goal_folder = os.path.join('include', self.pkg_name)
00014         for source_fn in self.sources:
00015             if goal_folder in source_fn:
00016                 return True
00017         return False
00018 
00019     def get_source_by_language(self, language):
00020         return [source for source in self.sources.values() if source.language == language]
00021 
00022     def setup_tags(self, cmake):
00023         for tag, files in [('library', cmake.get_library_source()),
00024                            ('executable', cmake.get_executable_source()),
00025                            ('test', cmake.get_test_source())]:
00026             for fn in files:
00027                 if fn and fn[0] == '$':
00028                     continue
00029                 if fn in self.sources:
00030                     self.sources[fn].tags.add(tag)
00031                 else:
00032                     print('    File %s found in CMake not found in folder!' % fn)
00033 
00034     def get_build_dependencies(self):
00035         packages = set()
00036         for source in self.sources.values():
00037             if 'test' in source.tags:
00038                 continue
00039             packages.update(source.get_dependencies())
00040         if self.pkg_name in packages:
00041             packages.remove(self.pkg_name)
00042         return packages
00043 
00044     def get_external_python_dependencies(self):
00045         packages = set()
00046         for source in self.sources.values():
00047             if 'test' in source.tags:
00048                 continue
00049             packages.update(source.get_external_python_dependencies())
00050         return packages
00051 
00052     def get_test_dependencies(self):
00053         packages = set()
00054         for source in self.sources.values():
00055             if 'test' not in source.tags:
00056                 continue
00057             packages.update(source.get_dependencies())
00058         if self.pkg_name in packages:
00059             packages.remove(self.pkg_name)
00060         return packages
00061 
00062     def search_for_patterns(self, patterns, per_line=True):
00063         files = {}
00064         for source in self.sources.values():
00065             if per_line:
00066                 matches = source.search_lines_for_patterns(patterns)
00067             else:
00068                 matches = source.search_for_patterns(patterns)
00069             if len(matches) != 0:
00070                 files[source.rel_fn] = matches
00071         return files
00072 
00073     def search_for_pattern(self, pattern, per_line=True):
00074         return self.search_for_patterns([pattern], per_line)
00075 
00076     def __repr__(self):
00077         return '\n'.join(map(str, sorted(self.sources.values())))


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