forked from spdx/tools-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextracted_licensing_info_converter.py
More file actions
35 lines (30 loc) · 1.75 KB
/
extracted_licensing_info_converter.py
File metadata and controls
35 lines (30 loc) · 1.75 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
# 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.extracted_licensing_info_properties import ExtractedLicensingInfoProperty
from spdx_tools.spdx.jsonschema.json_property import JsonProperty
from spdx_tools.spdx.jsonschema.optional_utils import apply_if_present
from spdx_tools.spdx.model import Document, ExtractedLicensingInfo
class ExtractedLicensingInfoConverter(TypedConverter[ExtractedLicensingInfo]):
def _get_property_value(
self,
extracted_licensing_info: ExtractedLicensingInfo,
extracted_licensing_info_property: ExtractedLicensingInfoProperty,
document: Document | None = None,
) -> Any:
if extracted_licensing_info_property == ExtractedLicensingInfoProperty.COMMENT:
return extracted_licensing_info.comment
elif extracted_licensing_info_property == ExtractedLicensingInfoProperty.EXTRACTED_TEXT:
return extracted_licensing_info.extracted_text
elif extracted_licensing_info_property == ExtractedLicensingInfoProperty.LICENSE_ID:
return extracted_licensing_info.license_id
elif extracted_licensing_info_property == ExtractedLicensingInfoProperty.NAME:
return apply_if_present(str, extracted_licensing_info.license_name)
elif extracted_licensing_info_property == ExtractedLicensingInfoProperty.SEE_ALSOS:
return extracted_licensing_info.cross_references or None
def get_json_type(self) -> Type[JsonProperty]:
return ExtractedLicensingInfoProperty
def get_data_model_type(self) -> Type[ExtractedLicensingInfo]:
return ExtractedLicensingInfo