aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/line_count
diff options
context:
space:
mode:
authorGravatar ncteisen <ncteisen@gmail.com>2017-12-11 18:09:31 -0800
committerGravatar ncteisen <ncteisen@gmail.com>2017-12-11 18:10:00 -0800
commit5f8bf79bbf4915b928f75c83c66592b1fa97657e (patch)
tree38753ccc2a25774e87c27cd0af185e3d7c8cbe0a /tools/line_count
parent888093c6ed0d24eed699173b5fb35235fe7a6069 (diff)
yapf tools
Diffstat (limited to 'tools/line_count')
-rwxr-xr-xtools/line_count/collect-history.py25
-rwxr-xr-xtools/line_count/summarize-history.py17
-rwxr-xr-xtools/line_count/yaml2csv.py25
3 files changed, 38 insertions, 29 deletions
diff --git a/tools/line_count/collect-history.py b/tools/line_count/collect-history.py
index 3f030fbb8f..d2d5c95705 100755
--- a/tools/line_count/collect-history.py
+++ b/tools/line_count/collect-history.py
@@ -19,20 +19,23 @@ import datetime
# this script is only of historical interest: it's the script that was used to
# bootstrap the dataset
+
def daterange(start, end):
- for n in range(int((end - start).days)):
- yield start + datetime.timedelta(n)
+ for n in range(int((end - start).days)):
+ yield start + datetime.timedelta(n)
+
start_date = datetime.date(2017, 3, 26)
end_date = datetime.date(2017, 3, 29)
for dt in daterange(start_date, end_date):
- dmy = dt.strftime('%Y-%m-%d')
- sha1 = subprocess.check_output(['git', 'rev-list', '-n', '1',
- '--before=%s' % dmy,
- 'master']).strip()
- subprocess.check_call(['git', 'checkout', sha1])
- subprocess.check_call(['git', 'submodule', 'update'])
- subprocess.check_call(['git', 'clean', '-f', '-x', '-d'])
- subprocess.check_call(['cloc', '--vcs=git', '--by-file', '--yaml', '--out=../count/%s.yaml' % dmy, '.'])
-
+ dmy = dt.strftime('%Y-%m-%d')
+ sha1 = subprocess.check_output(
+ ['git', 'rev-list', '-n', '1', '--before=%s' % dmy, 'master']).strip()
+ subprocess.check_call(['git', 'checkout', sha1])
+ subprocess.check_call(['git', 'submodule', 'update'])
+ subprocess.check_call(['git', 'clean', '-f', '-x', '-d'])
+ subprocess.check_call([
+ 'cloc', '--vcs=git', '--by-file', '--yaml',
+ '--out=../count/%s.yaml' % dmy, '.'
+ ])
diff --git a/tools/line_count/summarize-history.py b/tools/line_count/summarize-history.py
index d2ef7ec324..80b0ed7a7e 100755
--- a/tools/line_count/summarize-history.py
+++ b/tools/line_count/summarize-history.py
@@ -13,22 +13,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-
import subprocess
import datetime
# this script is only of historical interest: it's the script that was used to
# bootstrap the dataset
+
def daterange(start, end):
- for n in range(int((end - start).days)):
- yield start + datetime.timedelta(n)
+ for n in range(int((end - start).days)):
+ yield start + datetime.timedelta(n)
+
start_date = datetime.date(2017, 3, 26)
end_date = datetime.date(2017, 3, 29)
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])
-
+ 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
index 2a38a12c80..dd2e92b360 100755
--- a/tools/line_count/yaml2csv.py
+++ b/tools/line_count/yaml2csv.py
@@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-
import yaml
import argparse
import datetime
@@ -21,18 +20,22 @@ 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(
+ '-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)
-
+ 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)