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

This commit is contained in:
Jenkins 2014-08-13 13:42:27 +00:00 committed by Gerrit Code Review
commit 4861c486e8
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)