aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-03-28 14:36:50 -0700
committerGravatar Craig Tiller <ctiller@google.com>2017-03-28 14:36:50 -0700
commite2e34b8812f36eafa4fb2391bd3eb72d17d9789d (patch)
treed1263a9dc6787ff239a65536e1254d95892e890c /tools
parent0fe74d35ee31ac3fb38fe647786b0b71629d64d0 (diff)
Line counter
Diffstat (limited to 'tools')
-rwxr-xr-xtools/line_count/summarize-history.py17
-rwxr-xr-xtools/line_count/yaml2csv.py24
2 files changed, 41 insertions, 0 deletions
diff --git a/tools/line_count/summarize-history.py b/tools/line_count/summarize-history.py
new file mode 100755
index 0000000000..edaaf6517b
--- /dev/null
+++ b/tools/line_count/summarize-history.py
@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+
+import subprocess
+import datetime
+
+def daterange(start, end):
+ for n in range(int((end - start).days)):
+ yield start + datetime.timedelta(n)
+
+start_date = datetime.date(2014, 11, 26)
+end_date = datetime.date(2017, 3, 26)
+
+for dt in daterange(start_date, end_date):
+ dmy = dt.strftime('%Y-%m-%d')
+ print dmy
+ subprocess.check_call(['tools/line_count/yaml2csv.py', '-i', '../count/%s.yaml' % dmy, '-d', dmy, '-o', '../count/%s.csv' % dmy])
+
diff --git a/tools/line_count/yaml2csv.py b/tools/line_count/yaml2csv.py
new file mode 100755
index 0000000000..159901ac41
--- /dev/null
+++ b/tools/line_count/yaml2csv.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+import yaml
+import argparse
+import datetime
+import csv
+
+argp = argparse.ArgumentParser(description='Convert cloc yaml to bigquery csv')
+argp.add_argument('-i', '--input', type=str)
+argp.add_argument('-d', '--date', type=str, default=datetime.date.today().strftime('%Y-%m-%d'))
+argp.add_argument('-o', '--output', type=str, default='out.csv')
+args = argp.parse_args()
+
+data = yaml.load(open(args.input).read())
+with open(args.output, 'w') as outf:
+ writer = csv.DictWriter(outf, ['date', 'name', 'language', 'code', 'comment', 'blank'])
+ for key, value in data.iteritems():
+ if key == 'header': continue
+ if key == 'SUM': continue
+ if key.startswith('third_party/'): continue
+ row = {'name': key, 'date': args.date}
+ row.update(value)
+ writer.writerow(row)
+