add_sick_scan_base_header.py
Go to the documentation of this file.
1 """
2  Searches recursive all files "*.h" and "*.hpp" and adds line "include \"sick_scan/sick_scan_base.h\" at the beginning of all files.
3 
4  Usage:
5  python3 add_sick_scan_base_header.py
6 
7 """
8 
9 import os
10 
11 # List and return all files in a folder recursively, see https://stackoverflow.com/questions/18394147/how-to-do-a-recursive-sub-folder-search-and-return-files-in-a-list
12 def scandirectory(dir, extensions, excludes):
13  subfolders, files = [], []
14  for f in os.scandir(dir):
15  is_excluded = False
16  for exclude in excludes:
17  if exclude in f.path:
18  is_excluded = True
19  break
20  if is_excluded:
21  continue
22  if f.is_dir():
23  subfolders.append(f.path.replace("\\","/"))
24  if f.is_file():
25  if os.path.splitext(f.name)[1].lower() in extensions:
26  files.append(f.path.replace("\\","/"))
27  for dir in list(subfolders):
28  f = scandirectory(dir, extensions, excludes)
29  files.extend(f)
30  return files
31 
32 # Run this script
33 if __name__ == '__main__':
34 
35  folder = "../.." # search all files "*.h" and "*.hpp" in <folder>
36  exclude_string = "#include \"sick_scan/sick_scan_base.h\"" # keep file untouched, if it starts with <exclude_string>
37  additional_line = "#include \"sick_scan/sick_scan_base.h\" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */\n" # add this line at the beginning of all files
38 
39  header_files = scandirectory(folder, [".h", ".hpp"], ["sick_scan_base.h", "sick_scan_api.h"])
40  for file in header_files:
41  content = ""
42  with open(file, "r") as f:
43  content = f.read()
44  if content != "" and not content.startswith(exclude_string):
45  with open(file, "w") as f:
46  f.write(additional_line)
47  f.write(content)
48  print("{}: added \"{} ...\"".format(file, additional_line[:37]))
49  else:
50  print("{}: skipped".format(file))
51  print("add_sick_scan_base_header.py finished.")
52 
roswrap::console::print
ROSCONSOLE_DECL void print(FilterBase *filter, void *logger, Level level, const char *file, int line, const char *function, const char *fmt,...) ROSCONSOLE_PRINTF_ATTRIBUTE(7
Don't call this directly. Use the ROS_LOG() macro instead.
add_sick_scan_base_header.scandirectory
def scandirectory(dir, extensions, excludes)
Definition: add_sick_scan_base_header.py:12


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:07