util.py 890 B

12345678910111213141516171819202122232425262728
  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/ext/", "/.git/"}
  5. def get_tor_c_files(tor_topdir):
  6. """
  7. Return a list with the .c filenames we want to get metrics of.
  8. """
  9. files_list = []
  10. for root, directories, filenames in os.walk(tor_topdir):
  11. directories.sort()
  12. filenames.sort()
  13. for filename in filenames:
  14. # We only care about .c files
  15. if not filename.endswith(".c"):
  16. continue
  17. # Exclude the excluded paths
  18. full_path = os.path.join(root,filename)
  19. if any(os.path.normcase(exclude_dir) in full_path for exclude_dir in EXCLUDE_SOURCE_DIRS):
  20. continue
  21. files_list.append(full_path)
  22. return files_list