FOSSology  4.7.1
Open Source License Compliance by Open Source Software
FoScanner.Spdx3Report.Spdx3Report Class Reference
Inheritance diagram for FoScanner.Spdx3Report.Spdx3Report:
Inheritance graph
Collaboration diagram for FoScanner.Spdx3Report.Spdx3Report:
Collaboration graph

Public Member Functions

def __init__ (self, CliOptions cli_options, Scanners scanner)
 
def finalize_document (self)
 
def write_report (self, str file_name)
 

Public Attributes

 cli_options
 
 scanner
 
 payload
 
 creation_info
 
 root_package
 
- Public Attributes inherited from FoScanner.ReportBase.ReportBase
 cli_options
 
 scanner
 

Private Member Functions

def _deduplicate_creation_info (self, g, rdflib)
 
def _fixup_rdf_graph (self, g, rdflib)
 
def _process_component (self, dict component, str parent_pkg_id)
 
def _resolve_licenses (self, list[str] licenses)
 
def _get_license_object (self, str lic_id)
 
Package _get_or_create_dep_package (self, dict component)
 
None _validate_report (self, str file_name)
 

Static Private Member Functions

def _load_spdx_shacl_model ()
 
def _type_satisfies (existing_types, expected_class, subclass_map)
 
str _make_base_uri (str doc_name)
 
def _sanitize_xml_literals (g, rdflib)
 
str _rdf_format_for_file (str file_name)
 

Private Attributes

 _rel_idx
 
 _file_idx
 
 _spdx_licensing
 
 _base
 

Static Private Attributes

 _XML_INVALID_RE
 

Detailed Description

Handle SPDX 3.0 reports.

:ivar cli_options: CliOptions object
:ivar scanner: Scanners object
:ivar payload: spdx_tools Payload holding all SPDX 3.0 elements
:ivar root_package: Root Package element for the scanned project
:ivar creation_info: Shared CreationInfo for all elements

Definition at line 71 of file Spdx3Report.py.

Constructor & Destructor Documentation

◆ __init__()

def FoScanner.Spdx3Report.Spdx3Report.__init__ (   self,
CliOptions  cli_options,
Scanners  scanner 
)
Initialise the SPDX 3.0 report builder.

:param cli_options: CliOptions to use
:param scanner:     Scanners to use

Reimplemented from FoScanner.ReportBase.ReportBase.

Definition at line 82 of file Spdx3Report.py.

Member Function Documentation

◆ _deduplicate_creation_info()

def FoScanner.Spdx3Report.Spdx3Report._deduplicate_creation_info (   self,
  g,
  rdflib 
)
private
Merge identical CreationInfo blank nodes into a single named node.

The spdx-tools JSON-LD serializer inlines CreationInfo as blank nodes,
causing duplication. This replaces all of them with one shared URI node.

Definition at line 279 of file Spdx3Report.py.

◆ _get_license_object()

def FoScanner.Spdx3Report.Spdx3Report._get_license_object (   self,
str  lic_id 
)
private
Return a cached LicenseExpression or CustomLicense for a single ID.

For SPDX-listed licenses, creates a LicenseExpression with just the
spdx expression string (no full license object needed per the spec).
For custom/unknown licenses, creates a CustomLicense with licenseText
as required by the SPDX 3.0 spec (minCount=1).

Definition at line 516 of file Spdx3Report.py.

◆ _get_or_create_dep_package()

Package FoScanner.Spdx3Report.Spdx3Report._get_or_create_dep_package (   self,
dict  component 
)
private
Create (or retrieve cached) a dependency Package element.

Definition at line 549 of file Spdx3Report.py.

◆ _load_spdx_shacl_model()

def FoScanner.Spdx3Report.Spdx3Report._load_spdx_shacl_model ( )
staticprivate
Load the SPDX SHACL model bundled with spdx-tools.

:return: (rdflib.Graph, shacl_path_str)

Definition at line 267 of file Spdx3Report.py.

◆ _make_base_uri()

str FoScanner.Spdx3Report.Spdx3Report._make_base_uri ( str  doc_name)
staticprivate
Generate a unique base URI for the document.

Definition at line 573 of file Spdx3Report.py.

◆ _process_component()

def FoScanner.Spdx3Report.Spdx3Report._process_component (   self,
dict  component,
str  parent_pkg_id 
)
private
Read SCANNER_RESULTS and COPYRIGHT_RESULT from *component* dict,
create File elements, and wire CONTAINS relationships.

Definition at line 415 of file Spdx3Report.py.

◆ _rdf_format_for_file()

str FoScanner.Spdx3Report.Spdx3Report._rdf_format_for_file ( str  file_name)
staticprivate
Determine the rdflib serialization format from a file extension.

Uses rdflib's own ``SUFFIX_FORMAT_MAP`` so that new formats are
supported automatically without code changes. Falls back to
``json-ld`` for unknown extensions.

Definition at line 604 of file Spdx3Report.py.

◆ _resolve_licenses()

def FoScanner.Spdx3Report.Spdx3Report._resolve_licenses (   self,
list[str]  licenses 
)
private
Resolve a list of license identifiers to the correct SPDX 3.0 model
objects.

- SPDX-listed licenses → ListedLicense (ExpandedLicensing)
- Non-SPDX licenses → CustomLicense with LicenseRef- prefix
- Multiple licenses → ConjunctiveLicenseSet (AND semantics)
- No licenses → NoAssertionLicense

Objects are cached so the same license ID reuses one instance.

Definition at line 495 of file Spdx3Report.py.

◆ _sanitize_xml_literals()

def FoScanner.Spdx3Report.Spdx3Report._sanitize_xml_literals (   g,
  rdflib 
)
staticprivate
Remove characters that are invalid in XML 1.0 from all Literal values.

rdflib's RDF/XML serializer writes these characters verbatim, but
XML parsers (expat) reject them on re-read, causing 'not well-formed'
errors.  Only needed for XML-based output formats.

Definition at line 587 of file Spdx3Report.py.

◆ _type_satisfies()

def FoScanner.Spdx3Report.Spdx3Report._type_satisfies (   existing_types,
  expected_class,
  subclass_map 
)
staticprivate
Check whether any of *existing_types* equals *expected_class* or is
a known subclass of it (according to *subclass_map*).

Definition at line 403 of file Spdx3Report.py.

◆ _validate_report()

None FoScanner.Spdx3Report.Spdx3Report._validate_report (   self,
str  file_name 
)
private
Validate the written SPDX 3.0 report using pyshacl against the
SHACL schema bundled with spdx-tools.

Works for any RDF serialization format (Turtle, JSON-LD, RDF/XML, etc.).

Definition at line 615 of file Spdx3Report.py.

◆ finalize_document()

def FoScanner.Spdx3Report.Spdx3Report.finalize_document (   self)
Process all scan results (parent + dependencies), create File elements
and Relationships, then build the SpdxDocument.

Reimplemented from FoScanner.ReportBase.ReportBase.

Definition at line 161 of file Spdx3Report.py.

◆ write_report()

def FoScanner.Spdx3Report.Spdx3Report.write_report (   self,
str  file_name 
)
Validate and serialize the report to *file_name*.

:param file_name: Destination path for the generated report.
:raises RuntimeError: If validation or serialization fails.

Reimplemented from FoScanner.ReportBase.ReportBase.

Definition at line 217 of file Spdx3Report.py.

Member Data Documentation

◆ _XML_INVALID_RE

FoScanner.Spdx3Report.Spdx3Report._XML_INVALID_RE
staticprivate
Initial value:
= re.compile(
'[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x84\x86-\x9f'
'\ud800-\udfff\ufdd0-\ufdef\ufffe\uffff]'
)

Definition at line 581 of file Spdx3Report.py.


The documentation for this class was generated from the following file: