4343TEMPLATES_DIR = join (dirname (__file__ ), 'templates' )
4444
4545
46- TRACE = False
46+ TRACE = True
4747
4848
4949def logger_debug (* args ):
@@ -83,12 +83,16 @@ def process_codebase(self, codebase, html, **kwargs):
8383 license_references = []
8484 if hasattr (codebase .attributes , 'license_references' ):
8585 license_references = codebase .attributes .license_references
86+ summary = None
87+ if hasattr (codebase .attributes , 'summary' ):
88+ summary = codebase .attributes .summary
8689 template_loc = join (TEMPLATES_DIR , 'html' , 'template.html' )
8790 output_file = html
8891 write_templated (
8992 output_file = output_file ,
9093 results = results ,
9194 license_references = license_references ,
95+ summary = summary ,
9296 version = version ,
9397 template_loc = template_loc ,
9498 )
@@ -133,18 +137,22 @@ def process_codebase(self, codebase, custom_output, custom_template, **kwargs):
133137 license_references = []
134138 if hasattr (codebase .attributes , 'license_references' ):
135139 license_references = codebase .attributes .license_references
140+ summary = None
141+ if hasattr (codebase .attributes , 'summary' ):
142+ summary = codebase .attributes .summary
136143 template_loc = custom_template
137144 output_file = custom_output
138145 write_templated (
139146 output_file = output_file ,
140147 results = results ,
141148 license_references = license_references ,
149+ summary = summary ,
142150 version = version ,
143151 template_loc = template_loc
144152 )
145153
146154
147- def write_templated (output_file , results , license_references , version , template_loc ):
155+ def write_templated (output_file , results , license_references , summary , version , template_loc ):
148156 """
149157 Write scan output `results` to the `output_file` opened file using a template
150158 file at `template_loc`.
@@ -155,6 +163,7 @@ def write_templated(output_file, results, license_references, version, template_
155163 for template_chunk in generate_output (
156164 results = results ,
157165 license_references = license_references ,
166+ summary = summary ,
158167 version = version ,
159168 template = template ,
160169 ):
@@ -184,7 +193,7 @@ def get_template(location):
184193 return env .get_template (template_name )
185194
186195
187- def generate_output (results , license_references , version , template ):
196+ def generate_output (results , license_references , summary , version , template ):
188197 """
189198 Yield unicode strings from incrementally rendering `results` and `version`
190199 with the Jinja `template` object.
@@ -197,11 +206,12 @@ def generate_output(results, license_references, version, template):
197206 converted = {}
198207 converted_infos = {}
199208 converted_packages = {}
200- licenses = {}
209+ licenses = {}
201210
202211 LICENSES = 'license_detections'
203212 COPYRIGHTS = 'copyrights'
204213 PACKAGES = 'package_data'
214+ logger_debug (f"summary: { summary } " )
205215
206216 # Create a flattened data dict keyed by path
207217 for scanned_file in results :
@@ -223,12 +233,21 @@ def generate_output(results, license_references, version, template):
223233 if TRACE :
224234 logger_debug (f"match: { match } " )
225235 license_expression = match ['license_expression' ]
226- results . append ( {
236+ match_data = {
227237 'start' : match ['start_line' ],
228238 'end' : match ['end_line' ],
229239 'what' : 'license' ,
230240 'value' : license_expression ,
231- })
241+ }
242+
243+ if 'matched_text' in match :
244+ match_data ['matched_text' ] = match ['matched_text' ]
245+
246+ if 'matched_text_diagnostics' in match :
247+ logger_debug (match ['matched_text_diagnostics' ])
248+ match_data ['matched_text_diagnostics' ] = match ['matched_text_diagnostics' ]
249+
250+ results .append (match_data )
232251
233252 if not license_references and license_expression not in licenses :
234253 license_object = get_licenses_db ().get (license_expression )
@@ -261,7 +280,7 @@ def generate_output(results, license_references, version, template):
261280 'package_data' : converted_packages
262281 }
263282
264- return template .generate (files = files , license_references = license_references , version = version )
283+ return template .generate (files = files , license_references = license_references , summary = summary , version = version )
265284
266285
267286@output_impl
0 commit comments