|
|
@@ -1,9 +1,11 @@
|
|
1
|
1
|
import csv
|
|
|
2
|
+import glob
|
|
2
|
3
|
import logging
|
|
3
|
4
|
import os
|
|
4
|
5
|
import sys
|
|
5
|
6
|
|
|
6
|
7
|
import multiprocessing_logging
|
|
|
8
|
+from gitstats.cd import cd
|
|
7
|
9
|
|
|
8
|
10
|
from gitstats import cli
|
|
9
|
11
|
from gitstats.data import AuthorTotals, AuthorRow, File, LocByDate, PullRequest, Revision, Tag
|
|
|
@@ -36,7 +38,7 @@ class _FileHandles:
|
|
36
|
38
|
|
|
37
|
39
|
self.files_info = open(os.path.join(output_dir, 'files.csv'), 'w', encoding='utf8')
|
|
38
|
40
|
self.files_info_writer = csv.writer(self.files_info)
|
|
39
|
|
- self.files_info_writer.writerow(['Repo', 'File', 'Ext', 'Size', 'Lines'])
|
|
|
41
|
+ self.files_info_writer.writerow(['Repo', 'File', 'Ext', 'Size', 'Lines', 'Resource'])
|
|
40
|
42
|
|
|
41
|
43
|
self.loc_info = open(os.path.join(output_dir, 'loc.csv'), 'w', encoding='utf8')
|
|
42
|
44
|
self.loc_info_writer = csv.writer(self.loc_info)
|
|
|
@@ -61,12 +63,13 @@ class _FileHandles:
|
|
61
|
63
|
self.repo_info.close()
|
|
62
|
64
|
self.prs_info.close()
|
|
63
|
65
|
|
|
64
|
|
-
|
|
65
|
66
|
class GitCsvGenerator():
|
|
66
|
67
|
def __init__(self, conf, output_dir):
|
|
67
|
68
|
self.conf = conf
|
|
68
|
69
|
self.files: _FileHandles = None
|
|
69
|
70
|
self.output_dir = output_dir
|
|
|
71
|
+ self.resource_files = []
|
|
|
72
|
+ self.igore_files = ''
|
|
70
|
73
|
|
|
71
|
74
|
def __enter__(self):
|
|
72
|
75
|
self.files = _FileHandles(self.output_dir)
|
|
|
@@ -75,18 +78,26 @@ class GitCsvGenerator():
|
|
75
|
78
|
self.files.close()
|
|
76
|
79
|
|
|
77
|
80
|
def collect(self, dir):
|
|
78
|
|
- if len(self.conf['project_name']) == 0:
|
|
79
|
|
- self.projectname = os.path.basename(os.path.abspath(dir))
|
|
80
|
|
- else:
|
|
81
|
|
- self.projectname = self.conf['project_name']
|
|
82
|
|
-
|
|
83
|
|
- self.get_total_authors()
|
|
84
|
|
- self.get_tags()
|
|
85
|
|
- self.get_revision_info()
|
|
86
|
|
- self.get_file_info()
|
|
87
|
|
- self.get_loc_info()
|
|
88
|
|
- self.get_author_info()
|
|
89
|
|
- self.get_pr_info()
|
|
|
81
|
+
|
|
|
82
|
+ with cd(dir):
|
|
|
83
|
+ self.resource_files = [file for file in glob.glob(self.conf['resrouce_file_pattern'], recursive=True) if os.path.isfile(file)]
|
|
|
84
|
+
|
|
|
85
|
+ if self.resource_files:
|
|
|
86
|
+ self.ignore_files = '" "'.join([f":(exclude){file}" for file in self.resource_files])
|
|
|
87
|
+ self.ignore_files = f'-- "{self.ignore_files}"'
|
|
|
88
|
+
|
|
|
89
|
+ if len(self.conf['project_name']) == 0:
|
|
|
90
|
+ self.projectname = os.path.basename(os.path.abspath(dir))
|
|
|
91
|
+ else:
|
|
|
92
|
+ self.projectname = self.conf['project_name']
|
|
|
93
|
+
|
|
|
94
|
+ self.get_total_authors()
|
|
|
95
|
+ self.get_tags()
|
|
|
96
|
+ self.get_revision_info()
|
|
|
97
|
+ self.get_file_info()
|
|
|
98
|
+ self.get_loc_info()
|
|
|
99
|
+ self.get_author_info()
|
|
|
100
|
+ self.get_pr_info()
|
|
90
|
101
|
|
|
91
|
102
|
def get_total_authors(self):
|
|
92
|
103
|
logging.info(f"Getting author totals for {self.projectname}")
|
|
|
@@ -111,7 +122,7 @@ class GitCsvGenerator():
|
|
111
|
122
|
def get_file_info(self):
|
|
112
|
123
|
logging.info(f"Getting file info for {self.projectname}")
|
|
113
|
124
|
def row_processor(row: File):
|
|
114
|
|
- self.files.files_info_writer.writerow([self.projectname, row.full_path, row.ext, row.size, row.lines])
|
|
|
125
|
+ self.files.files_info_writer.writerow([self.projectname, row.full_path, row.ext, row.size, row.lines, row.full_path in self.resource_files])
|
|
115
|
126
|
gen_file_data(self.conf, row_processor)
|
|
116
|
127
|
|
|
117
|
128
|
def get_loc_info(self):
|
|
|
@@ -119,7 +130,7 @@ class GitCsvGenerator():
|
|
119
|
130
|
def row_processor(row: LocByDate):
|
|
120
|
131
|
self.files.loc_info_writer.writerow([self.projectname, row.hash, row.stamp, row.file_count,
|
|
121
|
132
|
row.lines_inserted, row.lines_deleted, row.total_lines])
|
|
122
|
|
- total_files, total_lines = gen_loc_data(self.conf, row_processor)
|
|
|
133
|
+ total_files, total_lines = gen_loc_data(self.conf, row_processor, self.ignore_files)
|
|
123
|
134
|
self.files.repo_info_writer.writerow([self.projectname, total_files, total_lines])
|
|
124
|
135
|
|
|
125
|
136
|
def get_author_info(self):
|
|
|
@@ -127,7 +138,7 @@ class GitCsvGenerator():
|
|
127
|
138
|
def row_processor(row: AuthorRow):
|
|
128
|
139
|
self.files.author_info_writer.writerow([self.projectname, row.hash, row.stamp, row.author,
|
|
129
|
140
|
row.files_modified, row.lines_inserted, row.lines_deleted])
|
|
130
|
|
- gen_author_data(self.conf, row_processor)
|
|
|
141
|
+ gen_author_data(self.conf, row_processor, self.ignore_files)
|
|
131
|
142
|
|
|
132
|
143
|
def get_pr_info(self):
|
|
133
|
144
|
logging.info(f"Getting pull request info for {self.projectname}")
|