4646from spdx .utils import SPDXNone
4747from spdx .version import Version
4848
49- from formattedcode .utils import get_headings
5049from plugincode .output import output_impl
5150from plugincode .output import OutputPlugin
5251from scancode import CommandLineOption
@@ -101,12 +100,12 @@ def _patch_license_list():
101100 from spdx .config import LICENSE_MAP
102101 from licensedcode .models import load_licenses
103102 licenses = load_licenses (with_deprecated = True )
104- spdx_licenses = get_by_spdx (licenses .values ())
103+ spdx_licenses = get_licenses_by_spdx_key (licenses .values ())
105104 LICENSE_MAP .update (spdx_licenses )
106105 _spdx_list_is_patched = True
107106
108107
109- def get_by_spdx (licenses ):
108+ def get_licenses_by_spdx_key (licenses ):
110109 """
111110 Return a mapping of {spdx_key: license object} given a sequence of License
112111 objects.
@@ -149,9 +148,13 @@ def is_enabled(self, spdx_tv, info, **kwargs):
149148
150149 def process_codebase (self , codebase , spdx_tv , ** kwargs ):
151150 input = kwargs .get ('input' , '' ) # NOQA
152- results = self .get_results (codebase , ** kwargs )
153- _files_count , version , notice , _scan_start , _options = get_headings (codebase )
154- write_spdx (spdx_tv , results , version , notice , input , as_tagvalue = True )
151+ files = self .get_files (codebase , ** kwargs )
152+ header = codebase .get_or_create_current_header ()
153+ tool_name = header .tool_name
154+ tool_version = header .tool_version
155+ notice = header .notice
156+ write_spdx (
157+ spdx_tv , files , tool_name , tool_version , notice , input , as_tagvalue = True )
155158
156159
157160@output_impl
@@ -171,13 +174,16 @@ def is_enabled(self, spdx_rdf, info, **kwargs):
171174
172175 def process_codebase (self , codebase , spdx_rdf , ** kwargs ):
173176 input = kwargs .get ('input' , '' ) # NOQA
174- results = self .get_results (codebase , ** kwargs )
175- _files_count , version , notice , _scan_start , _options = get_headings (codebase )
176- write_spdx (spdx_rdf , results , version , notice , input , as_tagvalue = False )
177+ files = self .get_files (codebase , ** kwargs )
178+ header = codebase .get_or_create_current_header ()
179+ tool_name = header .tool_name
180+ tool_version = header .tool_version
181+ notice = header .notice
182+ write_spdx (
183+ spdx_rdf , files , tool_name , tool_version , notice , input , as_tagvalue = False )
177184
178185
179- def write_spdx (output_file , results , scancode_version , scancode_notice ,
180- input_file , as_tagvalue = True ):
186+ def write_spdx (output_file , files , tool_name , tool_version , notice , input_file , as_tagvalue = True ):
181187 """
182188 Write scan output as SPDX Tag/value or RDF.
183189 """
@@ -191,9 +197,9 @@ def write_spdx(output_file, results, scancode_version, scancode_notice,
191197 input_path = dirname (absinput )
192198
193199 doc = Document (Version (2 , 1 ), License .from_identifier ('CC0-1.0' ))
194- doc .comment = scancode_notice
195-
196- doc .creation_info .add_creator (Tool ('ScanCode ' + scancode_version ))
200+ doc .comment = notice
201+ tool_name = tool_name or 'ScanCode'
202+ doc .creation_info .add_creator (Tool (tool_name + ' ' + tool_version ))
197203 doc .creation_info .set_created_now ()
198204
199205 package = doc .package = Package (
@@ -208,7 +214,7 @@ def write_spdx(output_file, results, scancode_version, scancode_notice,
208214 all_files_have_no_copyright = True
209215
210216 # FIXME: this should walk the codebase instead!!!
211- for file_data in results :
217+ for file_data in files :
212218 # Construct the absolute path in case we need to access the file
213219 # to calculate its SHA1.
214220 file_entry = File (join (input_path , file_data .get ('path' )))
0 commit comments