Created
February 22, 2014 15:46
-
-
Save NewProggie/9156865 to your computer and use it in GitHub Desktop.
Small python script to publish a js chart of git file changes, insertions and deletions
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 | |
import os | |
def header(): | |
print """ | |
<html> | |
<head> | |
<script type="text/javascript" src="https://www.google.com/jsapi"></script> | |
<script type="text/javascript"> | |
google.load("visualization", "1", {packages:["corechart"]}); | |
google.setOnLoadCallback(drawChart); | |
function drawChart() { | |
var data = google.visualization.arrayToDataTable([ | |
['Year', 'Files Changed', 'Insertions', 'Deletions'], | |
""" | |
def content(): | |
gitlog = os.popen("git log --oneline --shortstat -C").read().split("\n") | |
for log in gitlog[1::2]: | |
log = log.strip().split(" ") | |
if len(log) < 2: continue | |
numFiles = log[0] | |
numInserts = log[3] | |
numDeletes = log[5] if len(log) > 5 else "0" | |
print "['', %s, %s, %s]," % (numFiles, numInserts, numDeletes) | |
def footer(): | |
print """ | |
]); | |
var options = { | |
title: 'Code Crunch', | |
hAxis: {title: 'Changes per commit'} | |
}; | |
var chart = new google.visualization.AreaChart(document.getElementById('chart_div')); | |
chart.draw(data, options); | |
} | |
</script> | |
</head> | |
<body> | |
<div id="chart_div" style="width: 900px; height: 500px;"></div> | |
</body> | |
</html> | |
""" | |
def main(): | |
header() | |
content() | |
footer() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment