|
|
@@ -1,11 +1,14 @@
|
|
1
|
1
|
#!/usr/bin/python
|
|
2
|
2
|
# Copyright (c) 2007-2014 Heikki Hokkanen <hoxu@users.sf.net> & others (see doc/AUTHOR)
|
|
3
|
3
|
# GPLv2 / GPLv3
|
|
4
|
|
-import argparse
|
|
|
4
|
+import getopt
|
|
|
5
|
+import logging
|
|
5
|
6
|
import os
|
|
6
|
7
|
import sys
|
|
7
|
8
|
import time
|
|
8
|
9
|
|
|
|
10
|
+import multiprocessing_logging
|
|
|
11
|
+
|
|
9
|
12
|
from .gitdatacollector import GitDataCollector
|
|
10
|
13
|
from .htmlreportcreator import HTMLReportCreator
|
|
11
|
14
|
from .miscfuncs import getgnuplotversion
|
|
|
@@ -24,7 +27,8 @@ conf = {
|
|
24
|
27
|
'linear_linestats': 1,
|
|
25
|
28
|
'project_name': '',
|
|
26
|
29
|
'processes': 8,
|
|
27
|
|
- 'start_date': ''
|
|
|
30
|
+ 'start_date': '',
|
|
|
31
|
+ 'logging': logging.INFO
|
|
28
|
32
|
}
|
|
29
|
33
|
|
|
30
|
34
|
class GitStats:
|
|
|
@@ -42,22 +46,32 @@ class GitStats:
|
|
42
|
46
|
""")
|
|
43
|
47
|
|
|
44
|
48
|
def run(self):
|
|
45
|
|
- if len(sys.argv) < 2:
|
|
|
49
|
+ optlist, args = getopt.getopt(sys.argv[1:], 'hc:', ["help"])
|
|
|
50
|
+ for o, v in optlist:
|
|
|
51
|
+ if o == '-c':
|
|
|
52
|
+ key, value = v.split('=', 1)
|
|
|
53
|
+ if key not in conf:
|
|
|
54
|
+ raise KeyError('no such key "%s" in config' % key)
|
|
|
55
|
+ if isinstance(conf[key], int):
|
|
|
56
|
+ conf[key] = int(value)
|
|
|
57
|
+ else:
|
|
|
58
|
+ conf[key] = value
|
|
|
59
|
+ elif o in ('-h', '--help'):
|
|
|
60
|
+ self._usage()
|
|
|
61
|
+ sys.exit()
|
|
|
62
|
+
|
|
|
63
|
+ if len(args) < 2:
|
|
46
|
64
|
self._usage()
|
|
47
|
65
|
sys.exit(0)
|
|
48
|
66
|
|
|
49
|
|
- parser = argparse.ArgumentParser(description='GitStats')
|
|
50
|
|
-# parser.add_argument('-c', '--config', dest='config')
|
|
51
|
|
-
|
|
52
|
|
- (args, remaining_args) = parser.parse_known_args()
|
|
53
|
|
-# if args.config:
|
|
54
|
|
-# self.conf.load(args.config)
|
|
|
67
|
+ outputpath = os.path.abspath(args[-1])
|
|
|
68
|
+ paths = args[0:-1]
|
|
|
69
|
+ outputpath = os.path.abspath(outputpath)
|
|
55
|
70
|
|
|
|
71
|
+ logging.basicConfig(level=conf['logging'], format='%(message)s')
|
|
|
72
|
+ multiprocessing_logging.install_mp_handler()
|
|
56
|
73
|
time_start = time.time()
|
|
57
|
74
|
|
|
58
|
|
- outputpath = remaining_args[-1]
|
|
59
|
|
- paths = remaining_args[0:-1]
|
|
60
|
|
- outputpath = os.path.abspath(outputpath)
|
|
61
|
75
|
|
|
62
|
76
|
rundir = os.getcwd()
|
|
63
|
77
|
|
|
|
@@ -66,49 +80,48 @@ class GitStats:
|
|
66
|
80
|
except OSError:
|
|
67
|
81
|
pass
|
|
68
|
82
|
if not os.path.isdir(outputpath):
|
|
69
|
|
- print('FATAL: Output path is not a directory or does not exist')
|
|
|
83
|
+ logging.fatal('Output path is not a directory or does not exist')
|
|
70
|
84
|
sys.exit(1)
|
|
71
|
85
|
|
|
72
|
86
|
if not getgnuplotversion():
|
|
73
|
|
- print('gnuplot not found')
|
|
|
87
|
+ logging.error('gnuplot not found')
|
|
74
|
88
|
sys.exit(1)
|
|
75
|
89
|
|
|
76
|
|
- print(f'Output path: {outputpath}')
|
|
|
90
|
+ logging.info(f'Output path: {outputpath}')
|
|
77
|
91
|
cachefile = os.path.join(outputpath, 'gitstats.cache')
|
|
78
|
92
|
|
|
79
|
93
|
data = GitDataCollector(conf)
|
|
80
|
94
|
data.loadCache(cachefile)
|
|
81
|
95
|
|
|
82
|
96
|
for gitpath in paths:
|
|
83
|
|
- print(f'Git path: {gitpath}')
|
|
|
97
|
+ logging.info(f'Git path: {gitpath}')
|
|
84
|
98
|
|
|
85
|
99
|
prevdir = os.getcwd()
|
|
86
|
100
|
os.chdir(gitpath)
|
|
87
|
101
|
|
|
88
|
|
- print('Collecting data...')
|
|
|
102
|
+ logging.info('Collecting data...')
|
|
89
|
103
|
data.collect(gitpath)
|
|
90
|
104
|
|
|
91
|
105
|
os.chdir(prevdir)
|
|
92
|
106
|
|
|
93
|
|
- print('Refining data...')
|
|
|
107
|
+ logging.info('Refining data...')
|
|
94
|
108
|
data.saveCache(cachefile)
|
|
95
|
109
|
data.refine()
|
|
96
|
110
|
|
|
97
|
111
|
os.chdir(rundir)
|
|
98
|
112
|
|
|
99
|
|
- print('Generating report...')
|
|
|
113
|
+ logging.info('Generating report...')
|
|
100
|
114
|
report = HTMLReportCreator(conf)
|
|
101
|
115
|
report.create(data, outputpath)
|
|
102
|
116
|
|
|
103
|
117
|
time_end = time.time()
|
|
104
|
118
|
calculated_exectime_internal = time_end - time_start
|
|
105
|
|
- print(
|
|
106
|
|
- f'Execution time {calculated_exectime_internal} secs, {exectime_external} secs ({(100.0 * exectime_external) / calculated_exectime_internal}%) in external commands)')
|
|
107
|
|
- if sys.stdin.isatty():
|
|
108
|
|
- print('You may now run:')
|
|
109
|
|
- print()
|
|
110
|
|
- print(' sensible-browser \'%s\'' % os.path.join(outputpath, 'index.html').replace("'", "'\\''"))
|
|
111
|
|
- print()
|
|
|
119
|
+ logging.info(f'Execution time {calculated_exectime_internal} secs, {exectime_external} secs ({(100.0 * exectime_external) / calculated_exectime_internal}%) in external commands)')
|
|
|
120
|
+
|
|
|
121
|
+ print('You may now run:')
|
|
|
122
|
+ print()
|
|
|
123
|
+ print(' sensible-browser \'%s\'' % os.path.join(outputpath, 'index.html').replace("'", "'\\''"))
|
|
|
124
|
+ print()
|
|
112
|
125
|
|
|
113
|
126
|
|
|
114
|
127
|
if __name__ == '__main__':
|