spdx_tools.spdx3.bump_from_spdx2.spdx_document
1# SPDX-FileCopyrightText: 2023 spdx contributors 2# 3# SPDX-License-Identifier: Apache-2.0 4from spdx_tools.spdx3.bump_from_spdx2.annotation import bump_annotation 5from spdx_tools.spdx3.bump_from_spdx2.creation_info import bump_creation_info 6from spdx_tools.spdx3.bump_from_spdx2.file import bump_file 7from spdx_tools.spdx3.bump_from_spdx2.package import bump_package 8from spdx_tools.spdx3.bump_from_spdx2.relationship import bump_relationships 9from spdx_tools.spdx3.bump_from_spdx2.snippet import bump_snippet 10from spdx_tools.spdx3.model import CreationInfo, SpdxDocument 11from spdx_tools.spdx3.payload import Payload 12from spdx_tools.spdx.model import RelationshipType 13from spdx_tools.spdx.model.document import Document as Spdx2_Document 14from spdx_tools.spdx.model.relationship_filters import filter_by_type_and_origin 15 16""" We want to implement a bump_from_spdx2 from the data model in src.spdx to the data model in src.spdx3. 17 As there are many fundamental differences between these version we want each bump_from_spdx2 method to take 18 the object from src.spdx and add all objects that the input is translated to into the payload.""" 19 20 21def bump_spdx_document(document: Spdx2_Document) -> Payload: 22 payload = Payload() 23 document_namespace: str = document.creation_info.document_namespace 24 spdx_document: SpdxDocument = bump_creation_info(document.creation_info, payload) 25 spdx_document.root_element = [ 26 f"{document_namespace}#{relationship.related_spdx_element_id}" 27 for relationship in filter_by_type_and_origin( 28 document.relationships, RelationshipType.DESCRIBES, "SPDXRef-DOCUMENT" 29 ) 30 ] 31 32 creation_info: CreationInfo = spdx_document.creation_info 33 34 payload.add_element(spdx_document) 35 36 for spdx2_package in document.packages: 37 bump_package( 38 spdx2_package, 39 payload, 40 document_namespace, 41 document.creation_info.external_document_refs, 42 spdx_document.imports, 43 ) 44 45 for spdx2_file in document.files: 46 bump_file( 47 spdx2_file, 48 payload, 49 document_namespace, 50 document.creation_info.external_document_refs, 51 spdx_document.imports, 52 ) 53 54 for spdx2_snippet in document.snippets: 55 bump_snippet( 56 spdx2_snippet, 57 payload, 58 document_namespace, 59 document.creation_info.external_document_refs, 60 spdx_document.imports, 61 ) 62 63 bump_relationships(document.relationships, payload, document_namespace) 64 65 for counter, spdx2_annotation in enumerate(document.annotations): 66 bump_annotation(spdx2_annotation, payload, creation_info, document_namespace, counter) 67 68 spdx_document.element = [spdx_id for spdx_id in payload.get_full_map() if spdx_id != spdx_document.spdx_id] 69 70 return payload
def
bump_spdx_document( document: spdx_tools.spdx.model.document.Document) -> spdx_tools.spdx3.payload.Payload:
22def bump_spdx_document(document: Spdx2_Document) -> Payload: 23 payload = Payload() 24 document_namespace: str = document.creation_info.document_namespace 25 spdx_document: SpdxDocument = bump_creation_info(document.creation_info, payload) 26 spdx_document.root_element = [ 27 f"{document_namespace}#{relationship.related_spdx_element_id}" 28 for relationship in filter_by_type_and_origin( 29 document.relationships, RelationshipType.DESCRIBES, "SPDXRef-DOCUMENT" 30 ) 31 ] 32 33 creation_info: CreationInfo = spdx_document.creation_info 34 35 payload.add_element(spdx_document) 36 37 for spdx2_package in document.packages: 38 bump_package( 39 spdx2_package, 40 payload, 41 document_namespace, 42 document.creation_info.external_document_refs, 43 spdx_document.imports, 44 ) 45 46 for spdx2_file in document.files: 47 bump_file( 48 spdx2_file, 49 payload, 50 document_namespace, 51 document.creation_info.external_document_refs, 52 spdx_document.imports, 53 ) 54 55 for spdx2_snippet in document.snippets: 56 bump_snippet( 57 spdx2_snippet, 58 payload, 59 document_namespace, 60 document.creation_info.external_document_refs, 61 spdx_document.imports, 62 ) 63 64 bump_relationships(document.relationships, payload, document_namespace) 65 66 for counter, spdx2_annotation in enumerate(document.annotations): 67 bump_annotation(spdx2_annotation, payload, creation_info, document_namespace, counter) 68 69 spdx_document.element = [spdx_id for spdx_id in payload.get_full_map() if spdx_id != spdx_document.spdx_id] 70 71 return payload