Skip to content

Commit

Permalink
check-against-linux.py: Add ignore list functionality
Browse files Browse the repository at this point in the history
Fixes issue #5.
  • Loading branch information
neuschaefer committed Apr 13, 2018
1 parent 1d14876 commit 5601b97
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ node.
- If your binding is already present in Linux's
[Documentation/devicetree/bindings][linux-bindings] directory, make sure you
use the same file name and relative path.
- If your binding is not present in Linux, add its name (including the path
leading up to it) to [bindings/not-in-linux.txt].
- If your vendor prefix is not yet in [vendor-prefixes.txt], make sure to add
it as soon as possible to avoid collisions and inconsistencies.
- Make a pull request
Expand Down
4 changes: 4 additions & 0 deletions bindings/not-in-linux.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file should list all files that are present in this bindings directory,
# but not in Linux's. check-against-linux.py can check its correctness.

not-in-linux.txt
50 changes: 41 additions & 9 deletions scripts/check-against-linux.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0+
# Copyright (C) 2017 Jonathan Neuschäfer
# Copyright (C) 2017-2018 Jonathan Neuschäfer

import sys, os, subprocess

# Scan statistics
class Stats:
def __init__(self, our_dir, linux_dir):
def __init__(self, our_dir, linux_dir, ignorelist=[]):
self.our_dir = our_dir
self.linux_dir = linux_dir
self.ignorelist = ignorelist
self.files_match = []
self.files_missing_in_linux = []
self.files_mismatch = []
self.files_missing_in_linux = []
self.files_ignored = []
self.files_ignored_but_present = []

def good(self):
return len(self.files_missing_in_linux) == 0 and \
Expand All @@ -20,18 +23,29 @@ def good(self):
def print_summary(self):
print("\nStatistics:")
if len(self.files_match) > 0:
print(" Matching : %d" % len(self.files_match))
print(" Matching : %d" % len(self.files_match))
if len(self.files_missing_in_linux) > 0:
print(" Missing in Linux : %d" % len(self.files_missing_in_linux))
print(" Missing in Linux : %d" % len(self.files_missing_in_linux))
if len(self.files_ignored) > 0:
print(" Ignored : %d" % len(self.files_ignored))
if len(self.files_ignored_but_present) > 0:
print(" Ignored but present : %d" % len(self.files_ignored_but_present))
if len(self.files_mismatch) > 0:
print(" Content mismatch : %d" % len(self.files_mismatch))
print(" Content mismatch : %d" % len(self.files_mismatch))

def match(self, filename):
self.files_match.append(filename)

def missing_in_linux(self, filename):
print("%s: File exists here but not in Linux" % filename)
self.files_missing_in_linux.append(filename)
if filename in self.ignorelist:
self.files_ignored.append(filename)
else:
print("%s: File exists here but not in Linux" % filename)
self.files_missing_in_linux.append(filename)

def ignored_but_present(self, filename):
print(("%s: Ignored but present in Linux. " +
"Consider removing it from not-in-linux.txt") % filename)

def mismatch(self, filename):
print("%s: Content mismatch" % filename)
Expand All @@ -56,6 +70,19 @@ def file_tree_walk(path):
def add_slash(path):
return os.path.normpath(path) + '/'

# Load the not-in-linux.txt ignore list file.
# path: The path of that file
def load_ignorelist(path):
try:
f = open(path)
text = f.read()
except FileNotFoundError:
return []

# Empty lines and lines starting with a '#' comment character are ignored
return [ line for line in text.splitlines() if
line != '' and line[0] != '#' ]

def main():
if len(sys.argv) != 3:
print(repr(sys.argv))
Expand All @@ -65,7 +92,9 @@ def main():
our_dir = add_slash(sys.argv[1])
linux_dir = add_slash(sys.argv[2])

stats = Stats(our_dir, linux_dir)
ignorelist = load_ignorelist(our_dir + "/not-in-linux.txt")

stats = Stats(our_dir, linux_dir, ignorelist)

for filename in file_tree_walk(our_dir):
our_f = open(our_dir + filename)
Expand All @@ -76,6 +105,9 @@ def main():
stats.missing_in_linux(filename)
continue

if filename in ignorelist:
stats.ignored_but_present(filename)

our_data = our_f.read()
linux_data = linux_f.read()

Expand Down

0 comments on commit 5601b97

Please sign in to comment.