Add parameter --ignore-path to ignore files/directories

If the path is a file the file will not be checked for style
issues.

If the path is a directory all files inside this directory or
subdirectories will not be checked for style issues.

Change-Id: Ic40f798fb65804844e545de72263c44a8a603a40
This commit is contained in:
Christian Berendt 2014-08-13 15:12:49 +02:00
parent 7e28ba6c44
commit 5fb44c1213
2 changed files with 16 additions and 3 deletions

View File

@ -144,6 +144,8 @@ def main():
help="ignore the given errors code/codes",
type=split_set_type,
default=[])
parser.add_argument("--ignore-path", action="append", default=[],
help="ignore the given directory or file")
parser.add_argument("--max-line-length", action="store", metavar="int",
type=int,
help="maximum allowed line"
@ -164,8 +166,12 @@ def main():
args['extension'] = list(FILE_PATTERNS)
files = collections.deque()
ignored_paths = []
for path in args.pop('ignore_path', []):
ignored_paths.append(os.path.normpath(path))
for filename in utils.find_files(args.pop('paths', []),
args.pop('extension', [])):
args.pop('extension', []),
ignored_paths):
files.append(file_parser.parse(filename))
ignoreables = frozenset(args.pop('ignore', []))

View File

@ -17,22 +17,29 @@
import os
def find_files(paths, extensions):
def find_files(paths, extensions, ignored_paths):
extensions = set(extensions)
def extension_matches(path):
_base, ext = os.path.splitext(path)
return ext in extensions
def path_ignored(path):
return os.path.normpath(path) in ignored_paths
for path in paths:
if path_ignored(path):
continue
if os.path.isfile(path):
if extension_matches(path):
yield path
elif os.path.isdir(path):
for root, dirnames, filenames in os.walk(path):
if path_ignored(root):
continue
for filename in filenames:
path = os.path.join(root, filename)
if extension_matches(path):
if extension_matches(path) and not path_ignored(path):
yield path
else:
raise IOError('Invalid path: %s' % path)