check-files: exclude .git and third-party files

Exclude ".git" directories anywhere. This avoids spurious errors in git
checkouts that contain branch names that look like a file
check-files.py would check.

Exclude "mbed-os" anywhere and "examples" from the root. Switch to the
new mechanism to exclude "yotta/module". These are directories where
we store third-party files that do not need to match our preferences.

Exclude "cov-int" from the root. Fix #1691
This commit is contained in:
Gilles Peskine 2018-09-28 11:48:10 +02:00
parent e04d4e6d13
commit c426352ec5

View file

@ -155,6 +155,12 @@ class IntegrityChecker(object):
".c", ".h", ".sh", ".pl", ".py", ".md", ".function", ".data", ".c", ".h", ".sh", ".pl", ".py", ".md", ".function", ".data",
"Makefile", "CMakeLists.txt", "ChangeLog" "Makefile", "CMakeLists.txt", "ChangeLog"
) )
self.excluded_directories = ['.git', 'mbed-os']
self.excluded_paths = list(map(os.path.normpath, [
'cov-int',
'examples',
'yotta/module'
]))
self.issues_to_check = [ self.issues_to_check = [
PermissionIssueTracker(), PermissionIssueTracker(),
EndOfFileNewlineIssueTracker(), EndOfFileNewlineIssueTracker(),
@ -179,12 +185,19 @@ class IntegrityChecker(object):
console = logging.StreamHandler() console = logging.StreamHandler()
self.logger.addHandler(console) self.logger.addHandler(console)
def prune_branch(self, root, d):
if d in self.excluded_directories:
return True
if os.path.normpath(os.path.join(root, d)) in self.excluded_paths:
return True
return False
def check_files(self): def check_files(self):
for root, dirs, files in sorted(os.walk(".")): for root, dirs, files in os.walk("."):
dirs[:] = sorted(d for d in dirs if not self.prune_branch(root, d))
for filename in sorted(files): for filename in sorted(files):
filepath = os.path.join(root, filename) filepath = os.path.join(root, filename)
if (os.path.join("yotta", "module") in filepath or if not filepath.endswith(self.files_to_check):
not filepath.endswith(self.files_to_check)):
continue continue
for issue_to_check in self.issues_to_check: for issue_to_check in self.issues_to_check:
if issue_to_check.should_check_file(filepath): if issue_to_check.should_check_file(filepath):