Created
May 6, 2012 05:01
-
-
Save kaezarrex/2615222 to your computer and use it in GitHub Desktop.
Line Length
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
from collections import defaultdict | |
from os import walk | |
from os.path import join | |
from subprocess import check_output | |
args = ['git', 'blame', '-p'] | |
authors = defaultdict(list) | |
for root, dirs, files in walk('.'): | |
python_files = (join(root, f) for f in files if f[-3:] == '.py') | |
for p in python_files: | |
author = None | |
record = False | |
blame = check_output(args + [p]) | |
lines = (line for line in blame.splitlines()) | |
for line in lines: | |
if line[:7] == 'author ': | |
author = line[7:] | |
record = False | |
if line[:9] == 'filename ': | |
record = True | |
try: | |
line = lines.next() | |
except StopIteration: | |
break | |
if record: | |
try: | |
if line.strip() != '': | |
authors[author].append(len(line)) | |
line = lines.next() | |
except StopIteration: | |
break | |
fields = ( | |
'Author', | |
'lines > 80', | |
'% lines > 80 / lines written', | |
'% lines > 80 / total lines', | |
'longest line' | |
) | |
print ','.join(fields) | |
total_lines = sum(len(nums) for nums in authors.itervalues()) | |
for author, nums in authors.iteritems(): | |
count = 0.0 | |
for n in nums: | |
if n > 80: | |
count += 1 | |
print '%s, %s, %s, %s, %s' % ( | |
author, | |
count, | |
count / len(nums), | |
count / total_lines, | |
max(nums) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment