forked from spdx/tools-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelationship_converter.py
More file actions
29 lines (24 loc) · 1.27 KB
/
relationship_converter.py
File metadata and controls
29 lines (24 loc) · 1.27 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
# SPDX-FileCopyrightText: 2022 spdx contributors
#
# SPDX-License-Identifier: Apache-2.0
from beartype.typing import Any, Type
from spdx_tools.spdx.jsonschema.converter import TypedConverter
from spdx_tools.spdx.jsonschema.json_property import JsonProperty
from spdx_tools.spdx.jsonschema.relationship_properties import RelationshipProperty
from spdx_tools.spdx.model import Document, Relationship
class RelationshipConverter(TypedConverter[Relationship]):
def _get_property_value(
self, relationship: Relationship, relationship_property: RelationshipProperty, document: Document | None = None
) -> Any:
if relationship_property == RelationshipProperty.SPDX_ELEMENT_ID:
return relationship.spdx_element_id
elif relationship_property == RelationshipProperty.COMMENT:
return relationship.comment
elif relationship_property == RelationshipProperty.RELATED_SPDX_ELEMENT:
return str(relationship.related_spdx_element_id)
elif relationship_property == RelationshipProperty.RELATIONSHIP_TYPE:
return relationship.relationship_type.name
def get_json_type(self) -> Type[JsonProperty]:
return RelationshipProperty
def get_data_model_type(self) -> Type[Relationship]:
return Relationship