|
1 | 1 | import subprocess
|
2 | 2 | import sys
|
3 |
| -import os |
4 | 3 |
|
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 {}" |
6 | 5 | types = ['c', 'cpp', 'h', 'hpp', 'py', 'para', 'paracode', 'sh']
|
7 | 6 |
|
8 | 7 | if len(sys.argv) > 1:
|
9 | 8 | if sys.argv[1].lower() == "lines":
|
10 |
| - rcmd = "( find ./ -name '*.%s' -print0 | xargs -0 cat ) | wc -l" |
| 9 | + rcmd = rcmd.format("-l") |
11 | 10 | elif sys.argv[1].lower() == "chars":
|
12 |
| - rcmd = "( find ./ -name '*.%s' -print0 | xargs -0 cat ) | wc -c" |
| 11 | + rcmd = rcmd.format("-c") |
13 | 12 | 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") |
15 | 20 |
|
16 | 21 | if len(sys.argv) > 2:
|
17 | 22 | if sys.argv[2].lower() == "c":
|
|
31 | 36 |
|
32 | 37 | sum = 0
|
33 | 38 | 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 |
48 | 44 | print("sum: %d" % (sum))
|
0 commit comments