commit 43f163de80864a4918b1566c3fbc0b73aac6a327 Author: Nick Mathewson nickm@torproject.org Date: Wed Jul 17 14:30:12 2019 +0200
Practracker: improve exclude-directory logic
Instead of excluding directories at the last minute if they happen to appear in our filenames, we exclude them early, before recursing into all their subdirectories.
Part of 29746. --- scripts/maint/practracker/util.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/scripts/maint/practracker/util.py b/scripts/maint/practracker/util.py index b0ca73b99..5a8876a0f 100644 --- a/scripts/maint/practracker/util.py +++ b/scripts/maint/practracker/util.py @@ -2,15 +2,24 @@ import os
# We don't want to run metrics for unittests, automatically-generated C files, # external libraries or git leftovers. -EXCLUDE_SOURCE_DIRS = {"/src/test/", "/src/trunnel/", "/src/ext/", "/.git/"} +EXCLUDE_SOURCE_DIRS = {"src/test/", "src/trunnel/", "src/rust/", + "src/ext/", ".git/"} + +def _norm(p): + return os.path.normcase(os.path.normpath(p))
def get_tor_c_files(tor_topdir): """ Return a list with the .c filenames we want to get metrics of. """ files_list = [] + exclude_dirs = { _norm(os.path.join(tor_topdir, p)) for p in EXCLUDE_SOURCE_DIRS } +
for root, directories, filenames in os.walk(tor_topdir): + # Remove all the directories that are excluded. + directories[:] = [ d for d in directories + if _norm(os.path.join(root,d)) not in exclude_dirs ] directories.sort() filenames.sort() for filename in filenames: @@ -18,10 +27,7 @@ def get_tor_c_files(tor_topdir): if not filename.endswith(".c"): continue
- # Exclude the excluded paths full_path = os.path.join(root,filename) - if any(os.path.normcase(exclude_dir) in full_path for exclude_dir in EXCLUDE_SOURCE_DIRS): - continue
files_list.append(full_path)
tor-commits@lists.torproject.org