give find_files() a filename tester function arg
This commit is contained in:
parent
f5f6d99cd7
commit
cab1b81026
1 changed files with 12 additions and 7 deletions
19
script/cpplint.py
vendored
19
script/cpplint.py
vendored
|
@ -73,24 +73,29 @@ def main():
|
||||||
os.chdir(SOURCE_ROOT)
|
os.chdir(SOURCE_ROOT)
|
||||||
files = find_files('atom',
|
files = find_files('atom',
|
||||||
['app', 'browser', 'common', 'renderer', 'utility'],
|
['app', 'browser', 'common', 'renderer', 'utility'],
|
||||||
['*.cc', '*.h'])
|
is_cpp_file)
|
||||||
files += find_files('brightray', ['browser', 'common'], ['*.cc', '*.h'])
|
files |= find_files('brightray', ['browser', 'common'], is_cpp_file)
|
||||||
files -= set(IGNORE_FILES)
|
files -= set(IGNORE_FILES)
|
||||||
if args.only_changed:
|
if args.only_changed:
|
||||||
files &= find_changed_files()
|
files &= find_changed_files()
|
||||||
call_cpplint(list(files))
|
call_cpplint(list(files))
|
||||||
|
|
||||||
|
|
||||||
def find_files(parent, directories, filters):
|
def find_files(root, directories, test):
|
||||||
matches = set()
|
matches = set()
|
||||||
for directory in directories:
|
for directory in directories:
|
||||||
for root, _, filenames, in os.walk(os.path.join(parent, directory)):
|
for parent, _, children, in os.walk(os.path.join(root, directory)):
|
||||||
for f in filters:
|
for child in children:
|
||||||
for filename in fnmatch.filter(filenames, f):
|
filename = os.path.join(parent,child)
|
||||||
matches.add(os.path.join(root, filename))
|
if test(filename):
|
||||||
|
matches.add(filename)
|
||||||
return matches
|
return matches
|
||||||
|
|
||||||
|
|
||||||
|
def is_cpp_file(filename):
|
||||||
|
return filename.endswith('.cc') or filename.endswith('.h')
|
||||||
|
|
||||||
|
|
||||||
def find_changed_files():
|
def find_changed_files():
|
||||||
return set(execute(['git', 'diff', '--name-only']).splitlines())
|
return set(execute(['git', 'diff', '--name-only']).splitlines())
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue