package_structure.py
Go to the documentation of this file.
1 import collections
2 import os
3 
4 from .source_code_file import is_python_hashbang_line
5 
6 KEY = ['package.xml', 'CMakeLists.txt', 'setup.py']
7 SRC_EXTS = ['.py', '.cpp', '.h', '.hpp', '.c']
8 GENERATORS = ['.msg', '.srv', '.action']
9 
10 
11 def get_filetype_by_contents(filename, ext):
12  with open(filename) as f:
13  try:
14  first_line = f.readline()
15  except UnicodeDecodeError:
16  return
17  if is_python_hashbang_line(first_line):
18  return 'source'
19  elif '<launch' in first_line:
20  return 'launch'
21  elif ext == '.xml' and ('<library' in first_line or '<class_libraries' in first_line):
22  return 'plugin_config'
23 
24 
25 def get_package_structure(pkg_root):
26  structure = collections.defaultdict(dict)
27 
28  for root, dirs, files in os.walk(pkg_root):
29  if '.git' in root or '.svn' in root:
30  continue
31  for fn in files:
32  ext = os.path.splitext(fn)[-1]
33  full = '%s/%s' % (root, fn)
34  rel_fn = full.replace(pkg_root + '/', '')
35 
36  if fn[-1] == '~' or fn[-4:] == '.pyc':
37  continue
38  if fn in KEY:
39  structure['key'][rel_fn] = full
40  elif ext in SRC_EXTS:
41  structure['source'][rel_fn] = full
42  elif ext == '.launch':
43  structure['launch'][rel_fn] = full
44  elif ext in GENERATORS:
45  structure['generators'][rel_fn] = full
46  elif ext == '.cfg' and 'cfg/' in full:
47  structure['cfg'][rel_fn] = full
48  elif ext in ['.urdf', '.xacro']:
49  structure['urdf'][rel_fn] = full
50  else:
51  structure[get_filetype_by_contents(full, ext)][rel_fn] = full
52  return structure


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