Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/README
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
gitstats is a statistics generator for git repositories. It is mostly intended
for developers, as a way to check some development statistics for a project.

Currently it produces only HTML output with tables and graphs.
Currently it produces HTML output with tables and graphs and pretty JSON.

Requirements
============
Expand Down
28 changes: 26 additions & 2 deletions gitstats
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import datetime
import getopt
import glob
import json
import os
import pickle
import platform
Expand All @@ -25,6 +26,7 @@ os.environ['LC_ALL'] = 'C'
GNUPLOT_COMMON = 'set terminal png transparent size 640,240\nset size 1.0,1.0\n'
ON_LINUX = (platform.system() == 'Linux')
WEEKDAYS = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
JSONFILE = 'gitstats.json'

exectime_internal = 0.0
exectime_external = 0.0
Expand Down Expand Up @@ -728,6 +730,24 @@ def html_header(level, text):
name = html_linkify(text)
return '\n<h%d id="%s"><a href="#%s">%s</a></h%d>\n\n' % (level, name, name, text, level)

class GitDataCollectorJSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, set):
return list(obj)
if isinstance(obj, datetime.timedelta):
return str(obj)
if isinstance(obj, GitDataCollector):
return obj.__dict__
# Let the base class default method raise the TypeError
return json.JSONEncoder.default(self, obj)

class JSONReportCreator(ReportCreator):
def create(self, data, filename):
f = open(filename, 'w')
json.dump(data, f, indent=True,
cls=GitDataCollectorJSONEncoder)
f.close()

class HTMLReportCreator(ReportCreator):
def create(self, data, path):
ReportCreator.create(self, data, path)
Expand Down Expand Up @@ -1472,20 +1492,24 @@ class GitStats:

os.chdir(rundir)

print 'Generating report...'
print 'Generating HTML report...'
report = HTMLReportCreator()
report.create(data, outputpath)

print 'Generating JSON report...'
report = JSONReportCreator()
report.create(data, os.path.join(outputpath, JSONFILE))

time_end = time.time()
exectime_internal = time_end - time_start
print 'Execution time %.5f secs, %.5f secs (%.2f %%) in external commands)' % (exectime_internal, exectime_external, (100.0 * exectime_external) / exectime_internal)
if sys.stdin.isatty():
print 'You may now run:'
print
print ' sensible-browser \'%s\'' % os.path.join(outputpath, 'index.html').replace("'", "'\\''")
print ' sensible-notepad \'%s\'' % os.path.join(outputpath, JSONFILE).replace("'", "'\\''")
print

if __name__=='__main__':
g = GitStats()
g.run(sys.argv[1:])