2 # Copyright (c) 2007 Heikki Hokkanen <hoxu@users.sf.net>
14 def collect(self
, dir):
18 # TODO: get a dictionary of author
19 def getAuthorInfo(self
, author
):
23 # Get a list of authors
27 def getTotalAuthors(self
):
30 def getTotalCommits(self
):
33 def getTotalFiles(self
):
36 def getTotalLOC(self
):
39 class GitDataCollector(DataCollector
):
40 def collect(self
, dir):
41 DataCollector
.collect(self
, dir)
43 def getAuthorInfo(self
, author
):
44 res
= { 'commits' : -1, 'commits_frac' : 1.5, 'date_first' : '0000-00-00', 'date_last' : '0000-00-00' }
48 lines
= commands
.getoutput('git-rev-list --all --pretty=format:%an |grep -v ^commit |sort |uniq')
49 return lines
.split('\n')
51 def getTotalAuthors(self
):
52 return int(commands
.getoutput('git-log |git-shortlog -s |wc -l'))
54 def getTotalCommits(self
):
55 return int(commands
.getoutput('git-rev-list --all |wc -l'))
57 def getTotalFiles(self
):
58 files
= commands
.getoutput('git-ls-files |wc -l')
66 def create(self
, data
, path
):
70 class HTMLReportCreator(ReportCreator
):
71 def create(self
, data
, path
):
72 ReportCreator
.create(self
, data
, path
)
74 f
= open(path
+ "/index.html", 'w')
77 <title>StatGit</title>
82 f
.write('<h1>StatGit</h1>')
85 f
.write('<dt>Generated</dt><dd>%s</dd>' % datetime
.datetime
.now().strftime('%Y-%m-%d %H:%m:%S'));
86 f
.write('<dt>Report Period</dt><dd>%s to %s</dd>' % ('0000-00-00', '0000-00-00'))
87 f
.write('<dt>Total Files</dt><dd>%s</dd>' % data
.getTotalFiles())
88 f
.write('<dt>Total Lines of Code</dt><dd>%s</dd>' % data
.getTotalLOC())
89 f
.write('<dt>Total Commits</dt><dd>%s</dd>' % data
.getTotalCommits())
90 f
.write('<dt>Authors</dt><dd>%s</dd>' % data
.getTotalAuthors())
93 f
.write('<h2>Authors</h2>')
95 f
.write('<table class="authors">')
96 f
.write('<tr><th>Author</th><th>Commits (%)</th><th>First commit</th><th>Last commit</th></tr>')
97 for author
in data
.getAuthors():
98 info
= data
.getAuthorInfo(author
)
99 f
.write('<tr><td>%s</td><td>%d (%.2f)</td><td>%s</td><td>%s</td></tr>' % (author
, info
['commits'], info
['commits_frac'], info
['date_first'], info
['date_last']))
102 f
.write('</body>\n</html>');
107 Usage: statgit [options] <gitpath> <outputpath>
113 if len(sys
.argv
) < 3:
117 gitpath
= sys
.argv
[1]
118 outputpath
= sys
.argv
[2]
120 print 'Git path: %s' % gitpath
121 print 'Output path: %s' % outputpath
125 data
= GitDataCollector()
126 data
.collect(gitpath
)
128 report
= HTMLReportCreator()
129 report
.create(data
, outputpath
)