|
|
@@ -1,6 +1,8 @@
|
|
1
|
1
|
#!/usr/bin/python
|
|
2
|
2
|
# Copyright (c) 2007 Heikki Hokkanen <hoxu@users.sf.net>
|
|
3
|
3
|
# GPLv2
|
|
|
4
|
+import commands
|
|
|
5
|
+import datetime
|
|
4
|
6
|
import os
|
|
5
|
7
|
import re
|
|
6
|
8
|
import sys
|
|
|
@@ -11,8 +13,50 @@ class DataCollector:
|
|
11
|
13
|
|
|
12
|
14
|
def collect(self, dir):
|
|
13
|
15
|
self.dir = dir
|
|
|
16
|
+
|
|
|
17
|
+ ##
|
|
|
18
|
+ # TODO: get a dictionary of author
|
|
|
19
|
+ def getAuthorInfo(self, author):
|
|
|
20
|
+ return None
|
|
|
21
|
+
|
|
|
22
|
+ ##
|
|
|
23
|
+ # Get a list of authors
|
|
|
24
|
+ def getAuthors(self):
|
|
|
25
|
+ return []
|
|
|
26
|
+
|
|
|
27
|
+ def getTotalAuthors(self):
|
|
|
28
|
+ return -1
|
|
|
29
|
+
|
|
|
30
|
+ def getTotalCommits(self):
|
|
|
31
|
+ return -1
|
|
|
32
|
+
|
|
|
33
|
+ def getTotalFiles(self):
|
|
|
34
|
+ return -1
|
|
|
35
|
+
|
|
|
36
|
+ def getTotalLOC(self):
|
|
|
37
|
+ return -1
|
|
14
|
38
|
|
|
15
|
39
|
class GitDataCollector(DataCollector):
|
|
|
40
|
+ def collect(self, dir):
|
|
|
41
|
+ DataCollector.collect(self, dir)
|
|
|
42
|
+
|
|
|
43
|
+ def getAuthorInfo(self, author):
|
|
|
44
|
+ res = { 'commits' : -1, 'commits_frac' : 1.5, 'date_first' : '0000-00-00', 'date_last' : '0000-00-00' }
|
|
|
45
|
+ return res
|
|
|
46
|
+
|
|
|
47
|
+ def getAuthors(self):
|
|
|
48
|
+ lines = commands.getoutput('git-rev-list --all --pretty=format:%an |grep -v ^commit |sort |uniq')
|
|
|
49
|
+ return lines.split('\n')
|
|
|
50
|
+
|
|
|
51
|
+ def getTotalAuthors(self):
|
|
|
52
|
+ return int(commands.getoutput('git-log |git-shortlog -s |wc -l'))
|
|
|
53
|
+
|
|
|
54
|
+ def getTotalCommits(self):
|
|
|
55
|
+ return int(commands.getoutput('git-rev-list --all |wc -l'))
|
|
|
56
|
+
|
|
|
57
|
+ def getTotalFiles(self):
|
|
|
58
|
+ files = commands.getoutput('git-ls-files |wc -l')
|
|
|
59
|
+ return int(files)
|
|
16
|
60
|
pass
|
|
17
|
61
|
|
|
18
|
62
|
class ReportCreator:
|
|
|
@@ -23,13 +67,40 @@ class ReportCreator:
|
|
23
|
67
|
self.data = data
|
|
24
|
68
|
self.path = path
|
|
25
|
69
|
|
|
26
|
|
-class ConsoleReportCreator(ReportCreator):
|
|
|
70
|
+class HTMLReportCreator(ReportCreator):
|
|
27
|
71
|
def create(self, data, path):
|
|
28
|
|
- ReportCreator.create(data, path)
|
|
|
72
|
+ ReportCreator.create(self, data, path)
|
|
29
|
73
|
|
|
30
|
|
- pass
|
|
|
74
|
+ f = open(path + "/index.html", 'w')
|
|
|
75
|
+ f.write("""<html>
|
|
|
76
|
+<head>
|
|
|
77
|
+ <title>StatGit</title>
|
|
|
78
|
+</head>
|
|
|
79
|
+<body>
|
|
|
80
|
+""")
|
|
31
|
81
|
|
|
32
|
|
-class HTMLReportCreator(ReportCreator):
|
|
|
82
|
+ f.write('<h1>StatGit</h1>')
|
|
|
83
|
+
|
|
|
84
|
+ f.write('<dl>');
|
|
|
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())
|
|
|
91
|
+ f.write('</dl>');
|
|
|
92
|
+
|
|
|
93
|
+ f.write('<h2>Authors</h2>')
|
|
|
94
|
+
|
|
|
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']))
|
|
|
100
|
+ f.write('</table>')
|
|
|
101
|
+
|
|
|
102
|
+ f.write('</body>\n</html>');
|
|
|
103
|
+ f.close()
|
|
33
|
104
|
pass
|
|
34
|
105
|
|
|
35
|
106
|
usage = """
|
|
|
@@ -49,10 +120,12 @@ outputpath = sys.argv[2]
|
|
49
|
120
|
print 'Git path: %s' % gitpath
|
|
50
|
121
|
print 'Output path: %s' % outputpath
|
|
51
|
122
|
|
|
|
123
|
+os.chdir(gitpath)
|
|
|
124
|
+
|
|
52
|
125
|
data = GitDataCollector()
|
|
53
|
126
|
data.collect(gitpath)
|
|
54
|
127
|
|
|
55
|
|
-report = ConsoleReportCreator()
|
|
|
128
|
+report = HTMLReportCreator()
|
|
56
|
129
|
report.create(data, outputpath)
|
|
57
|
130
|
|
|
58
|
131
|
|