-
Notifications
You must be signed in to change notification settings - Fork 4
/
tag_stats.py
executable file
·77 lines (61 loc) · 2.74 KB
/
tag_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python2.7
import shlex
import subprocess
import sys
import datetime
from utils import RELEASES, date_range
first = ('001407b969bc12d48bd7f10960f84f519bb19111', '2010-07-12')
today = datetime.datetime.now().strftime('%Y-%m-%d')
tags = [first] + [(tag, date) for (date, tag, cycle) in RELEASES] + [('master', today)]
tag_pairs = zip(*[tags[x::1] for x in (0, 1)])
trigger = 'Total Physical Source Lines of Code (SLOC)'
def stats_at_tag(tag):
code_line_count = 0
test_line_count = 0
cmd = 'git checkout %s' % tag
args = shlex.split(cmd)
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
cmd = 'git clean -fd'
args = shlex.split(cmd)
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
cmd = 'sloccount swift'
args = shlex.split(cmd)
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
raw, _ = p.communicate()
for line in raw.split('\n'):
if line.startswith(trigger):
raw_line_count = line.strip().rsplit('=', 1)[1].strip().replace(',', '')
code_line_count = int(raw_line_count)
cmd = 'sloccount test'
args = shlex.split(cmd)
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
raw, _ = p.communicate()
for line in raw.split('\n'):
if line.startswith(trigger):
raw_line_count = line.strip().rsplit('=', 1)[1].strip().replace(',', '')
test_line_count = int(raw_line_count)
try:
ratio = float(test_line_count) / float(code_line_count)
except ZeroDivisionError:
ratio = '-'
return code_line_count, test_line_count, ratio
# code_line_count, test_line_count, ratio = stats_at_tag(tags[0])
# print tags[0], '-', '-', code_line_count, test_line_count, ratio
initial_code, initial_test, initial_ratio = stats_at_tag(first[0])
total_lines = initial_code + initial_test
all_rows = []
row = [first[1], 'Initial Commit', '', total_lines, initial_code, initial_test, initial_ratio, -initial_test]
print ','.join(str(x) for x in row)
for ((start_tag, d1), (end_tag, d2)) in tag_pairs:
cmd = 'git diff --shortstat %s..%s' % (start_tag, end_tag)
args = shlex.split(cmd)
p = subprocess.Popen(args, stdout=subprocess.PIPE)
raw, _ = p.communicate()
file_count, insertions, deletions = raw.strip().split(',')
insertions = int(insertions.strip().split(' ', 1)[0])
deletions = int(deletions.strip().split(' ', 1)[0])
line_change = insertions - deletions
total_lines += line_change
code_line_count, test_line_count, ratio = stats_at_tag(end_tag)
row = [d2, end_tag, line_change, total_lines, code_line_count, test_line_count, ratio, -test_line_count]
print ','.join(str(x) for x in row)