MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / write_spdx

Function write_spdx

src/formattedcode/output_spdx.py:181–407  ·  view source on GitHub ↗

Write scan output as SPDX Tag/value to ``output_file`` file-like object using the ``files`` list of scanned file data. Write as RDF XML if ``as_tagvalue`` is False. Use the ``notice`` string as a notice included in a document comment. Include the ``tool_name`` and ``tool_versio

(
    codebase,
    output_file,
    files,
    tool_name,
    tool_version,
    notice,
    package_name='',
    download_location=SpdxNoAssertion(),
    as_tagvalue=True,
    spdx_version = (2, 2),
    with_notice_text=False,
)

Source from the content-addressed store, hash-verified

179
180
181def write_spdx(
182 codebase,
183 output_file,
184 files,
185 tool_name,
186 tool_version,
187 notice,
188 package_name='',
189 download_location=SpdxNoAssertion(),
190 as_tagvalue=True,
191 spdx_version = (2, 2),
192 with_notice_text=False,
193):
194 """
195 Write scan output as SPDX Tag/value to ``output_file`` file-like
196 object using the ``files`` list of scanned file data.
197 Write as RDF XML if ``as_tagvalue`` is False.
198
199 Use the ``notice`` string as a notice included in a document comment.
200 Include the ``tool_name`` and ``tool_version`` to indicate which tool is
201 producing this SPDX document.
202 Use ``package_name`` as a Package name and as a namespace prefix base.
203 """
204 from licensedcode import cache
205 licenses = cache.get_licenses_db()
206 licensing = Licensing()
207
208 as_rdf = not as_tagvalue
209
210 ns_prefix = '_'.join(package_name.lower().split())
211 comment = notice + f'\nSPDX License List: {scancode_config.spdx_license_list_version}'
212
213 version_major, version_minor = scancode_config.spdx_license_list_version.split(".")
214 spdx_license_list_version = Version(major=version_major, minor=version_minor)
215
216 tool_name = tool_name or 'ScanCode'
217 creator = Actor(ActorType.TOOL, f'{tool_name} {tool_version}')
218
219 creation_info = CreationInfo(
220 spdx_id="SPDXRef-DOCUMENT",
221 spdx_version=f"SPDX-{spdx_version[0]}.{spdx_version[1]}",
222 data_license='CC0-1.0',
223 document_comment=comment,
224 document_namespace=f'http://spdx.org/spdxdocs/{ns_prefix}-{uuid.uuid4()}',
225 license_list_version=spdx_license_list_version,
226 name='SPDX Document created by ScanCode Toolkit',
227 creators=[creator],
228 created=datetime.now(),
229 )
230
231
232 package_id = '001'
233 package = Package(
234 name=package_name,
235 download_location=download_location,
236 spdx_id=f'SPDXRef-{package_id}',
237 )
238

Callers 1

_process_codebaseFunction · 0.85

Calls 13

PackageClass · 0.90
DocumentInterface · 0.85
license_keysMethod · 0.80
getMethod · 0.65
joinMethod · 0.45
splitMethod · 0.45
parseMethod · 0.45
appendMethod · 0.45
updateMethod · 0.45
formatMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected