util.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import os
  2. # We don't want to run metrics for unittests, automatically-generated C files,
  3. # external libraries or git leftovers.
  4. EXCLUDE_SOURCE_DIRS = {"src/test/", "src/trunnel/", "src/rust/",
  5. "src/ext/", ".git/"}
  6. def _norm(p):
  7. return os.path.normcase(os.path.normpath(p))
  8. def get_tor_c_files(tor_topdir):
  9. """
  10. Return a list with the .c filenames we want to get metrics of.
  11. """
  12. files_list = []
  13. exclude_dirs = { _norm(os.path.join(tor_topdir, p)) for p in EXCLUDE_SOURCE_DIRS }
  14. for root, directories, filenames in os.walk(tor_topdir):
  15. # Remove all the directories that are excluded.
  16. directories[:] = [ d for d in directories
  17. if _norm(os.path.join(root,d)) not in exclude_dirs ]
  18. directories.sort()
  19. filenames.sort()
  20. for filename in filenames:
  21. # We only care about .c files
  22. if not filename.endswith(".c"):
  23. continue
  24. full_path = os.path.join(root,filename)
  25. files_list.append(full_path)
  26. return files_list