-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlicense_tools.py
155 lines (128 loc) · 4.86 KB
/
license_tools.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# -------------------------------------------------------------------------------
# (c) 2019-2022 Siemens AG
# All Rights Reserved.
# Author: [email protected]
#
# Licensed under the MIT license.
# SPDX-License-Identifier: MIT
# -------------------------------------------------------------------------------
from typing import List, Optional
from .CLI import CliFile
from .cli_license import CliLicense
class LicenseTools:
"""Tools for license and CLI file processing."""
NOT_README_TAG = "NOT_README_OSS"
NON_FUNCTIONAL_TAG = "NON_FUNCTIONAL"
NON_USED_DUAL_LICENSE_TAG = "NOT_USED_DUAL_LICENSE"
MANUAL_CHECK_NEEDED_TAG = "MANUAL_CHECK_NEEDED"
@staticmethod
def get_global_license(clifile: CliFile) -> Optional[CliLicense]:
"""Determines the global license."""
for lic in clifile.licenses:
if lic.type.upper() == "GLOBAL":
return lic
return None
@staticmethod
def get_non_global_licenses(clifile: CliFile) -> List[CliLicense]:
"""Gets the non global licenses."""
result: List[CliLicense] = []
for lic in clifile.licenses:
if lic.type.upper() != "GLOBAL":
result.append(lic)
return result
@staticmethod
def has_license(clifile: CliFile, spdx_identifier: str) -> bool:
"""Determines whether the specified component has the
specified license."""
for lic in clifile.licenses:
if lic.spdx_identifier.upper() == spdx_identifier.upper():
return True
return False
@staticmethod
def is_source_code_shipping_license(spdx_identifier: str) -> bool:
"""Determines whether this is a license where the source code needs to
be ready to be shipped to customers.
Please note that this is a very simplified approach."""
licenseUpper = spdx_identifier.upper()
if "GPL" in licenseUpper: # includes LGPL
return True
if "CDDL" in licenseUpper:
return True
if "EPL" in licenseUpper:
return True
if "ECOS" in licenseUpper:
return True
if "EUPL" in licenseUpper:
return True
if "MPL" in licenseUpper:
return True
if "MS-RL" in licenseUpper:
return True
return False
@staticmethod
def is_multi_license(spdx_identifier: str) -> bool:
"""Determines whether the licenses is a dual/multi license."""
licenseUpper = spdx_identifier.upper()
if "DUAL" in licenseUpper:
return True
if "TRIPLE" in licenseUpper:
return True
if "QUADRUPLE" in licenseUpper:
return True
if "MULTI" in licenseUpper:
return True
if " OR " in licenseUpper:
return True
if " AND " in licenseUpper:
return True
return False
@staticmethod
def is_do_not_use_license(license: CliLicense) -> bool:
"""Determines whether this license is a 'do not use' license."""
typeUpper = license.type.upper()
if typeUpper == "OTHER_RED":
return True
if typeUpper == "OTHERRED":
return True
if typeUpper == "RED":
return True
return False
@staticmethod
def has_multi_license(clifile: CliFile) -> bool:
"""Determines whether this component has at least one multi license."""
for lic in clifile.licenses:
if LicenseTools.is_multi_license(lic.spdx_identifier):
return True
return False
@staticmethod
def has_do_not_use_files(clifile: CliFile) -> bool:
"""Determines whether this component has at least one
'do not use' license/file."""
for lic in clifile.licenses:
if LicenseTools.is_do_not_use_license(lic):
return True
return False
@staticmethod
def has_source_code_shipping_license(clifile: CliFile) -> bool:
"""Determines whether this component has at least one license
where the source code needs to get shipped."""
for lic in clifile.licenses:
if LicenseTools.is_source_code_shipping_license(lic.spdx_identifier):
return True
return False
@staticmethod
def license_has_not_readme_tag(license: CliLicense) -> bool:
"""Determines whether the specified item has a
'not for Readme_OSS' tag."""
for tag in license.tags:
if tag.upper() == LicenseTools.NOT_README_TAG:
return True
return False
@staticmethod
def component_has_not_readme_tag(clifile: CliFile) -> bool:
"""Determines whether the specified item has a
'not for Readme_OSS' tag."""
for tag in clifile.tags:
if tag.upper() == LicenseTools.NOT_README_TAG:
return True
return False