Skip to content

Commit 02f18c3

Browse files
committed
Cleaned up dataCounter.py.
1 parent 476c4ac commit 02f18c3

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

dataCounter.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
import subprocess
22
import sys
3-
import os
43

5-
rcmd = "( find ./ -name '*.%s' -print0 | xargs -0 cat ) | wc -l"
4+
rcmd = "( find ./ -type d -name .git -prune -o -name '*.%s' -print0 | xargs -0 cat ) | wc {}"
65
types = ['c', 'cpp', 'h', 'hpp', 'py', 'para', 'paracode', 'sh']
76

87
if len(sys.argv) > 1:
98
if sys.argv[1].lower() == "lines":
10-
rcmd = "( find ./ -name '*.%s' -print0 | xargs -0 cat ) | wc -l"
9+
rcmd = rcmd.format("-l")
1110
elif sys.argv[1].lower() == "chars":
12-
rcmd = "( find ./ -name '*.%s' -print0 | xargs -0 cat ) | wc -c"
11+
rcmd = rcmd.format("-c")
1312
elif sys.argv[1].lower() == "maxlinelength" or sys.argv[1].lower() == "max-line-length" or sys.argv[1].lower() == "mll":
14-
rcmd = "( find ./ -name '*.%s' -print0 | xargs -0 cat ) | wc -L"
13+
rcmd = rcmd.format("-L")
14+
elif sys.argv[1].lower() == "files":
15+
rcmd = "( find ./ -type d -name .git -prune -o -name '*.%s' -print ) | wc -l"
16+
else:
17+
rcmd = rcmd.format("-l")
18+
else:
19+
rcmd = rcmd.format("-l")
1520

1621
if len(sys.argv) > 2:
1722
if sys.argv[2].lower() == "c":
@@ -31,18 +36,9 @@
3136

3237
sum = 0
3338
for el in types:
34-
if len(sys.argv) > 1 and sys.argv[1].lower() != "files":
35-
cmd = rcmd % (el)
36-
p = subprocess.Popen([cmd],stdout=subprocess.PIPE,shell=True)
37-
out = int(p.stdout.read().strip())
38-
print("*.%s: %s" % (el, out))
39-
sum += out
40-
else:
41-
out = 0
42-
for root, dirs, files in os.walk(os.path.dirname(os.path.realpath(__file__))):
43-
for file in files:
44-
if file.endswith("." + el):
45-
out += 1
46-
print("*.%s: %s" % (el, out))
47-
sum += out
39+
cmd = rcmd % (el)
40+
p = subprocess.Popen([cmd],stdout=subprocess.PIPE,shell=True)
41+
out = int(p.stdout.read().strip())
42+
print("*.%s: %s" % (el, out))
43+
sum += out
4844
print("sum: %d" % (sum))

0 commit comments

Comments
 (0)