spdx_tools.spdx3.writer.console.element_writer

 1# SPDX-FileCopyrightText: 2023 spdx contributors
 2#
 3# SPDX-License-Identifier: Apache-2.0
 4from beartype.typing import TextIO
 5
 6from spdx_tools.spdx3.model import Element
 7from spdx_tools.spdx3.writer.console.console import write_value
 8from spdx_tools.spdx3.writer.console.creation_info_writer import write_creation_info
 9from spdx_tools.spdx3.writer.console.external_identifier_writer import write_external_identifier
10from spdx_tools.spdx3.writer.console.external_reference_writer import write_external_reference
11from spdx_tools.spdx3.writer.console.hash_writer import write_hash
12from spdx_tools.spdx.writer.tagvalue.tagvalue_writer_helper_functions import write_optional_heading
13
14
15def write_element_properties(element: Element, text_output: TextIO):
16    write_value("SPDXID", element.spdx_id, text_output)
17    write_value("name", element.name, text_output)
18    if element.creation_info:
19        write_creation_info(element.creation_info, text_output, True)
20    write_value("summary", element.summary, text_output)
21    write_value("description", element.description, text_output)
22    write_value("comment", element.comment, text_output)
23    write_optional_heading(element.verified_using, "verified using:\n", text_output)
24    for integrity_method in element.verified_using:
25        # for now Hash is the only child class of the abstract class IntegrityMethod,
26        # as soon as there are more inherited classes we need to implement a logic
27        # that determines the correct write function for the "integrity_method" object
28        write_hash(integrity_method, text_output, heading=False)
29    write_optional_heading(element.external_reference, "External Reference\n", text_output)
30    for external_reference in element.external_reference:
31        write_external_reference(external_reference, text_output)
32    write_optional_heading(element.external_identifier, "External Identifier\n", text_output)
33    for external_identifier in element.external_identifier:
34        write_external_identifier(external_identifier, text_output)
def write_element_properties( element: spdx_tools.spdx3.model.element.Element, text_output: <class 'TextIO'>):
16def write_element_properties(element: Element, text_output: TextIO):
17    write_value("SPDXID", element.spdx_id, text_output)
18    write_value("name", element.name, text_output)
19    if element.creation_info:
20        write_creation_info(element.creation_info, text_output, True)
21    write_value("summary", element.summary, text_output)
22    write_value("description", element.description, text_output)
23    write_value("comment", element.comment, text_output)
24    write_optional_heading(element.verified_using, "verified using:\n", text_output)
25    for integrity_method in element.verified_using:
26        # for now Hash is the only child class of the abstract class IntegrityMethod,
27        # as soon as there are more inherited classes we need to implement a logic
28        # that determines the correct write function for the "integrity_method" object
29        write_hash(integrity_method, text_output, heading=False)
30    write_optional_heading(element.external_reference, "External Reference\n", text_output)
31    for external_reference in element.external_reference:
32        write_external_reference(external_reference, text_output)
33    write_optional_heading(element.external_identifier, "External Identifier\n", text_output)
34    for external_identifier in element.external_identifier:
35        write_external_identifier(external_identifier, text_output)