find-german-comments: enable scanning subdirs

This makes it possible to scan sub directories, when you give them
as arguments to the script.

Also update the directory_whitelist.

Change-Id: I0a8468348fffe0814905d6f5602fad3f8d6b69e3
Reviewed-on: https://gerrit.libreoffice.org/25523
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
This commit is contained in:
Phillip Sz 2016-05-26 21:30:02 +02:00 committed by Miklos Vajna
parent 4aca087c7c
commit 02b666c477

View File

@ -224,12 +224,27 @@ class Parser:
""" """
checks each _tracked_ file in a directory recursively checks each _tracked_ file in a directory recursively
""" """
sock = os.popen(r"git ls-files '%s' |egrep '\.(c|cc|cpp|cxx|h|hxx|mm)$'" % directory) globalscan = False
if re.match(r'.*/core$', os.getcwd()) and directory == '.':
globalscan = True
# Change into the given dir, so "git ls-tree" does work.
# If we want to scan the current dir, we must not do so as we are already there.
if not globalscan and directory != '.':
currentdir = os.getcwd()
os.chdir(currentdir.split("core",1)[0] + "core/")
os.chdir(directory)
sock = os.popen(r"git ls-tree -r HEAD --name-only |egrep '\.(c|cc|cpp|cxx|h|hxx|mm)$'")
lines = sock.readlines() lines = sock.readlines()
sock.close() sock.close()
# Helps to speedup a global scan # Helps to speedup a global scan
directory_whitelist = { directory_whitelist = {
"ure" : 1,
"ios" : 1,
"bean" : 1,
"apple_remote" : 1,
"UnoControls" : 1, "UnoControls" : 1,
"accessibility" : 1, "accessibility" : 1,
"android" : 1, "android" : 1,
@ -351,18 +366,20 @@ class Parser:
"xmlscript" : 1, "xmlscript" : 1,
} }
if directory is '.': if globalscan:
sys.stderr.write("Overriding the white-list for the current directory - pass an absolute path to the top-level for faster global white-list searches.\n") print("Scanning all files globally:")
elif directory == '.':
print("Scanning all files in our current directory:")
else:
print("Scanning all files in", directory + ":")
num_checked = 0 num_checked = 0
for path in lines: for path in lines:
baseDir = self.first_elem(path) baseDir = self.first_elem(path)
# If we have an globalscan use the whitelist.
# Support searching within sub directories if globalscan:
if directory is '.': if not baseDir in directory_whitelist:
self.check_file(path.strip())
elif not baseDir in directory_whitelist:
sys.stderr.write ("\n - Error: Missing path %s -\n\n" % baseDir) sys.stderr.write ("\n - Error: Missing path %s -\n\n" % baseDir)
sys.exit(1) sys.exit(1)
elif directory_whitelist[baseDir] is 0: elif directory_whitelist[baseDir] is 0:
@ -371,6 +388,9 @@ class Parser:
elif directory_whitelist[baseDir] is 1: elif directory_whitelist[baseDir] is 1:
sys.stderr.write ("Skipping whitelisted directory %s\n" % baseDir) sys.stderr.write ("Skipping whitelisted directory %s\n" % baseDir)
directory_whitelist[baseDir] = 2 directory_whitelist[baseDir] = 2
elif not globalscan:
self.check_file(path.strip())
num_checked = num_checked + 1
sys.stderr.write ("Scanned %s files\n" % num_checked) sys.stderr.write ("Scanned %s files\n" % num_checked)