util.py 821 B

123456789101112131415161718192021222324252627
  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. for filename in filenames:
  12. # We only care about .c files
  13. if not filename.endswith(".c"):
  14. continue
  15. # Exclude the excluded paths
  16. full_path = os.path.join(root,filename)
  17. if any(exclude_dir in full_path for exclude_dir in EXCLUDE_SOURCE_DIRS):
  18. continue
  19. files_list.append(full_path)
  20. return files_list