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


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