Skip to content

Commit b10dda3

Browse files
committed
Added script for counting lines of code
1 parent 4553b96 commit b10dda3

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

scripts/count_lines/count_lines.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import glob
2+
import os
3+
4+
def count_lines(filename):
5+
f = open(filename, 'rb')
6+
lines = 0
7+
buf_size = 1024 * 1024
8+
read_f = f.raw.read
9+
buf = read_f(buf_size)
10+
while buf:
11+
lines += buf.count(b'\n')
12+
buf = read_f(buf_size)
13+
return lines
14+
15+
def count_files(extensions, name):
16+
line_counter = 0
17+
file_counter = 0
18+
if isinstance(extensions, str):
19+
extensions = [extensions]
20+
for extension in extensions:
21+
files = glob.glob(os.path.join('..', '..', '**', '*.' + extension), recursive=True)
22+
file_counter += len(files)
23+
for f in files:
24+
line_counter += count_lines(f)
25+
print((name + ':').ljust(12) + str(line_counter).ljust(6) + ' lines of codes in ' + str(file_counter).ljust(4) + ' files')
26+
27+
count_files(['cpp', 'hpp'], 'C++')
28+
count_files(['c', 'h'], 'C')
29+
count_files(['py'], 'Python')
30+
count_files('js', 'JavaScript')
31+
count_files('java', 'Java')
32+
count_files('m', 'MATLAB')
33+
count_files('vert', 'GLSL')

0 commit comments

Comments
 (0)