1 # Future imports for Python 2.7, mandatory in 3.0
2 from __future__
import division
3 from __future__
import print_function
4 from __future__
import unicode_literals
8 # We don't want to run metrics for unittests, automatically-generated C files,
9 # external libraries or git leftovers.
10 EXCLUDE_SOURCE_DIRS
= {"src/test/", "src/trunnel/", "src/ext/" }
12 EXCLUDE_FILES
= {"orconfig.h"}
15 return os
.path
.normcase(os
.path
.normpath(p
))
17 def get_tor_c_files(tor_topdir
, include_dirs
=None):
19 Return a list with the .c and .h filenames we want to get metrics of.
22 exclude_dirs
= { _norm(os
.path
.join(tor_topdir
, p
)) for p
in EXCLUDE_SOURCE_DIRS
}
24 if include_dirs
is None:
25 topdirs
= [ tor_topdir
]
27 topdirs
= [ os
.path
.join(tor_topdir
, inc
) for inc
in include_dirs
]
29 for topdir
in topdirs
:
30 for root
, directories
, filenames
in os
.walk(topdir
):
31 # Remove all the directories that are excluded.
32 directories
[:] = [ d
for d
in directories
33 if _norm(os
.path
.join(root
,d
)) not in exclude_dirs
]
36 for filename
in filenames
:
37 # We only care about .c and .h files
38 if not (filename
.endswith(".c") or filename
.endswith(".h")):
40 if filename
in EXCLUDE_FILES
:
42 # Avoid editor temporary files
43 bname
= os
.path
.basename(filename
)
44 if bname
.startswith("."):
46 if bname
.startswith("#"):
49 full_path
= os
.path
.join(root
,filename
)
51 files_list
.append(full_path
)
56 """A file-like object that we can us to suppress output."""