From 02f18c3c23085d1c0108a958d05451724c91e41c Mon Sep 17 00:00:00 2001 From: DaRubyMiner360 <55484201+DaRubyMiner360@users.noreply.github.com> Date: Tue, 19 Oct 2021 18:22:35 +0000 Subject: [PATCH] Cleaned up dataCounter.py. --- dataCounter.py | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/dataCounter.py b/dataCounter.py index 9f18918..442c8c0 100644 --- a/dataCounter.py +++ b/dataCounter.py @@ -1,17 +1,22 @@ import subprocess import sys -import os -rcmd = "( find ./ -name '*.%s' -print0 | xargs -0 cat ) | wc -l" +rcmd = "( find ./ -type d -name .git -prune -o -name '*.%s' -print0 | xargs -0 cat ) | wc {}" types = ['c', 'cpp', 'h', 'hpp', 'py', 'para', 'paracode', 'sh'] if len(sys.argv) > 1: if sys.argv[1].lower() == "lines": - rcmd = "( find ./ -name '*.%s' -print0 | xargs -0 cat ) | wc -l" + rcmd = rcmd.format("-l") elif sys.argv[1].lower() == "chars": - rcmd = "( find ./ -name '*.%s' -print0 | xargs -0 cat ) | wc -c" + rcmd = rcmd.format("-c") elif sys.argv[1].lower() == "maxlinelength" or sys.argv[1].lower() == "max-line-length" or sys.argv[1].lower() == "mll": - rcmd = "( find ./ -name '*.%s' -print0 | xargs -0 cat ) | wc -L" + rcmd = rcmd.format("-L") + elif sys.argv[1].lower() == "files": + rcmd = "( find ./ -type d -name .git -prune -o -name '*.%s' -print ) | wc -l" + else: + rcmd = rcmd.format("-l") +else: + rcmd = rcmd.format("-l") if len(sys.argv) > 2: if sys.argv[2].lower() == "c": @@ -31,18 +36,9 @@ sum = 0 for el in types: - if len(sys.argv) > 1 and sys.argv[1].lower() != "files": - cmd = rcmd % (el) - p = subprocess.Popen([cmd],stdout=subprocess.PIPE,shell=True) - out = int(p.stdout.read().strip()) - print("*.%s: %s" % (el, out)) - sum += out - else: - out = 0 - for root, dirs, files in os.walk(os.path.dirname(os.path.realpath(__file__))): - for file in files: - if file.endswith("." + el): - out += 1 - print("*.%s: %s" % (el, out)) - sum += out + cmd = rcmd % (el) + p = subprocess.Popen([cmd],stdout=subprocess.PIPE,shell=True) + out = int(p.stdout.read().strip()) + print("*.%s: %s" % (el, out)) + sum += out print("sum: %d" % (sum))