forked from dmitryn/GitStats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-stats
executable file
·90 lines (73 loc) · 2.11 KB
/
git-stats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
# Copyright (c) 2007-2010 Heikki Hokkanen <[email protected]> & others (see doc/author.txt)
# GPLv2 / GPLv3
import getopt
import os
import sys
import time
#Our project imports
from git_data_collector import GitDataCollector
from html_report_creator import HTMLReportCreator
from command_line_processor import *
class GitStats:
def run(self, args_orig):
optlist, args = getopt.getopt(args_orig, 'c:')
for o,v in optlist:
if o == '-c':
key, value = v.split('=', 1)
if key not in conf:
raise 'Error: no such key "%s" in config' % key
if isinstance(conf[key], int):
conf[key] = int(value)
else:
conf[key] = value
if len(args) < 2:
print """
Usage: gitstats [options] <gitpath> <outputpath>
Options:
-c key=value Override configuration value
Default config values:
%s
""" % conf
sys.exit(0)
gitpath = args[0]
outputpath = os.path.abspath(args[1])
rundir = os.getcwd()
try:
os.makedirs(outputpath)
except OSError:
pass
if not os.path.isdir(outputpath):
print 'FATAL: Output path is not a directory or does not exist'
sys.exit(1)
print 'Git path: %s' % gitpath
print 'Output path: %s' % outputpath
os.chdir(gitpath)
cachefile = os.path.join(outputpath, 'gitstats.cache')
print 'Collecting data...'
data = GitDataCollector(conf)
data.loadCache(cachefile)
data.collect(gitpath)
print 'Refining data...'
data.saveCache(cachefile)
data.refine()
os.chdir(rundir)
print 'Generating report...'
report = HTMLReportCreator(conf)
report.create(data, outputpath)
time_end = time.time()
exectime_internal = time_end - time_start
exectime_external = getexectimeexternal()
print 'Execution time %.5f secs, %.5f secs (%.2f %%) in external commands)' % (exectime_internal, exectime_external, (100.0 * exectime_external) / exectime_internal)
if __name__ == "__main__":
exectime_internal = 0.0
time_start = time.time()
conf = {
'max_domains': 10,
'max_ext_length': 10,
'style': 'gitstats.css',
'max_authors': 20,
'image_type': 'svg' # everything that gnuplot accepts, I guess
}
g = GitStats()
g.run(sys.argv[1:])