Skip to content

Instantly share code, notes, and snippets.

@ahcorde
Created August 10, 2020 07:39
Show Gist options
  • Save ahcorde/bcc558aedad8560cfa46c4b5de366f32 to your computer and use it in GitHub Desktop.
Save ahcorde/bcc558aedad8560cfa46c4b5de366f32 to your computer and use it in GitHub Desktop.
test_cpplint_exclude.py
import pathlib
import os
def is_file_or_directory_to_exclude(path_to_file, excludes):
if not os.path.isdir(path_to_file):
path, file_name = os.path.split(path_to_file)
else:
path = path_to_file
file_name = ''
path_to_check = pathlib.Path(path_to_file)
def check_path_parents(parents, exclude):
for p in parents:
if p.match(exclude):
return True
return False
for excl in excludes:
if (
excl == file_name or
path_to_check.match(excl) or
check_path_parents(path_to_check.parents, excl)
):
print('Skipping ' + path_to_file)
return True
return False
def get_file_groups(paths, extensions, excludes):
# dict mapping root path to files
groups = {}
for path in paths:
if os.path.isdir(path):
for dirpath, dirnames, filenames in os.walk(path):
if is_file_or_directory_to_exclude(dirpath, excludes):
print(dirpath)
continue
if 'AMENT_IGNORE' in dirnames + filenames:
dirnames[:] = []
continue
# ignore folder starting with . or _
dirnames[:] = [d for d in dirnames if d[0] not in ['.', '_']]
dirnames[:] = [
d for d in dirnames if not is_file_or_directory_to_exclude(
os.path.join(dirpath, d), excludes)
]
dirnames.sort()
# select files by extension
for filename in sorted(filenames):
_, ext = os.path.splitext(filename)
if ext in ('.%s' % e for e in extensions):
if is_file_or_directory_to_exclude(
os.path.join(dirpath, filename), excludes):
pass
if os.path.isfile(path):
if is_file_or_directory_to_exclude(path, excludes):
pass
return groups
path = '/tmp/test_path/tf2'
path_folders = ['src', 'include/tf2', 'include/tf2/LinearMath', 'include/tf2/impl', 'test']
files_in_folder = []
files_in_folder.append([
'buffer_core.cpp',
'cache.cpp',
'static_cache.cpp',
'time.cpp',
])
files_in_folder.append([
'buffer_core.h',
'buffer_core_interface.h',
'convert.h',
'exceptions.h',
'time_cache.h',
'time.h',
'transform_datatypes.h',
'transform_storage.h',
'utils.h',
'visibility_control.h',
])
files_in_folder.append([
'Matrix3x3.h',
'MinMax.h',
'QuadWord.h',
'Quaternion.h',
'Scalar.h',
'Transform.h',
'Vector3.h',
])
files_in_folder.append([
'convert.h',
'utils.h',
])
files_in_folder.append([
'cache_unittest.cpp',
'simple_tf2_core.cpp',
'speed_test.cpp',
'static_cache_test.cpp',
'test_time.cpp',
])
if not os.path.exists(path):
os.makedirs(path)
for folder, files in zip(path_folders, files_in_folder):
directory = path + '/' + folder
if not os.path.exists(directory):
os.makedirs(directory)
for file in files:
with open(directory + '/' + file, 'w') as fp:
pass
get_file_groups(
[path],
['cpp', 'hpp'],
['test_time.cpp', 'tf2/LinearMath', 'impl', 'test/cache_unittest.cpp']
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment