Selaa lähdekoodia

Handle exclusion of resource files from some of the reporting

Dan Rapp 7 vuotta sitten
vanhempi
commit
af2be5277d

+ 1
- 0
gitstats/cli.py Näytä tiedosto

@@ -16,6 +16,7 @@ conf = {
16 16
     'processes': 8,
17 17
     'start_date': '',
18 18
     'logging': logging.INFO,
19
+    'resrouce_file_pattern': '**/resources/**/*',
19 20
 }
20 21
 
21 22
 

+ 3
- 3
gitstats/data_generators/gen_author_data.py Näytä tiedosto

@@ -8,7 +8,7 @@ from gitstats.miscfuncs import getlogrange, getpipeoutput, getstatsummarycounts
8 8
 from gitstats.data import AuthorRow
9 9
 
10 10
 
11
-def gen_author_data(conf, row_processor):
11
+def gen_author_data(conf, row_processor, ignore_files=''):
12 12
     '''
13 13
     Given a configuration, pull authorship information. For
14 14
     each author, callback to the row_processor passing an AuthorRow
@@ -29,8 +29,8 @@ def gen_author_data(conf, row_processor):
29 29
     # The first line(s) is the merge to master or other branch
30 30
     # The last line is the commit on the branch
31 31
     lines = getpipeoutput(
32
-        ['git log --shortstat --date-order --pretty=format:"%%H %%at %%aN" %s' % (
33
-            getlogrange(conf, 'HEAD'))]).split('\n')
32
+        ['git log --shortstat --date-order --pretty=format:"%%H %%at %%aN" %s %s' % (
33
+            getlogrange(conf, 'HEAD'), ignore_files)]).split('\n')
34 34
     lines.reverse()
35 35
 
36 36
     files = 0

+ 3
- 3
gitstats/data_generators/gen_loc_data.py Näytä tiedosto

@@ -10,7 +10,7 @@ from gitstats.data import LocByDate
10 10
 # TODO: the author isn't working here because it's the commit that merges to master, so we
11 11
 # TODO: probably need to back up a commit. Each commit here represents a merged PR
12 12
 
13
-def gen_loc_data(conf, row_processor):
13
+def gen_loc_data(conf, row_processor, ignore_files=''):
14 14
     '''
15 15
     Given a configuration, pull authorship information. For
16 16
     each author, callback to the row_processor passing an AuthorRow
@@ -32,7 +32,7 @@ def gen_loc_data(conf, row_processor):
32 32
 
33 33
     # DBG: git log --shortstat --first-parent -m --pretty=format:"%at %aN" --since="2017-10-01" "HEAD"'
34 34
     lines = getpipeoutput(
35
-        ['git log --shortstat %s --pretty=format:"%%H %%at %%aN" %s' % (extra, getlogrange(conf, 'HEAD'))]).split('\n')
35
+        ['git log --shortstat %s --pretty=format:"%%H %%at %%aN" %s %s' % (extra, getlogrange(conf, 'HEAD'), ignore_files)]).split('\n')
36 36
     lines.reverse()
37 37
     files = 0
38 38
     inserted = 0
@@ -66,7 +66,7 @@ def gen_loc_data(conf, row_processor):
66 66
                 (files, inserted, deleted) = (0, 0, 0)
67 67
 
68 68
     totals = getpipeoutput(
69
-        ['git diff --shortstat `git hash-object -t tree /dev/null`']
69
+        ['git diff --shortstat `git hash-object -t tree /dev/null` %s' % (ignore_files)]
70 70
     )
71 71
     total_files, remainder = totals.strip().split(' file')
72 72
     total_lines = remainder.split('hanged, ')[1].split(' insert')[0]

+ 28
- 17
gitstats/git_csv_generator.py Näytä tiedosto

@@ -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}")