forked from spdx/tools-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspdx_document.py
More file actions
45 lines (34 loc) · 2.24 KB
/
Copy pathspdx_document.py
File metadata and controls
45 lines (34 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# SPDX-FileCopyrightText: 2023 spdx contributors
#
# SPDX-License-Identifier: Apache-2.0
from spdx_tools.spdx3.bump_from_spdx2.annotation import bump_annotation
from spdx_tools.spdx3.bump_from_spdx2.creation_information import bump_creation_information
from spdx_tools.spdx3.bump_from_spdx2.file import bump_file
from spdx_tools.spdx3.bump_from_spdx2.package import bump_package
from spdx_tools.spdx3.bump_from_spdx2.relationship import bump_relationship
from spdx_tools.spdx3.bump_from_spdx2.snippet import bump_snippet
from spdx_tools.spdx3.model.creation_information import CreationInformation
from spdx_tools.spdx3.model.spdx_document import SpdxDocument
from spdx_tools.spdx3.payload import Payload
from spdx_tools.spdx.model.document import Document as Spdx2_Document
""" We want to implement a bump_from_spdx2 from the data model in src.spdx to the data model in src.spdx3.
As there are many fundamental differences between these version we want each bump_from_spdx2 method to take
the object from src.spdx and add all objects that the input is translated to into the payload."""
def bump_spdx_document(document: Spdx2_Document) -> Payload:
payload = Payload()
document_namespace: str = document.creation_info.document_namespace
spdx_document: SpdxDocument = bump_creation_information(document.creation_info, payload)
creation_info: CreationInformation = spdx_document.creation_info
payload.add_element(spdx_document)
for spdx2_package in document.packages:
bump_package(spdx2_package, payload, creation_info, document_namespace)
for spdx2_file in document.files:
bump_file(spdx2_file, payload, creation_info, document_namespace)
for spdx2_snippet in document.snippets:
bump_snippet(spdx2_snippet, payload, creation_info, document_namespace)
for counter, spdx2_relationship in enumerate(document.relationships):
bump_relationship(spdx2_relationship, payload, creation_info, document_namespace, counter)
for counter, spdx2_annotation in enumerate(document.annotations):
bump_annotation(spdx2_annotation, payload, creation_info, document_namespace, counter)
spdx_document.elements = [spdx_id for spdx_id in payload.get_full_map() if spdx_id != spdx_document.spdx_id]
return payload