scanoss 1.20.0__py3-none-any.whl → 1.20.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. protoc_gen_swagger/__init__.py +13 -13
  2. protoc_gen_swagger/options/__init__.py +13 -13
  3. protoc_gen_swagger/options/annotations_pb2.py +12 -9
  4. protoc_gen_swagger/options/annotations_pb2_grpc.py +1 -1
  5. protoc_gen_swagger/options/openapiv2_pb2.py +98 -96
  6. protoc_gen_swagger/options/openapiv2_pb2_grpc.py +1 -1
  7. scanoss/__init__.py +18 -18
  8. scanoss/api/__init__.py +17 -17
  9. scanoss/api/common/__init__.py +17 -17
  10. scanoss/api/common/v2/__init__.py +17 -17
  11. scanoss/api/common/v2/scanoss_common_pb2.py +18 -18
  12. scanoss/api/common/v2/scanoss_common_pb2_grpc.py +1 -1
  13. scanoss/api/components/__init__.py +17 -17
  14. scanoss/api/components/v2/__init__.py +17 -17
  15. scanoss/api/components/v2/scanoss_components_pb2.py +48 -38
  16. scanoss/api/components/v2/scanoss_components_pb2_grpc.py +142 -96
  17. scanoss/api/cryptography/v2/scanoss_cryptography_pb2.py +22 -16
  18. scanoss/api/cryptography/v2/scanoss_cryptography_pb2_grpc.py +75 -49
  19. scanoss/api/dependencies/__init__.py +17 -17
  20. scanoss/api/dependencies/v2/__init__.py +17 -17
  21. scanoss/api/dependencies/v2/scanoss_dependencies_pb2.py +30 -24
  22. scanoss/api/dependencies/v2/scanoss_dependencies_pb2_grpc.py +75 -49
  23. scanoss/api/scanning/__init__.py +17 -17
  24. scanoss/api/scanning/v2/__init__.py +17 -17
  25. scanoss/api/scanning/v2/scanoss_scanning_pb2.py +10 -8
  26. scanoss/api/scanning/v2/scanoss_scanning_pb2_grpc.py +40 -32
  27. scanoss/api/semgrep/__init__.py +17 -17
  28. scanoss/api/semgrep/v2/__init__.py +17 -17
  29. scanoss/api/semgrep/v2/scanoss_semgrep_pb2.py +22 -18
  30. scanoss/api/semgrep/v2/scanoss_semgrep_pb2_grpc.py +71 -49
  31. scanoss/api/vulnerabilities/__init__.py +17 -17
  32. scanoss/api/vulnerabilities/v2/__init__.py +17 -17
  33. scanoss/api/vulnerabilities/v2/scanoss_vulnerabilities_pb2.py +37 -27
  34. scanoss/api/vulnerabilities/v2/scanoss_vulnerabilities_pb2_grpc.py +109 -72
  35. scanoss/cli.py +664 -356
  36. scanoss/components.py +67 -45
  37. scanoss/csvoutput.py +83 -56
  38. scanoss/cyclonedx.py +48 -46
  39. scanoss/data/build_date.txt +1 -1
  40. scanoss/file_filters.py +13 -15
  41. scanoss/filecount.py +43 -36
  42. scanoss/inspection/__init__.py +17 -17
  43. scanoss/inspection/copyleft.py +71 -58
  44. scanoss/inspection/policy_check.py +76 -53
  45. scanoss/inspection/undeclared_component.py +98 -75
  46. scanoss/inspection/utils/license_utils.py +66 -44
  47. scanoss/results.py +51 -60
  48. scanoss/scancodedeps.py +61 -38
  49. scanoss/scanner.py +203 -135
  50. scanoss/scanoss_settings.py +5 -3
  51. scanoss/scanossapi.py +98 -69
  52. scanoss/scanossbase.py +19 -19
  53. scanoss/scanossgrpc.py +73 -51
  54. scanoss/scanpostprocessor.py +9 -6
  55. scanoss/scantype.py +22 -21
  56. scanoss/spdxlite.py +265 -171
  57. scanoss/threadeddependencies.py +91 -61
  58. scanoss/threadedscanning.py +37 -31
  59. scanoss/utils/file.py +4 -4
  60. scanoss/winnowing.py +111 -47
  61. {scanoss-1.20.0.dist-info → scanoss-1.20.2.dist-info}/METADATA +1 -1
  62. scanoss-1.20.2.dist-info/RECORD +74 -0
  63. {scanoss-1.20.0.dist-info → scanoss-1.20.2.dist-info}/WHEEL +1 -1
  64. scanoss-1.20.0.dist-info/RECORD +0 -74
  65. {scanoss-1.20.0.dist-info → scanoss-1.20.2.dist-info}/LICENSE +0 -0
  66. {scanoss-1.20.0.dist-info → scanoss-1.20.2.dist-info}/entry_points.txt +0 -0
  67. {scanoss-1.20.0.dist-info → scanoss-1.20.2.dist-info}/top_level.txt +0 -0
@@ -1,38 +1,49 @@
1
1
  """
2
- SPDX-License-Identifier: MIT
3
-
4
- Copyright (c) 2024, SCANOSS
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in
14
- all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- THE SOFTWARE.
2
+ SPDX-License-Identifier: MIT
3
+
4
+ Copyright (c) 2024, SCANOSS
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
23
23
  """
24
+
24
25
  import json
25
26
  from typing import Dict, Any
26
27
  from .policy_check import PolicyCheck, PolicyStatus
27
28
 
29
+
28
30
  class UndeclaredComponent(PolicyCheck):
29
31
  """
30
32
  SCANOSS UndeclaredComponent class
31
33
  Inspects for undeclared components
32
34
  """
33
35
 
34
- def __init__(self, debug: bool = False, trace: bool = True, quiet: bool = False, filepath: str = None,
35
- format_type: str = 'json', status: str = None, output: str = None, sbom_format: str = 'settings'):
36
+ def __init__(
37
+ self,
38
+ debug: bool = False,
39
+ trace: bool = True,
40
+ quiet: bool = False,
41
+ filepath: str = None,
42
+ format_type: str = 'json',
43
+ status: str = None,
44
+ output: str = None,
45
+ sbom_format: str = 'settings',
46
+ ):
36
47
  """
37
48
  Initialize the UndeclaredComponent class.
38
49
 
@@ -45,20 +56,21 @@ class UndeclaredComponent(PolicyCheck):
45
56
  :param output: Path to save detailed output
46
57
  :param sbom_format: Sbom format for status output (default 'settings')
47
58
  """
48
- super().__init__(debug, trace, quiet, filepath, format_type, status, output,
49
- name='Undeclared Components Policy')
59
+ super().__init__(
60
+ debug, trace, quiet, filepath, format_type, status, output, name='Undeclared Components Policy'
61
+ )
50
62
  self.filepath = filepath
51
63
  self.format = format
52
64
  self.output = output
53
65
  self.status = status
54
66
  self.sbom_format = sbom_format
55
67
 
56
- def _get_undeclared_component(self, components: list)-> list or None:
68
+ def _get_undeclared_component(self, components: list) -> list or None:
57
69
  """
58
- Filter the components list to include only undeclared components.
70
+ Filter the components list to include only undeclared components.
59
71
 
60
- :param components: List of all components
61
- :return: List of undeclared components
72
+ :param components: List of all components
73
+ :return: List of undeclared components
62
74
  """
63
75
  if components is None:
64
76
  self.print_debug(f'WARNING: No components provided!')
@@ -73,24 +85,29 @@ class UndeclaredComponent(PolicyCheck):
73
85
 
74
86
  def _get_jira_summary(self, components: list) -> str:
75
87
  """
76
- Get a summary of the undeclared components.
88
+ Get a summary of the undeclared components.
77
89
 
78
- :param components: List of all components
79
- :return: Component summary markdown
80
- """
90
+ :param components: List of all components
91
+ :return: Component summary markdown
92
+ """
81
93
  if len(components) > 0:
82
94
  if self.sbom_format == 'settings':
83
- json_str = (json.dumps(self._generate_scanoss_file(components), indent=2).replace('\n', '\\n')
84
- .replace('"', '\\"'))
95
+ json_str = (
96
+ json.dumps(self._generate_scanoss_file(components), indent=2)
97
+ .replace('\n', '\\n')
98
+ .replace('"', '\\"')
99
+ )
85
100
  return f'{len(components)} undeclared component(s) were found.\nAdd the following snippet into your `scanoss.json` file\n{{code:json}}\n{json.dumps(self._generate_scanoss_file(components), indent=2)}\n{{code}}\n'
86
101
  else:
87
- json_str = (json.dumps(self._generate_scanoss_file(components), indent=2).replace('\n', '\\n')
88
- .replace('"', '\\"'))
102
+ json_str = (
103
+ json.dumps(self._generate_scanoss_file(components), indent=2)
104
+ .replace('\n', '\\n')
105
+ .replace('"', '\\"')
106
+ )
89
107
  return f'{len(components)} undeclared component(s) were found.\nAdd the following snippet into your `sbom.json` file\n{{code:json}}\n{json.dumps(self._generate_scanoss_file(components), indent=2)}\n{{code}}\n'
90
108
 
91
109
  return f'{len(components)} undeclared component(s) were found.\\n'
92
110
 
93
-
94
111
  def _get_summary(self, components: list) -> str:
95
112
  """
96
113
  Get a summary of the undeclared components.
@@ -101,11 +118,15 @@ class UndeclaredComponent(PolicyCheck):
101
118
  summary = f'{len(components)} undeclared component(s) were found.\n'
102
119
  if len(components) > 0:
103
120
  if self.sbom_format == 'settings':
104
- summary += (f'Add the following snippet into your `scanoss.json` file\n'
105
- f'\n```json\n{json.dumps(self._generate_scanoss_file(components), indent=2)}\n```\n')
121
+ summary += (
122
+ f'Add the following snippet into your `scanoss.json` file\n'
123
+ f'\n```json\n{json.dumps(self._generate_scanoss_file(components), indent=2)}\n```\n'
124
+ )
106
125
  else:
107
- summary += (f'Add the following snippet into your `sbom.json` file\n'
108
- f'\n```json\n{json.dumps(self._generate_sbom_file(components), indent=2)}\n```\n')
126
+ summary += (
127
+ f'Add the following snippet into your `sbom.json` file\n'
128
+ f'\n```json\n{json.dumps(self._generate_sbom_file(components), indent=2)}\n```\n'
129
+ )
109
130
 
110
131
  return summary
111
132
 
@@ -120,71 +141,71 @@ class UndeclaredComponent(PolicyCheck):
120
141
  if len(components) > 0:
121
142
  details = {'components': components}
122
143
  return {
123
- 'details': f'{json.dumps(details, indent=2)}\n',
144
+ 'details': f'{json.dumps(details, indent=2)}\n',
124
145
  'summary': self._get_summary(components),
125
146
  }
126
147
 
127
- def _markdown(self, components: list) -> Dict[str,Any]:
148
+ def _markdown(self, components: list) -> Dict[str, Any]:
128
149
  """
129
- Format the undeclared components as Markdown.
150
+ Format the undeclared components as Markdown.
130
151
 
131
- :param components: List of undeclared components
132
- :return: Dictionary with formatted Markdown details and summary
133
- """
152
+ :param components: List of undeclared components
153
+ :return: Dictionary with formatted Markdown details and summary
154
+ """
134
155
  headers = ['Component', 'Version', 'License']
135
- rows: [[]]= []
156
+ rows: [[]] = []
136
157
  # TODO look at using SpdxLite license name lookup method
137
158
  for component in components:
138
- licenses = " - ".join(lic.get('spdxid', 'Unknown') for lic in component['licenses'])
159
+ licenses = ' - '.join(lic.get('spdxid', 'Unknown') for lic in component['licenses'])
139
160
  rows.append([component['purl'], component['version'], licenses])
140
- return {
141
- 'details': f'### Undeclared components\n{self.generate_table(headers,rows)}\n',
161
+ return {
162
+ 'details': f'### Undeclared components\n{self.generate_table(headers, rows)}\n',
142
163
  'summary': self._get_summary(components),
143
164
  }
144
165
 
145
- def _jira_markdown(self, components: list) -> Dict[str,Any]:
166
+ def _jira_markdown(self, components: list) -> Dict[str, Any]:
146
167
  """
147
- Format the undeclared components as Markdown.
168
+ Format the undeclared components as Markdown.
148
169
 
149
- :param components: List of undeclared components
150
- :return: Dictionary with formatted Markdown details and summary
151
- """
170
+ :param components: List of undeclared components
171
+ :return: Dictionary with formatted Markdown details and summary
172
+ """
152
173
  headers = ['Component', 'Version', 'License']
153
- rows: [[]]= []
174
+ rows: [[]] = []
154
175
  # TODO look at using SpdxLite license name lookup method
155
176
  for component in components:
156
- licenses = " - ".join(lic.get('spdxid', 'Unknown') for lic in component['licenses'])
177
+ licenses = ' - '.join(lic.get('spdxid', 'Unknown') for lic in component['licenses'])
157
178
  rows.append([component['purl'], component['version'], licenses])
158
- return {
159
- 'details': f'{self.generate_jira_table(headers,rows)}',
179
+ return {
180
+ 'details': f'{self.generate_jira_table(headers, rows)}',
160
181
  'summary': self._get_jira_summary(components),
161
182
  }
162
183
 
163
184
  def _get_unique_components(self, components: list) -> list:
164
185
  """
165
- Generate a list of unique components.
186
+ Generate a list of unique components.
166
187
 
167
- :param components: List of undeclared components
168
- :return: list of unique components
169
- """
188
+ :param components: List of undeclared components
189
+ :return: list of unique components
190
+ """
170
191
  unique_components = {}
171
192
  if components is None:
172
193
  self.print_stderr(f'WARNING: No components provided!')
173
194
  return []
174
195
 
175
196
  for component in components:
176
- unique_components[component['purl']] = {'purl': component['purl']}
197
+ unique_components[component['purl']] = {'purl': component['purl']}
177
198
  return list(unique_components.values())
178
199
 
179
200
  def _generate_scanoss_file(self, components: list) -> dict:
180
201
  """
181
- Generate a list of PURLs for the scanoss.json file.
202
+ Generate a list of PURLs for the scanoss.json file.
182
203
 
183
- :param components: List of undeclared components
184
- :return: scanoss.json Dictionary
185
- """
204
+ :param components: List of undeclared components
205
+ :return: scanoss.json Dictionary
206
+ """
186
207
  scanoss_settings = {
187
- 'bom':{
208
+ 'bom': {
188
209
  'include': self._get_unique_components(components),
189
210
  }
190
211
  }
@@ -193,11 +214,11 @@ class UndeclaredComponent(PolicyCheck):
193
214
 
194
215
  def _generate_sbom_file(self, components: list) -> dict:
195
216
  """
196
- Generate a list of PURLs for the SBOM file.
217
+ Generate a list of PURLs for the SBOM file.
197
218
 
198
- :param components: List of undeclared components
199
- :return: SBOM Dictionary with components
200
- """
219
+ :param components: List of undeclared components
220
+ :return: SBOM Dictionary with components
221
+ """
201
222
  sbom = {
202
223
  'components': self._get_unique_components(components),
203
224
  }
@@ -236,6 +257,8 @@ class UndeclaredComponent(PolicyCheck):
236
257
  if len(undeclared_components) <= 0:
237
258
  return PolicyStatus.FAIL.value, results
238
259
  return PolicyStatus.SUCCESS.value, results
260
+
261
+
239
262
  #
240
263
  # End of UndeclaredComponent Class
241
264
  #
@@ -1,61 +1,82 @@
1
1
  """
2
- SPDX-License-Identifier: MIT
3
-
4
- Copyright (c) 2024, SCANOSS
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in
14
- all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- THE SOFTWARE.
2
+ SPDX-License-Identifier: MIT
3
+
4
+ Copyright (c) 2024, SCANOSS
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
23
23
  """
24
+
24
25
  from ...scanossbase import ScanossBase
25
26
 
26
27
  DEFAULT_COPYLEFT_LICENSES = {
27
- 'agpl-3.0-only', 'artistic-1.0', 'artistic-2.0', 'cc-by-sa-4.0', 'cddl-1.0', 'cddl-1.1', 'cecill-2.1',
28
- 'epl-1.0', 'epl-2.0', 'gfdl-1.1-only', 'gfdl-1.2-only', 'gfdl-1.3-only', 'gpl-1.0-only', 'gpl-2.0-only',
29
- 'gpl-3.0-only', 'lgpl-2.1-only', 'lgpl-3.0-only', 'mpl-1.1', 'mpl-2.0', 'sleepycat', 'watcom-1.0'
28
+ 'agpl-3.0-only',
29
+ 'artistic-1.0',
30
+ 'artistic-2.0',
31
+ 'cc-by-sa-4.0',
32
+ 'cddl-1.0',
33
+ 'cddl-1.1',
34
+ 'cecill-2.1',
35
+ 'epl-1.0',
36
+ 'epl-2.0',
37
+ 'gfdl-1.1-only',
38
+ 'gfdl-1.2-only',
39
+ 'gfdl-1.3-only',
40
+ 'gpl-1.0-only',
41
+ 'gpl-2.0-only',
42
+ 'gpl-3.0-only',
43
+ 'lgpl-2.1-only',
44
+ 'lgpl-3.0-only',
45
+ 'mpl-1.1',
46
+ 'mpl-2.0',
47
+ 'sleepycat',
48
+ 'watcom-1.0',
30
49
  }
31
50
 
51
+
32
52
  class LicenseUtil(ScanossBase):
33
53
  """
34
- A utility class for handling software licenses, particularly copyleft licenses.
54
+ A utility class for handling software licenses, particularly copyleft licenses.
35
55
 
36
- This class provides functionality to initialize, manage, and query a set of
37
- copyleft licenses. It also offers a method to generate URLs for license information.
56
+ This class provides functionality to initialize, manage, and query a set of
57
+ copyleft licenses. It also offers a method to generate URLs for license information.
38
58
  """
59
+
39
60
  BASE_SPDX_ORG_URL = 'https://spdx.org/licenses'
40
61
  BASE_OSADL_URL = 'https://www.osadl.org/fileadmin/checklists/unreflicenses'
41
62
 
42
- def __init__(self,debug: bool = False, trace: bool = True, quiet: bool = False):
63
+ def __init__(self, debug: bool = False, trace: bool = True, quiet: bool = False):
43
64
  super().__init__(debug, trace, quiet)
44
65
  self.default_copyleft_licenses = set(DEFAULT_COPYLEFT_LICENSES)
45
66
  self.copyleft_licenses = set()
46
67
 
47
68
  def init(self, include: str = None, exclude: str = None, explicit: str = None):
48
69
  """
49
- Initialize the set of copyleft licenses based on user input.
70
+ Initialize the set of copyleft licenses based on user input.
50
71
 
51
- This method allows for customization of the copyleft license set by:
52
- - Setting an explicit list of licenses
53
- - Including additional licenses to the default set
54
- - Excluding specific licenses from the default set
72
+ This method allows for customization of the copyleft license set by:
73
+ - Setting an explicit list of licenses
74
+ - Including additional licenses to the default set
75
+ - Excluding specific licenses from the default set
55
76
 
56
- :param include: Comma-separated string of licenses to include
57
- :param exclude: Comma-separated string of licenses to exclude
58
- :param explicit: Comma-separated string of licenses to use exclusively
77
+ :param include: Comma-separated string of licenses to include
78
+ :param exclude: Comma-separated string of licenses to exclude
79
+ :param explicit: Comma-separated string of licenses to use exclusively
59
80
  """
60
81
  if self.debug:
61
82
  self.print_stderr(f'Include Copyleft licenses: ${include}')
@@ -73,7 +94,7 @@ class LicenseUtil(ScanossBase):
73
94
  if include:
74
95
  include = include.strip()
75
96
  if include:
76
- inc =[item.strip().lower() for item in include.split(',')]
97
+ inc = [item.strip().lower() for item in include.split(',')]
77
98
  self.copyleft_licenses.update(inc)
78
99
  if exclude:
79
100
  exclude = exclude.strip()
@@ -85,23 +106,22 @@ class LicenseUtil(ScanossBase):
85
106
 
86
107
  def is_copyleft(self, spdxid: str) -> bool:
87
108
  """
88
- Check if a given license is considered copyleft.
109
+ Check if a given license is considered copyleft.
89
110
 
90
- :param spdxid: The SPDX identifier of the license to check
91
- :return: True if the license is copyleft, False otherwise
111
+ :param spdxid: The SPDX identifier of the license to check
112
+ :return: True if the license is copyleft, False otherwise
92
113
  """
93
114
  return spdxid.lower() in self.copyleft_licenses
94
115
 
95
116
  def get_spdx_url(self, spdxid: str) -> str:
96
117
  """
97
- Generate the URL for the SPDX page of a license.
118
+ Generate the URL for the SPDX page of a license.
98
119
 
99
- :param spdxid: The SPDX identifier of the license
100
- :return: The URL of the SPDX page for the given license
120
+ :param spdxid: The SPDX identifier of the license
121
+ :return: The URL of the SPDX page for the given license
101
122
  """
102
123
  return f'{self.BASE_SPDX_ORG_URL}/{spdxid}.html'
103
124
 
104
-
105
125
  def get_osadl_url(self, spdxid: str) -> str:
106
126
  """
107
127
  Generate the URL for the OSADL (Open Source Automation Development Lab) page of a license.
@@ -110,6 +130,8 @@ class LicenseUtil(ScanossBase):
110
130
  :return: The URL of the OSADL page for the given license
111
131
  """
112
132
  return f'{self.BASE_OSADL_URL}/{spdxid}.txt'
133
+
134
+
113
135
  #
114
136
  # End of LicenseUtil Class
115
137
  #
scanoss/results.py CHANGED
@@ -1,25 +1,25 @@
1
1
  """
2
- SPDX-License-Identifier: MIT
3
-
4
- Copyright (c) 2024, SCANOSS
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in
14
- all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- THE SOFTWARE.
2
+ SPDX-License-Identifier: MIT
3
+
4
+ Copyright (c) 2024, SCANOSS
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
23
23
  """
24
24
 
25
25
  import json
@@ -27,27 +27,27 @@ from typing import Any, Dict, List
27
27
 
28
28
  from .scanossbase import ScanossBase
29
29
 
30
- MATCH_TYPES = ["file", "snippet"]
31
- STATUSES = ["pending", "identified"]
30
+ MATCH_TYPES = ['file', 'snippet']
31
+ STATUSES = ['pending', 'identified']
32
32
 
33
33
 
34
34
  AVAILABLE_FILTER_VALUES = {
35
- "match_type": [e for e in MATCH_TYPES],
36
- "status": [e for e in STATUSES],
35
+ 'match_type': [e for e in MATCH_TYPES],
36
+ 'status': [e for e in STATUSES],
37
37
  }
38
38
 
39
39
 
40
40
  ARG_TO_FILTER_MAP = {
41
- "match_type": "id",
42
- "status": "status",
41
+ 'match_type': 'id',
42
+ 'status': 'status',
43
43
  }
44
44
 
45
45
  PENDING_IDENTIFICATION_FILTERS = {
46
- "match_type": ["file", "snippet"],
47
- "status": ["pending"],
46
+ 'match_type': ['file', 'snippet'],
47
+ 'status': ['pending'],
48
48
  }
49
49
 
50
- AVAILABLE_OUTPUT_FORMATS = ["json", "plain"]
50
+ AVAILABLE_OUTPUT_FORMATS = ['json', 'plain']
51
51
 
52
52
 
53
53
  class Results(ScanossBase):
@@ -95,11 +95,11 @@ class Results(ScanossBase):
95
95
  Returns:
96
96
  Dict[str, Any]: The parsed JSON data
97
97
  """
98
- with open(file, "r") as jsonfile:
98
+ with open(file, 'r') as jsonfile:
99
99
  try:
100
100
  return json.load(jsonfile)
101
101
  except Exception as e:
102
- self.print_stderr(f"ERROR: Problem parsing input JSON: {e}")
102
+ self.print_stderr(f'ERROR: Problem parsing input JSON: {e}')
103
103
 
104
104
  def _load_and_transform(self, file: str) -> List[Dict[str, Any]]:
105
105
  """
@@ -143,7 +143,7 @@ class Results(ScanossBase):
143
143
 
144
144
  @staticmethod
145
145
  def _extract_comma_separated_values(values: str):
146
- return [value.strip() for value in values.split(",")]
146
+ return [value.strip() for value in values.split(',')]
147
147
 
148
148
  def apply_filters(self):
149
149
  """Apply the filters to the data"""
@@ -172,14 +172,11 @@ class Results(ScanossBase):
172
172
 
173
173
  @staticmethod
174
174
  def _validate_filter_values(filter_key: str, filter_value: List[str]):
175
- if any(
176
- value not in AVAILABLE_FILTER_VALUES.get(filter_key, [])
177
- for value in filter_value
178
- ):
179
- valid_values = ", ".join(AVAILABLE_FILTER_VALUES.get(filter_key, []))
175
+ if any(value not in AVAILABLE_FILTER_VALUES.get(filter_key, []) for value in filter_value):
176
+ valid_values = ', '.join(AVAILABLE_FILTER_VALUES.get(filter_key, []))
180
177
  raise Exception(
181
178
  f"ERROR: Invalid filter value '{filter_value}' for filter '{filter_key.value}'. "
182
- f"Valid values are: {valid_values}"
179
+ f'Valid values are: {valid_values}'
183
180
  )
184
181
 
185
182
  def get_pending_identifications(self):
@@ -226,9 +223,7 @@ class Results(ScanossBase):
226
223
  Args:
227
224
  file (str, optional): Output file. Defaults to None.
228
225
  """
229
- self.print_to_file_or_stdout(
230
- json.dumps(self._format_json_output(), indent=2), file
231
- )
226
+ self.print_to_file_or_stdout(json.dumps(self._format_json_output(), indent=2), file)
232
227
 
233
228
  def _format_json_output(self):
234
229
  """
@@ -240,15 +235,11 @@ class Results(ScanossBase):
240
235
  formatted_data.append(
241
236
  {
242
237
  'file': item.get('filename'),
243
- 'status': item.get('status', "N/A"),
238
+ 'status': item.get('status', 'N/A'),
244
239
  'match_type': item['id'],
245
- 'matched': item.get('matched', "N/A"),
246
- 'purl': (item.get('purl')[0] if item.get('purl') else "N/A"),
247
- 'license': (
248
- item.get('licenses')[0].get('name', "N/A")
249
- if item.get('licenses')
250
- else "N/A"
251
- ),
240
+ 'matched': item.get('matched', 'N/A'),
241
+ 'purl': (item.get('purl')[0] if item.get('purl') else 'N/A'),
242
+ 'license': (item.get('licenses')[0].get('name', 'N/A') if item.get('licenses') else 'N/A'),
252
243
  }
253
244
  )
254
245
  return {'results': formatted_data, 'total': len(formatted_data)}
@@ -263,7 +254,7 @@ class Results(ScanossBase):
263
254
  None
264
255
  """
265
256
  if not self.data:
266
- return self.print_stderr("No results to present")
257
+ return self.print_stderr('No results to present')
267
258
  self.print_to_file_or_stdout(self._format_plain_output(), file)
268
259
 
269
260
  def _present_stdout(self):
@@ -273,7 +264,7 @@ class Results(ScanossBase):
273
264
  None
274
265
  """
275
266
  if not self.data:
276
- return self.print_stderr("No results to present")
267
+ return self.print_stderr('No results to present')
277
268
  self.print_to_file_or_stdout(self._format_plain_output())
278
269
 
279
270
  def _format_plain_output(self):
@@ -281,9 +272,9 @@ class Results(ScanossBase):
281
272
  Format the output data into a plain text string
282
273
  """
283
274
 
284
- formatted = ""
275
+ formatted = ''
285
276
  for item in self.data:
286
- formatted += f"{self._format_plain_output_item(item)} \n"
277
+ formatted += f'{self._format_plain_output_item(item)} \n'
287
278
  return formatted
288
279
 
289
280
  @staticmethod
@@ -292,10 +283,10 @@ class Results(ScanossBase):
292
283
  licenses = item.get('licenses', [])
293
284
 
294
285
  return (
295
- f"File: {item.get('filename')}\n"
296
- f"Match type: {item.get('id')}\n"
297
- f"Status: {item.get('status', 'N/A')}\n"
298
- f"Matched: {item.get('matched', 'N/A')}\n"
299
- f"Purl: {purls[0] if purls else 'N/A'}\n"
300
- f"License: {licenses[0].get('name', 'N/A') if licenses else 'N/A'}\n"
286
+ f'File: {item.get("filename")}\n'
287
+ f'Match type: {item.get("id")}\n'
288
+ f'Status: {item.get("status", "N/A")}\n'
289
+ f'Matched: {item.get("matched", "N/A")}\n'
290
+ f'Purl: {purls[0] if purls else "N/A"}\n'
291
+ f'License: {licenses[0].get("name", "N/A") if licenses else "N/A"}\n'
301
292
  )