source_code.py
Go to the documentation of this file.
1 import os.path
2 from source_code_file import SourceCodeFile
3 
4 
5 class SourceCode:
6  def __init__(self, filenames, pkg_name):
7  self.pkg_name = pkg_name
8  self.sources = {}
9  for rel_fn, file_path in filenames.iteritems():
10  self.sources[rel_fn] = SourceCodeFile(rel_fn, file_path)
11 
12  def has_header_files(self):
13  goal_folder = os.path.join('include', self.pkg_name)
14  for source_fn in self.sources:
15  if goal_folder in source_fn:
16  return True
17  return False
18 
19  def get_source_by_language(self, language):
20  return [source for source in self.sources.values() if source.language == language]
21 
22  def setup_tags(self, cmake):
23  for tag, files in [('library', cmake.get_library_source()),
24  ('executable', cmake.get_executable_source()),
25  ('test', cmake.get_test_source())]:
26  for fn in files:
27  if fn and fn[0] == '$':
28  continue
29  if fn in self.sources:
30  self.sources[fn].tags.add(tag)
31  else:
32  print(' File %s found in CMake not found in folder!' % fn)
33 
35  packages = set()
36  for source in self.sources.values():
37  if 'test' in source.tags:
38  continue
39  packages.update(source.get_dependencies())
40  if self.pkg_name in packages:
41  packages.remove(self.pkg_name)
42  return packages
43 
45  packages = set()
46  for source in self.sources.values():
47  if 'test' in source.tags:
48  continue
49  packages.update(source.get_external_python_dependencies())
50  return packages
51 
53  packages = set()
54  for source in self.sources.values():
55  if 'test' not in source.tags:
56  continue
57  packages.update(source.get_dependencies())
58  if self.pkg_name in packages:
59  packages.remove(self.pkg_name)
60  return packages
61 
62  def search_for_patterns(self, patterns, per_line=True):
63  files = {}
64  for source in self.sources.values():
65  if per_line:
66  matches = source.search_lines_for_patterns(patterns)
67  else:
68  matches = source.search_for_patterns(patterns)
69  if len(matches) != 0:
70  files[source.rel_fn] = matches
71  return files
72 
73  def search_for_pattern(self, pattern, per_line=True):
74  return self.search_for_patterns([pattern], per_line)
75 
76  def __repr__(self):
77  return '\n'.join(map(str, sorted(self.sources.values())))
def search_for_patterns(self, patterns, per_line=True)
Definition: source_code.py:62
def search_for_pattern(self, pattern, per_line=True)
Definition: source_code.py:73
def get_source_by_language(self, language)
Definition: source_code.py:19
def __init__(self, filenames, pkg_name)
Definition: source_code.py:6


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