scanoss 1.12.2__py3-none-any.whl → 1.43.1__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 (109) 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 +18 -12
  4. protoc_gen_swagger/options/annotations_pb2.pyi +48 -0
  5. protoc_gen_swagger/options/annotations_pb2_grpc.py +20 -0
  6. protoc_gen_swagger/options/openapiv2_pb2.py +110 -99
  7. protoc_gen_swagger/options/openapiv2_pb2.pyi +1317 -0
  8. protoc_gen_swagger/options/openapiv2_pb2_grpc.py +20 -0
  9. scanoss/__init__.py +18 -18
  10. scanoss/api/__init__.py +17 -17
  11. scanoss/api/common/__init__.py +17 -17
  12. scanoss/api/common/v2/__init__.py +17 -17
  13. scanoss/api/common/v2/scanoss_common_pb2.py +49 -20
  14. scanoss/api/common/v2/scanoss_common_pb2_grpc.py +25 -0
  15. scanoss/api/components/__init__.py +17 -17
  16. scanoss/api/components/v2/__init__.py +17 -17
  17. scanoss/api/components/v2/scanoss_components_pb2.py +68 -43
  18. scanoss/api/components/v2/scanoss_components_pb2_grpc.py +83 -22
  19. scanoss/api/cryptography/v2/scanoss_cryptography_pb2.py +136 -21
  20. scanoss/api/cryptography/v2/scanoss_cryptography_pb2_grpc.py +766 -13
  21. scanoss/api/dependencies/__init__.py +17 -17
  22. scanoss/api/dependencies/v2/__init__.py +17 -17
  23. scanoss/api/dependencies/v2/scanoss_dependencies_pb2.py +56 -29
  24. scanoss/api/dependencies/v2/scanoss_dependencies_pb2_grpc.py +94 -8
  25. scanoss/api/geoprovenance/__init__.py +23 -0
  26. scanoss/api/geoprovenance/v2/__init__.py +23 -0
  27. scanoss/api/geoprovenance/v2/scanoss_geoprovenance_pb2.py +92 -0
  28. scanoss/api/geoprovenance/v2/scanoss_geoprovenance_pb2_grpc.py +381 -0
  29. scanoss/api/licenses/__init__.py +23 -0
  30. scanoss/api/licenses/v2/__init__.py +23 -0
  31. scanoss/api/licenses/v2/scanoss_licenses_pb2.py +84 -0
  32. scanoss/api/licenses/v2/scanoss_licenses_pb2_grpc.py +302 -0
  33. scanoss/api/scanning/__init__.py +17 -17
  34. scanoss/api/scanning/v2/__init__.py +17 -17
  35. scanoss/api/scanning/v2/scanoss_scanning_pb2.py +42 -13
  36. scanoss/api/scanning/v2/scanoss_scanning_pb2_grpc.py +86 -7
  37. scanoss/api/semgrep/__init__.py +17 -17
  38. scanoss/api/semgrep/v2/__init__.py +17 -17
  39. scanoss/api/semgrep/v2/scanoss_semgrep_pb2.py +50 -23
  40. scanoss/api/semgrep/v2/scanoss_semgrep_pb2_grpc.py +151 -16
  41. scanoss/api/vulnerabilities/__init__.py +17 -17
  42. scanoss/api/vulnerabilities/v2/__init__.py +17 -17
  43. scanoss/api/vulnerabilities/v2/scanoss_vulnerabilities_pb2.py +78 -31
  44. scanoss/api/vulnerabilities/v2/scanoss_vulnerabilities_pb2_grpc.py +282 -18
  45. scanoss/cli.py +2359 -370
  46. scanoss/components.py +187 -94
  47. scanoss/constants.py +22 -0
  48. scanoss/cryptography.py +308 -0
  49. scanoss/csvoutput.py +91 -58
  50. scanoss/cyclonedx.py +221 -63
  51. scanoss/data/build_date.txt +1 -1
  52. scanoss/data/osadl-copyleft.json +133 -0
  53. scanoss/data/scanoss-settings-schema.json +254 -0
  54. scanoss/delta.py +197 -0
  55. scanoss/export/__init__.py +23 -0
  56. scanoss/export/dependency_track.py +227 -0
  57. scanoss/file_filters.py +582 -0
  58. scanoss/filecount.py +75 -69
  59. scanoss/gitlabqualityreport.py +214 -0
  60. scanoss/header_filter.py +563 -0
  61. scanoss/inspection/__init__.py +23 -0
  62. scanoss/inspection/policy_check/__init__.py +0 -0
  63. scanoss/inspection/policy_check/dependency_track/__init__.py +0 -0
  64. scanoss/inspection/policy_check/dependency_track/project_violation.py +479 -0
  65. scanoss/inspection/policy_check/policy_check.py +222 -0
  66. scanoss/inspection/policy_check/scanoss/__init__.py +0 -0
  67. scanoss/inspection/policy_check/scanoss/copyleft.py +243 -0
  68. scanoss/inspection/policy_check/scanoss/undeclared_component.py +309 -0
  69. scanoss/inspection/summary/__init__.py +0 -0
  70. scanoss/inspection/summary/component_summary.py +170 -0
  71. scanoss/inspection/summary/license_summary.py +191 -0
  72. scanoss/inspection/summary/match_summary.py +341 -0
  73. scanoss/inspection/utils/file_utils.py +44 -0
  74. scanoss/inspection/utils/license_utils.py +123 -0
  75. scanoss/inspection/utils/markdown_utils.py +63 -0
  76. scanoss/inspection/utils/scan_result_processor.py +417 -0
  77. scanoss/osadl.py +125 -0
  78. scanoss/results.py +275 -0
  79. scanoss/scancodedeps.py +87 -38
  80. scanoss/scanner.py +431 -539
  81. scanoss/scanners/__init__.py +23 -0
  82. scanoss/scanners/container_scanner.py +476 -0
  83. scanoss/scanners/folder_hasher.py +358 -0
  84. scanoss/scanners/scanner_config.py +73 -0
  85. scanoss/scanners/scanner_hfh.py +252 -0
  86. scanoss/scanoss_settings.py +337 -0
  87. scanoss/scanossapi.py +140 -101
  88. scanoss/scanossbase.py +59 -22
  89. scanoss/scanossgrpc.py +799 -251
  90. scanoss/scanpostprocessor.py +294 -0
  91. scanoss/scantype.py +22 -21
  92. scanoss/services/dependency_track_service.py +132 -0
  93. scanoss/spdxlite.py +532 -174
  94. scanoss/threadeddependencies.py +148 -47
  95. scanoss/threadedscanning.py +53 -37
  96. scanoss/utils/__init__.py +23 -0
  97. scanoss/utils/abstract_presenter.py +103 -0
  98. scanoss/utils/crc64.py +96 -0
  99. scanoss/utils/file.py +84 -0
  100. scanoss/utils/scanoss_scan_results_utils.py +41 -0
  101. scanoss/utils/simhash.py +198 -0
  102. scanoss/winnowing.py +241 -63
  103. {scanoss-1.12.2.dist-info → scanoss-1.43.1.dist-info}/METADATA +18 -9
  104. scanoss-1.43.1.dist-info/RECORD +110 -0
  105. {scanoss-1.12.2.dist-info → scanoss-1.43.1.dist-info}/WHEEL +1 -1
  106. scanoss-1.12.2.dist-info/RECORD +0 -58
  107. {scanoss-1.12.2.dist-info → scanoss-1.43.1.dist-info}/entry_points.txt +0 -0
  108. {scanoss-1.12.2.dist-info → scanoss-1.43.1.dist-info/licenses}/LICENSE +0 -0
  109. {scanoss-1.12.2.dist-info → scanoss-1.43.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,341 @@
1
+ """
2
+ SPDX-License-Identifier: MIT
3
+
4
+ Copyright (c) 2025, 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
+ """
24
+
25
+ from dataclasses import dataclass
26
+
27
+ from ...scanossbase import ScanossBase
28
+ from ...utils import scanoss_scan_results_utils
29
+ from ..utils.file_utils import load_json_file
30
+ from ..utils.markdown_utils import generate_table
31
+
32
+
33
+ @dataclass
34
+ class MatchSummaryItem:
35
+ """
36
+ Represents a single match entry in the SCANOSS results.
37
+
38
+ This data class encapsulates all the relevant information about a component
39
+ match found during scanning, including file location, license details, and
40
+ match quality metrics.
41
+ """
42
+ file: str
43
+ file_url: str
44
+ license: str
45
+ similarity: str
46
+ purl: str
47
+ purl_url: str
48
+ version: str
49
+ lines: str
50
+
51
+
52
+ @dataclass
53
+ class ComponentMatchSummary:
54
+ """
55
+ Container for categorized SCANOSS match results.
56
+
57
+ Organizes matches into two categories: full file matches and snippet matches.
58
+ This separation allows for different presentation and analysis of match types.
59
+ """
60
+ files: list[MatchSummaryItem]
61
+ snippet: list[MatchSummaryItem]
62
+
63
+ class MatchSummary(ScanossBase):
64
+ """
65
+ Generates Markdown summaries from SCANOSS scan results.
66
+
67
+ This class processes SCANOSS scan results and creates human-readable Markdown
68
+ reports with collapsible sections for file and snippet matches. The reports
69
+ include clickable links to files when a line range
70
+ prefix is provided.
71
+ """
72
+
73
+ def __init__( # noqa: PLR0913
74
+ self,
75
+ debug: bool = False,
76
+ trace: bool = False,
77
+ quiet: bool = False,
78
+ line_range_prefix: str = None,
79
+ scanoss_results_path: str = None,
80
+ output: str = None,
81
+ ):
82
+ """
83
+ Initialize the Matches Summary generator.
84
+
85
+ :param debug: Enable debug output for troubleshooting
86
+ :param trace: Enable trace-level logging for detailed execution tracking
87
+ :param quiet: Suppress informational messages
88
+ :param line_range_prefix: Base URL prefix for GitLab file links with line ranges
89
+ (e.g., 'https://gitlab.com/org/project/-/blob/main')
90
+ :param scanoss_results_path: Path to SCANOSS scan results file in JSON format
91
+ :param output: Output file path for the generated Markdown report (default: stdout)
92
+ """
93
+ super().__init__(debug=debug, trace=trace, quiet=quiet)
94
+ self.scanoss_results_path = scanoss_results_path
95
+ self.line_range_prefix = line_range_prefix
96
+ self.output = output
97
+ self.print_debug("Initializing MatchSummary class")
98
+
99
+
100
+ def _get_match_summary_item(self, file_name: str, result: dict) -> MatchSummaryItem:
101
+ """
102
+ Create a MatchSummaryItem from a single scan result.
103
+
104
+ Processes a SCANOSS scan result and creates a MatchSummaryItem with appropriate
105
+ file URLs, license information, and line ranges. Handles both snippet matches
106
+ (with specific line ranges) and file matches (entire file).
107
+
108
+ :param file_name: Name of the scanned file (relative path in the repository)
109
+ :param result: SCANOSS scan result dictionary containing match details
110
+ :return: Populated match summary item with all relevant information
111
+ """
112
+ self.print_trace(f"Creating match summary item for file: {file_name}, id: {result.get('id')}")
113
+
114
+ if result.get('id') == "snippet":
115
+ # Snippet match: create URL with line range anchor
116
+ lines = scanoss_scan_results_utils.get_lines(result.get('lines'))
117
+ end_line = lines[len(lines) - 1] if len(lines) > 1 else lines[0]
118
+ file_url = f"{self.line_range_prefix}/{file_name}#L{lines[0]}-L{end_line}"
119
+
120
+ self.print_trace(f"Snippet match: lines {lines[0]}-{end_line}, purl: {result.get('purl')[0]}")
121
+
122
+ return MatchSummaryItem(
123
+ file_url=file_url,
124
+ file=file_name,
125
+ license=result.get('licenses')[0].get('name'),
126
+ similarity=result.get('matched'),
127
+ purl=result.get('purl')[0],
128
+ purl_url=result.get('url'),
129
+ version=result.get('version'),
130
+ lines=f"{lines[0]}-{lines[len(lines) - 1] if len(lines) > 1 else lines[0]}"
131
+ )
132
+ # File match: create URL without line range
133
+ self.print_trace(f"File match: {file_name}, purl: {result.get('purl')[0]}, version: {result.get('version')}")
134
+
135
+ return MatchSummaryItem(
136
+ file=file_name,
137
+ file_url=f"{self.line_range_prefix}/{file_name}",
138
+ license=result.get('licenses')[0].get('name'),
139
+ similarity=result.get('matched'),
140
+ purl=result.get('purl')[0],
141
+ purl_url=result.get('url'),
142
+ version=result.get('version'),
143
+ lines="all"
144
+ )
145
+
146
+ def _validate_result(self, file_name: str, result: dict) -> bool:
147
+ """
148
+ Validate that a scan result has all required fields.
149
+
150
+ :param file_name: Name of the file being validated
151
+ :param result: The scan result to validate
152
+ :return: True if valid, False otherwise
153
+ """
154
+ validations = [
155
+ ('id', 'No id found'),
156
+ ('lines', 'No lines found'),
157
+ ('purl', 'No purl found'),
158
+ ('licenses', 'No licenses found'),
159
+ ('version', 'No version found'),
160
+ ('matched', 'No matched found'),
161
+ ('url', 'No url found'),
162
+ ]
163
+
164
+ for field, error_msg in validations:
165
+ if not result.get(field):
166
+ self.print_debug(f'ERROR: {error_msg} for file {file_name}')
167
+ return False
168
+
169
+ # Additional validation for non-empty lists
170
+ if len(result.get('purl')) == 0:
171
+ self.print_debug(f'ERROR: No purl found for file {file_name}')
172
+ return False
173
+ if len(result.get('licenses')) == 0:
174
+ self.print_debug(f'ERROR: Empty licenses list for file {file_name}')
175
+ return False
176
+
177
+ return True
178
+
179
+ def _get_matches_summary(self) -> ComponentMatchSummary:
180
+ """
181
+ Parse SCANOSS scan results and create categorized match summaries.
182
+
183
+ Loads the SCANOSS scan results file and processes each match, validating
184
+ required fields and categorizing matches into file matches and snippet matches.
185
+ Skips invalid or incomplete results with debug messages.
186
+ """
187
+ self.print_debug(f"Loading scan results from: {self.scanoss_results_path}")
188
+
189
+ # Load scan results from JSON file
190
+ scan_results = load_json_file(self.scanoss_results_path)
191
+ gitlab_matches_summary = ComponentMatchSummary(files=[], snippet=[])
192
+
193
+ self.print_debug(f"Processing {len(scan_results)} files from scan results")
194
+ self.print_trace(f"Line range prefix set to: {self.line_range_prefix}")
195
+
196
+ # Process each file and its results
197
+ for file_name, results in scan_results.items():
198
+ self.print_trace(f"Processing file: {file_name} with {len(results)} results")
199
+
200
+ for result in results:
201
+ # Skip non-matches
202
+ if result.get('id') == "none":
203
+ self.print_debug(f'Skipping non-match for file {file_name}')
204
+ continue
205
+
206
+ # Validate required fields
207
+ if not self._validate_result(file_name, result):
208
+ continue
209
+
210
+ # Create summary item and categorize by match type
211
+ summary_item = self._get_match_summary_item(file_name, result)
212
+ if result.get('id') == "snippet":
213
+ gitlab_matches_summary.snippet.append(summary_item)
214
+ self.print_trace(f"Added snippet match for {file_name}")
215
+ else:
216
+ gitlab_matches_summary.files.append(summary_item)
217
+ self.print_trace(f"Added file match for {file_name}")
218
+
219
+ self.print_debug(
220
+ f"Match summary complete: {len(gitlab_matches_summary.files)} file matches, "
221
+ f"{len(gitlab_matches_summary.snippet)} snippet matches"
222
+ )
223
+
224
+ return gitlab_matches_summary
225
+
226
+
227
+ def _markdown(self, gitlab_matches_summary: ComponentMatchSummary) -> str:
228
+ """
229
+ Generate Markdown from match summaries.
230
+
231
+ Creates a formatted Markdown document with collapsible sections for file
232
+ and snippet matches.
233
+
234
+ :param gitlab_matches_summary: Container with categorized file and snippet matches to format
235
+ :return: Complete Markdown document with formatted match tables
236
+ """
237
+ self.print_debug("Generating Markdown from match summaries")
238
+
239
+ if len(gitlab_matches_summary.files) == 0 and len(gitlab_matches_summary.snippet) == 0:
240
+ self.print_debug("No matches to format - returning empty string")
241
+ return ""
242
+
243
+ self.print_trace(
244
+ f"Formatting {len(gitlab_matches_summary.files)} file matches and "
245
+ f"{len(gitlab_matches_summary.snippet)} snippet matches"
246
+ )
247
+
248
+ # Define table headers
249
+ file_match_headers = ['File', 'License', 'Similarity', 'PURL', 'Version']
250
+ snippet_match_headers = ['File', 'License', 'Similarity', 'PURL', 'Version', 'Lines']
251
+
252
+ # Build file matches table
253
+ self.print_trace("Building file matches table")
254
+ file_match_rows = []
255
+ for file_match in gitlab_matches_summary.files:
256
+ row = [
257
+ f"[{file_match.file}]({file_match.file_url})",
258
+ file_match.license,
259
+ file_match.similarity,
260
+ f"[{file_match.purl}]({file_match.purl_url})",
261
+ file_match.version,
262
+ ]
263
+ file_match_rows.append(row)
264
+ file_match_table = generate_table(file_match_headers, file_match_rows)
265
+
266
+ # Build snippet matches table
267
+ self.print_trace("Building snippet matches table")
268
+ snippet_match_rows = []
269
+ for snippet_match in gitlab_matches_summary.snippet:
270
+ row = [
271
+ f"[{snippet_match.file}]({snippet_match.file_url})",
272
+ snippet_match.license,
273
+ snippet_match.similarity,
274
+ f"[{snippet_match.purl}]({snippet_match.purl_url})",
275
+ snippet_match.version,
276
+ snippet_match.lines
277
+ ]
278
+ snippet_match_rows.append(row)
279
+ snippet_match_table = generate_table(snippet_match_headers, snippet_match_rows)
280
+
281
+ # Assemble complete Markdown document
282
+ markdown = ""
283
+ markdown += "### SCANOSS Match Summary\n\n"
284
+
285
+ # File matches section (collapsible)
286
+ markdown += "<details>\n"
287
+ markdown += "<summary>File Match Summary</summary>\n\n"
288
+ markdown += file_match_table
289
+ markdown += "\n</details>\n"
290
+
291
+ # Snippet matches section (collapsible)
292
+ markdown += "<details>\n"
293
+ markdown += "<summary>Snippet Match Summary</summary>\n\n"
294
+ markdown += snippet_match_table
295
+ markdown += "\n</details>\n"
296
+
297
+ self.print_trace(f"Markdown generation complete (length: {len(markdown)} characters)")
298
+ self.print_debug("Match summary Markdown generation complete")
299
+ return markdown
300
+
301
+ def run(self):
302
+ """
303
+ Execute the matches summary generation process.
304
+
305
+ This is the main entry point for generating the matches summary report.
306
+ It orchestrates the entire workflow:
307
+ 1. Loads and parses SCANOSS scan results
308
+ 2. Validates and categorizes matches
309
+ 3. Generates Markdown report
310
+ 4. Outputs to file or stdout
311
+ """
312
+ self.print_debug("Starting match summary generation process")
313
+ self.print_trace(
314
+ f"Configuration - Results path: {self.scanoss_results_path}, Output: {self.output}, "
315
+ f"Line range prefix: {self.line_range_prefix}"
316
+ )
317
+
318
+ # Load and process scan results into categorized matches
319
+ self.print_trace("Loading and processing scan results")
320
+ matches = self._get_matches_summary()
321
+
322
+ # Format matches as GitLab-compatible Markdown
323
+ self.print_trace("Generating Markdown output")
324
+ matches_md = self._markdown(matches)
325
+ if matches_md == "":
326
+ self.print_debug("No matches found - exiting")
327
+ self.print_stdout("No matches found.")
328
+ return
329
+
330
+ # Output to file or stdout
331
+ self.print_trace("Writing output")
332
+ if self.output:
333
+ self.print_debug(f"Writing match summary to file: {self.output}")
334
+ else:
335
+ self.print_debug("Writing match summary to 'stdout'")
336
+
337
+ self.print_to_file_or_stdout(matches_md, self.output)
338
+ self.print_debug("Match summary generation complete")
339
+
340
+
341
+
@@ -0,0 +1,44 @@
1
+ """
2
+ SPDX-License-Identifier: MIT
3
+
4
+ Copyright (c) 2025, 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
+ """
24
+
25
+ import json
26
+ import os
27
+
28
+
29
+ def load_json_file(file_path: str) -> dict:
30
+ """
31
+ Load the file
32
+
33
+ :param file_path: file path to the JSON file
34
+
35
+ Returns:
36
+ Dict[str, Any]: The parsed JSON data
37
+ """
38
+ if not os.path.exists(file_path):
39
+ raise ValueError(f'The file "{file_path}" does not exist.')
40
+ with open(file_path, 'r') as jsonfile:
41
+ try:
42
+ return json.load(jsonfile)
43
+ except Exception as e:
44
+ raise ValueError(f'ERROR: Problem parsing input JSON: {e}')
@@ -0,0 +1,123 @@
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.
23
+ """
24
+
25
+ from scanoss.osadl import Osadl
26
+
27
+ from ...scanossbase import ScanossBase
28
+
29
+
30
+ class LicenseUtil(ScanossBase):
31
+ """
32
+ A utility class for handling software licenses, particularly copyleft licenses.
33
+
34
+ Uses OSADL (Open Source Automation Development Lab) authoritative copyleft data
35
+ with optional include/exclude/explicit filters.
36
+ """
37
+
38
+ BASE_SPDX_ORG_URL = 'https://spdx.org/licenses'
39
+
40
+ def __init__(self, debug: bool = False, trace: bool = True, quiet: bool = False):
41
+ super().__init__(debug, trace, quiet)
42
+ self.osadl = Osadl(debug=debug, trace=trace, quiet=quiet)
43
+ self.include_licenses = set()
44
+ self.exclude_licenses = set()
45
+ self.explicit_licenses = set()
46
+
47
+ def init(self, include: str = None, exclude: str = None, explicit: str = None):
48
+ """
49
+ Initialize copyleft license filters.
50
+
51
+ :param include: Comma-separated licenses to mark as copyleft (in addition to OSADL)
52
+ :param exclude: Comma-separated licenses to mark as NOT copyleft (override OSADL)
53
+ :param explicit: Comma-separated licenses to use exclusively (ignore OSADL)
54
+ """
55
+ # Reset previous filters so init() can be safely called multiple times
56
+ self.include_licenses.clear()
57
+ self.exclude_licenses.clear()
58
+ self.explicit_licenses.clear()
59
+
60
+ # Parse explicit list (if provided, ignore OSADL completely)
61
+ if explicit:
62
+ self.explicit_licenses = {lic.strip().lower() for lic in explicit.split(',') if lic.strip()}
63
+ self.print_debug(f'Explicit copyleft licenses: {self.explicit_licenses}')
64
+ return
65
+
66
+ # Parse include list (mark these as copyleft in addition to OSADL)
67
+ if include:
68
+ self.include_licenses = {lic.strip().lower() for lic in include.split(',') if lic.strip()}
69
+ self.print_debug(f'Include licenses: {self.include_licenses}')
70
+
71
+ # Parse exclude list (mark these as NOT copyleft, overriding OSADL)
72
+ if exclude:
73
+ self.exclude_licenses = {lic.strip().lower() for lic in exclude.split(',') if lic.strip()}
74
+ self.print_debug(f'Exclude licenses: {self.exclude_licenses}')
75
+
76
+ def is_copyleft(self, spdxid: str) -> bool:
77
+ """
78
+ Check if a license is copyleft.
79
+
80
+ Logic:
81
+ 1. If explicit list provided → check if license in explicit list
82
+ 2. If license in include list → return True
83
+ 3. If license in exclude list → return False
84
+ 4. Otherwise → use OSADL authoritative data
85
+
86
+ :param spdxid: SPDX license identifier
87
+ :return: True if copyleft, False otherwise
88
+ """
89
+ if not spdxid:
90
+ self.print_debug('No license ID provided for copyleft check')
91
+ return False
92
+
93
+ spdxid_lc = spdxid.lower()
94
+
95
+ # Explicit mode: use only the explicit list
96
+ if self.explicit_licenses:
97
+ return spdxid_lc in self.explicit_licenses
98
+
99
+ # Include filter: if license in include list, force copyleft=True
100
+ if spdxid_lc in self.include_licenses:
101
+ return True
102
+
103
+ # Exclude filter: if license in exclude list, force copyleft=False
104
+ if spdxid_lc in self.exclude_licenses:
105
+ return False
106
+
107
+ # No filters matched, use OSADL authoritative data
108
+ return self.osadl.is_copyleft(spdxid)
109
+
110
+ def get_spdx_url(self, spdxid: str) -> str:
111
+ """
112
+ Generate the URL for the SPDX page of a license.
113
+
114
+ :param spdxid: The SPDX identifier of the license
115
+ :return: The URL of the SPDX page for the given license
116
+ """
117
+ return f'{self.BASE_SPDX_ORG_URL}/{spdxid}.html'
118
+
119
+
120
+
121
+ #
122
+ # End of LicenseUtil Class
123
+ #
@@ -0,0 +1,63 @@
1
+ """
2
+ SPDX-License-Identifier: MIT
3
+
4
+ Copyright (c) 2025, 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
+ """
24
+
25
+ def generate_table(headers, rows, centered_columns=None):
26
+ """
27
+ Generate a Markdown table.
28
+
29
+ :param headers: List of headers for the table.
30
+ :param rows: List of rows for the table.
31
+ :param centered_columns: List of column indices to be centered.
32
+ :return: A string representing the Markdown table.
33
+ """
34
+ col_sep = ' | '
35
+ centered_column_set = set(centered_columns or [])
36
+ if headers is None:
37
+ return None
38
+
39
+ # Decide which separator to use
40
+ def create_separator(index):
41
+ if centered_columns is None:
42
+ return '-'
43
+ return ':-:' if index in centered_column_set else '-'
44
+
45
+ # Build the row separator
46
+ row_separator = col_sep + col_sep.join(create_separator(index) for index, _ in enumerate(headers)) + col_sep
47
+ # build table rows
48
+ table_rows = [col_sep + col_sep.join(headers) + col_sep, row_separator]
49
+ table_rows.extend(col_sep + col_sep.join(row) + col_sep for row in rows)
50
+ return '\n'.join(table_rows)
51
+
52
+ def generate_jira_table(headers, rows, centered_columns=None):
53
+ col_sep = '*|*'
54
+ if headers is None:
55
+ return None
56
+
57
+ table_header = '|*' + col_sep.join(headers) + '*|\n'
58
+ table = table_header
59
+ for row in rows:
60
+ if len(headers) == len(row):
61
+ table += '|' + '|'.join(row) + '|\n'
62
+
63
+ return table