-
Notifications
You must be signed in to change notification settings - Fork 1
/
codelines.py
31 lines (16 loc) · 847 Bytes
/
codelines.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#script to get number of C/C++ and Python code lines in project
import os
num_cpp_lines = int(0)
num_cpp_header_lines = int(0)
num_python_lines = int(0)
for root, dirs, files in os.walk("."):
for filename in files:
if filename.lower().endswith(('.c', '.cpp', 'cxx', 'c++', 'cc')):
num_cpp_lines += sum(1 for line in open(os.path.join(root, filename)))
if filename.lower().endswith(('.h', '.hpp', '.hxx', '.h++', '.hh')):
num_cpp_header_lines += sum(1 for line in open(os.path.join(root, filename)))
if filename.lower().endswith(('.py', '.pyw', '.pyc', '.pyo', '.pyd')):
num_python_lines += sum(1 for line in open(os.path.join(root, filename)))
print('Number of C/C++ code lines: ', num_cpp_lines)
print('Number of C/C++ header code lines: ', num_cpp_header_lines)
print('Number of Python lines: ', num_python_lines)