-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathwc.py
executable file
·37 lines (30 loc) · 1007 Bytes
/
wc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import division
import os
import io
def count_source(path, ext):
total = 0
for root, dirs, filenames in os.walk(path):
for filename in filenames:
if filename.endswith(ext):
filepath = os.path.join(root, filename)
with io.open(filepath, "r", encoding = "utf-8") as f:
lines = len(f.readlines())
print(filepath, ":", lines)
total += lines
return total
def main():
total = 0
total += count_source("src", ".cpp")
total += count_source("include", ".h")
total += count_source("tests", ".cpp")
total += count_source("contrib", ".cpp")
total += count_source("contrib", ".h")
total += count_source("docs", ".rst")
print("total:", total)
if __name__ == "__main__":
main()