|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+import csv
|
|
|
2
|
+import logging
|
|
|
3
|
+import os
|
|
|
4
|
+import sys
|
|
|
5
|
+
|
|
|
6
|
+import multiprocessing_logging
|
|
|
7
|
+
|
|
|
8
|
+from gitstats import cli
|
|
|
9
|
+from gitstats.data import AuthorTotals, AuthorRow, File, LocByDate, Revision, Tag
|
|
|
10
|
+from gitstats.data_generators import gen_author_data, gen_author_totals_data, gen_tag_data, gen_revision_data, \
|
|
|
11
|
+ gen_file_data, gen_loc_data
|
|
|
12
|
+
|
|
|
13
|
+exectime_internal = 0.0
|
|
|
14
|
+exectime_external = 0.0
|
|
|
15
|
+
|
|
|
16
|
+
|
|
|
17
|
+class _FileHandles:
|
|
|
18
|
+ def __init__(self, output_dir):
|
|
|
19
|
+ self.author_info = open(os.path.join(output_dir, 'authors.csv'), 'w', encoding='utf8')
|
|
|
20
|
+ self.author_info_writer = csv.writer(self.author_info)
|
|
|
21
|
+ self.author_info_writer.writerow(['Repo', 'CommitHash', 'TimeStamp', 'Author', 'FilesChanged', 'LinesInserted',
|
|
|
22
|
+ 'LinesDeleted'])
|
|
|
23
|
+
|
|
|
24
|
+ self.author_totals_info = open(os.path.join(output_dir, 'author_totals.csv'), 'w', encoding='utf8')
|
|
|
25
|
+ self.author_totals_info_writer = csv.writer(self.author_totals_info)
|
|
|
26
|
+ self.author_totals_info_writer.writerow(["Repo", "Author", "Commits"])
|
|
|
27
|
+
|
|
|
28
|
+ self.tag_info = open(os.path.join(output_dir, 'tags.csv'), 'w', encoding='utf8')
|
|
|
29
|
+ self.tag_info_writer = csv.writer(self.tag_info)
|
|
|
30
|
+ self.tag_info_writer.writerow(["Repo", "CommitHash", "Timestamp", "TotalCommits", "Author", "AuthorCommits"])
|
|
|
31
|
+
|
|
|
32
|
+ self.revision_info = open(os.path.join(output_dir, 'revs.csv'), 'w', encoding='utf8')
|
|
|
33
|
+ self.revision_info_writer = csv.writer(self.revision_info)
|
|
|
34
|
+ self.revision_info_writer.writerow(['Repo', 'CommitHash', 'TimeStamp', 'TimeZone', 'Author', 'AuthorEmail',
|
|
|
35
|
+ 'Domain', 'FilesChanged'])
|
|
|
36
|
+
|
|
|
37
|
+ self.files_info = open(os.path.join(output_dir, 'files.csv'), 'w', encoding='utf8')
|
|
|
38
|
+ self.files_info_writer = csv.writer(self.files_info)
|
|
|
39
|
+ self.files_info_writer.writerow(['Repo', 'File', 'Ext', 'Size', 'Lines'])
|
|
|
40
|
+
|
|
|
41
|
+ self.loc_info = open(os.path.join(output_dir, 'loc.csv'), 'w', encoding='utf8')
|
|
|
42
|
+ self.loc_info_writer = csv.writer(self.loc_info)
|
|
|
43
|
+ self.loc_info_writer.writerow(['Repo', 'CommitHash', 'TimeStamp', 'FileCount', 'LinesInserted', 'LinesDeleted',
|
|
|
44
|
+ 'TotalLines'])
|
|
|
45
|
+
|
|
|
46
|
+ def close(self):
|
|
|
47
|
+ self.author_info.close()
|
|
|
48
|
+ self.author_totals_info.close()
|
|
|
49
|
+ self.tag_info.close()
|
|
|
50
|
+ self.revision_info.close()
|
|
|
51
|
+ self.files_info.close()
|
|
|
52
|
+ self.loc_info.close()
|
|
|
53
|
+
|
|
|
54
|
+
|
|
|
55
|
+class GitCsvGenerator():
|
|
|
56
|
+ def __init__(self, conf, output_dir):
|
|
|
57
|
+ self.conf = conf
|
|
|
58
|
+ self.files: _FileHandles = None
|
|
|
59
|
+ self.output_dir = output_dir
|
|
|
60
|
+
|
|
|
61
|
+ def __enter__(self):
|
|
|
62
|
+ self.files = _FileHandles(self.output_dir)
|
|
|
63
|
+
|
|
|
64
|
+ def __exit__(self, exc_type, exc_val, exc_tb):
|
|
|
65
|
+ self.files.close()
|
|
|
66
|
+
|
|
|
67
|
+ def collect(self, dir):
|
|
|
68
|
+ if len(self.conf['project_name']) == 0:
|
|
|
69
|
+ self.projectname = os.path.basename(os.path.abspath(dir))
|
|
|
70
|
+ else:
|
|
|
71
|
+ self.projectname = self.conf['project_name']
|
|
|
72
|
+
|
|
|
73
|
+ self.get_total_authors()
|
|
|
74
|
+ self.get_tags()
|
|
|
75
|
+ self.get_revision_info()
|
|
|
76
|
+ self.get_file_info()
|
|
|
77
|
+ self.get_loc_info()
|
|
|
78
|
+ self.get_author_info()
|
|
|
79
|
+
|
|
|
80
|
+ def get_total_authors(self):
|
|
|
81
|
+ logging.info(f"Getting author totals for {self.projectname}")
|
|
|
82
|
+ def row_processor(row: AuthorTotals):
|
|
|
83
|
+ self.files.author_totals_info_writer.writerow([self.projectname, row.author, row.total_commits])
|
|
|
84
|
+ gen_author_totals_data(self.conf, row_processor)
|
|
|
85
|
+
|
|
|
86
|
+ def get_tags(self):
|
|
|
87
|
+ logging.info(f"Getting tag info for {self.projectname}")
|
|
|
88
|
+ def row_processor(row: Tag):
|
|
|
89
|
+ for author, commits in row.authors.items():
|
|
|
90
|
+ self.files.tag_info_writer.writerow([self.projectname, row.hash, row.stamp, row.commits, author, commits])
|
|
|
91
|
+ gen_tag_data(self.conf, row_processor)
|
|
|
92
|
+
|
|
|
93
|
+ def get_revision_info(self):
|
|
|
94
|
+ logging.info(f"Getting rev info for {self.projectname}")
|
|
|
95
|
+ def row_processor(row: Revision):
|
|
|
96
|
+ self.files.revision_info_writer.writerow([self.projectname, row.hash, row.stamp, row.timezone, row.author,
|
|
|
97
|
+ row.email, row.domain, row.file_count])
|
|
|
98
|
+ gen_revision_data(self.conf, row_processor)
|
|
|
99
|
+
|
|
|
100
|
+ def get_file_info(self):
|
|
|
101
|
+ logging.info(f"Getting file info for {self.projectname}")
|
|
|
102
|
+ def row_processor(row: File):
|
|
|
103
|
+ self.files.files_info_writer.writerow([self.projectname, row.full_path, row.ext, row.size, row.lines])
|
|
|
104
|
+ gen_file_data(self.conf, row_processor)
|
|
|
105
|
+
|
|
|
106
|
+ def get_loc_info(self):
|
|
|
107
|
+ logging.info(f"Getting LOC info for {self.projectname}")
|
|
|
108
|
+ def row_processor(row: LocByDate):
|
|
|
109
|
+ self.files.loc_info_writer.writerow([self.projectname, row.hash, row.stamp, row.file_count,
|
|
|
110
|
+ row.lines_inserted, row.lines_deleted, row.total_lines])
|
|
|
111
|
+ gen_loc_data(self.conf, row_processor)
|
|
|
112
|
+
|
|
|
113
|
+ def get_author_info(self):
|
|
|
114
|
+ logging.info(f"Getting author info for {self.projectname}")
|
|
|
115
|
+ def row_processor(row: AuthorRow):
|
|
|
116
|
+ self.files.author_info_writer.writerow([self.projectname, row.hash, row.stamp, row.author,
|
|
|
117
|
+ row.files_modified, row.lines_inserted, row.lines_deleted])
|
|
|
118
|
+ gen_author_data(self.conf, row_processor)
|
|
|
119
|
+
|
|
|
120
|
+def gen_csv():
|
|
|
121
|
+ conf, paths, outputpath = cli.get_cli()
|
|
|
122
|
+
|
|
|
123
|
+ logging.basicConfig(level=conf['logging'], format='%(message)s')
|
|
|
124
|
+ multiprocessing_logging.install_mp_handler()
|
|
|
125
|
+ try:
|
|
|
126
|
+ os.makedirs(outputpath)
|
|
|
127
|
+ except OSError:
|
|
|
128
|
+ pass
|
|
|
129
|
+ if not os.path.isdir(outputpath):
|
|
|
130
|
+ logging.fatal('Output path is not a directory or does not exist')
|
|
|
131
|
+ sys.exit(1)
|
|
|
132
|
+
|
|
|
133
|
+ logging.info(f'Output path: {outputpath}')
|
|
|
134
|
+
|
|
|
135
|
+ data = GitCsvGenerator(conf, outputpath)
|
|
|
136
|
+ with data:
|
|
|
137
|
+ for gitpath in paths:
|
|
|
138
|
+ logging.info(f'Git path: {gitpath}')
|
|
|
139
|
+
|
|
|
140
|
+ prevdir = os.getcwd()
|
|
|
141
|
+ os.chdir(gitpath)
|
|
|
142
|
+
|
|
|
143
|
+ logging.info('Collecting data...')
|
|
|
144
|
+ data.collect(gitpath)
|
|
|
145
|
+
|
|
|
146
|
+ os.chdir(prevdir)
|
|
|
147
|
+
|
|
|
148
|
+if __name__ == '__main__':
|
|
|
149
|
+ gen_csv()
|