scanoss 1.40.1__py3-none-any.whl → 1.41.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.
- scanoss/__init__.py +1 -1
- scanoss/cli.py +14 -0
- scanoss/constants.py +3 -0
- scanoss/data/build_date.txt +1 -1
- scanoss/data/osadl-copyleft.json +133 -0
- scanoss/filecount.py +37 -38
- scanoss/inspection/policy_check/scanoss/copyleft.py +7 -1
- scanoss/inspection/utils/license_utils.py +57 -71
- scanoss/inspection/utils/scan_result_processor.py +22 -11
- scanoss/osadl.py +125 -0
- scanoss/scanner.py +191 -189
- scanoss/scanners/folder_hasher.py +24 -24
- scanoss/scanners/scanner_hfh.py +21 -16
- scanoss/threadedscanning.py +10 -0
- {scanoss-1.40.1.dist-info → scanoss-1.41.1.dist-info}/METADATA +1 -1
- {scanoss-1.40.1.dist-info → scanoss-1.41.1.dist-info}/RECORD +20 -18
- {scanoss-1.40.1.dist-info → scanoss-1.41.1.dist-info}/WHEEL +0 -0
- {scanoss-1.40.1.dist-info → scanoss-1.41.1.dist-info}/entry_points.txt +0 -0
- {scanoss-1.40.1.dist-info → scanoss-1.41.1.dist-info}/licenses/LICENSE +0 -0
- {scanoss-1.40.1.dist-info → scanoss-1.41.1.dist-info}/top_level.txt +0 -0
scanoss/__init__.py
CHANGED
scanoss/cli.py
CHANGED
|
@@ -55,6 +55,7 @@ from . import __version__
|
|
|
55
55
|
from .components import Components
|
|
56
56
|
from .constants import (
|
|
57
57
|
DEFAULT_API_TIMEOUT,
|
|
58
|
+
DEFAULT_COPYLEFT_LICENSE_SOURCES,
|
|
58
59
|
DEFAULT_HFH_DEPTH,
|
|
59
60
|
DEFAULT_HFH_MIN_ACCEPTED_SCORE,
|
|
60
61
|
DEFAULT_HFH_RANK_THRESHOLD,
|
|
@@ -64,6 +65,7 @@ from .constants import (
|
|
|
64
65
|
DEFAULT_TIMEOUT,
|
|
65
66
|
MIN_TIMEOUT,
|
|
66
67
|
PYTHON_MAJOR_VERSION,
|
|
68
|
+
VALID_LICENSE_SOURCES,
|
|
67
69
|
)
|
|
68
70
|
from .csvoutput import CsvOutput
|
|
69
71
|
from .cyclonedx import CycloneDx
|
|
@@ -699,6 +701,17 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
|
|
|
699
701
|
p.add_argument('--exclude', help='Licenses to exclude from analysis (comma-separated list)')
|
|
700
702
|
p.add_argument('--explicit', help='Use only these specific licenses for analysis (comma-separated list)')
|
|
701
703
|
|
|
704
|
+
# License source filtering
|
|
705
|
+
for p in [p_inspect_raw_copyleft, p_inspect_legacy_copyleft]:
|
|
706
|
+
p.add_argument(
|
|
707
|
+
'-ls', '--license-sources',
|
|
708
|
+
action='extend',
|
|
709
|
+
nargs='+',
|
|
710
|
+
choices=VALID_LICENSE_SOURCES,
|
|
711
|
+
help=f'Specify which license sources to check for copyleft violations. Each license object in scan results '
|
|
712
|
+
f'has a source field indicating its origin. Default: {", ".join(DEFAULT_COPYLEFT_LICENSE_SOURCES)}',
|
|
713
|
+
)
|
|
714
|
+
|
|
702
715
|
# Common options for (legacy) copyleft and undeclared component inspection
|
|
703
716
|
for p in [p_inspect_raw_copyleft, p_inspect_raw_undeclared, p_inspect_legacy_copyleft, p_inspect_legacy_undeclared]:
|
|
704
717
|
p.add_argument('-i', '--input', nargs='?', help='Path to scan results file to analyse')
|
|
@@ -1752,6 +1765,7 @@ def inspect_copyleft(parser, args):
|
|
|
1752
1765
|
include=args.include, # Additional licenses to check
|
|
1753
1766
|
exclude=args.exclude, # Licenses to ignore
|
|
1754
1767
|
explicit=args.explicit, # Explicit license list
|
|
1768
|
+
license_sources=args.license_sources, # License sources to check (list)
|
|
1755
1769
|
)
|
|
1756
1770
|
# Execute inspection and exit with appropriate status code
|
|
1757
1771
|
status, _ = i_copyleft.run()
|
scanoss/constants.py
CHANGED
|
@@ -17,3 +17,6 @@ DEFAULT_HFH_RANK_THRESHOLD = 5
|
|
|
17
17
|
DEFAULT_HFH_DEPTH = 1
|
|
18
18
|
DEFAULT_HFH_RECURSIVE_THRESHOLD = 0.8
|
|
19
19
|
DEFAULT_HFH_MIN_ACCEPTED_SCORE = 0.15
|
|
20
|
+
|
|
21
|
+
VALID_LICENSE_SOURCES = ['component_declared', 'license_file', 'file_header', 'file_spdx_tag', 'scancode']
|
|
22
|
+
DEFAULT_COPYLEFT_LICENSE_SOURCES = ['component_declared', 'license_file']
|
scanoss/data/build_date.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
date:
|
|
1
|
+
date: 20251217130422, utime: 1765976662
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": "OSADL Open Source License Obligations Checklist (https:\/\/www.osadl.org\/Checklists)",
|
|
3
|
+
"license": "Creative Commons Attribution 4.0 International license (CC-BY-4.0)",
|
|
4
|
+
"attribution": "A project by the Open Source Automation Development Lab (OSADL) eG. For further information about the project see the description at www.osadl.org\/checklists.",
|
|
5
|
+
"copyright": "(C) 2017 - 2024 Open Source Automation Development Lab (OSADL) eG and contributors, info@osadl.org",
|
|
6
|
+
"disclaimer": "The checklists and particularly the copyleft data have been assembled with maximum diligence and care; however, the authors do not warrant nor can be held liable in any way for its correctness, usefulness, merchantibility or fitness for a particular purpose as far as permissible by applicable law. Anyone who uses the information does this on his or her sole responsibility. For any individual legal advice, it is recommended to contact a lawyer.",
|
|
7
|
+
"timeformat": "%Y-%m-%dT%H:%M:%S%z",
|
|
8
|
+
"timestamp": "2025-10-30T11:23:00+0000",
|
|
9
|
+
"copyleft":
|
|
10
|
+
{
|
|
11
|
+
"0BSD": "No",
|
|
12
|
+
"AFL-2.0": "No",
|
|
13
|
+
"AFL-2.1": "No",
|
|
14
|
+
"AFL-3.0": "No",
|
|
15
|
+
"AGPL-3.0-only": "Yes",
|
|
16
|
+
"AGPL-3.0-or-later": "Yes",
|
|
17
|
+
"Apache-1.0": "No",
|
|
18
|
+
"Apache-1.1": "No",
|
|
19
|
+
"Apache-2.0": "No",
|
|
20
|
+
"APSL-2.0": "Yes (restricted)",
|
|
21
|
+
"Artistic-1.0": "No",
|
|
22
|
+
"Artistic-1.0-Perl": "No",
|
|
23
|
+
"Artistic-2.0": "No",
|
|
24
|
+
"Bitstream-Vera": "No",
|
|
25
|
+
"blessing": "No",
|
|
26
|
+
"BlueOak-1.0.0": "No",
|
|
27
|
+
"BSD-1-Clause": "No",
|
|
28
|
+
"BSD-2-Clause": "No",
|
|
29
|
+
"BSD-2-Clause-Patent": "No",
|
|
30
|
+
"BSD-3-Clause": "No",
|
|
31
|
+
"BSD-3-Clause-Open-MPI": "No",
|
|
32
|
+
"BSD-4-Clause": "No",
|
|
33
|
+
"BSD-4-Clause-UC": "No",
|
|
34
|
+
"BSD-4.3TAHOE": "No",
|
|
35
|
+
"BSD-Source-Code": "No",
|
|
36
|
+
"BSL-1.0": "No",
|
|
37
|
+
"bzip2-1.0.5": "No",
|
|
38
|
+
"bzip2-1.0.6": "No",
|
|
39
|
+
"CC-BY-2.5": "No",
|
|
40
|
+
"CC-BY-3.0": "No",
|
|
41
|
+
"CDDL-1.0": "Yes (restricted)",
|
|
42
|
+
"CDDL-1.1": "Yes (restricted)",
|
|
43
|
+
"CPL-1.0": "Yes",
|
|
44
|
+
"curl": "No",
|
|
45
|
+
"ECL-1.0": "No",
|
|
46
|
+
"ECL-2.0": "No",
|
|
47
|
+
"EFL-2.0": "No",
|
|
48
|
+
"EPL-1.0": "Yes",
|
|
49
|
+
"EPL-2.0": "Yes (restricted)",
|
|
50
|
+
"EUPL-1.1": "Yes",
|
|
51
|
+
"EUPL-1.2": "Yes",
|
|
52
|
+
"FSFAP": "No",
|
|
53
|
+
"FSFUL": "No",
|
|
54
|
+
"FSFULLR": "No",
|
|
55
|
+
"FSFULLRWD": "No",
|
|
56
|
+
"FTL": "No",
|
|
57
|
+
"GPL-1.0-only": "Yes",
|
|
58
|
+
"GPL-1.0-or-later": "Yes",
|
|
59
|
+
"GPL-2.0-only": "Yes",
|
|
60
|
+
"GPL-2.0-only WITH Classpath-exception-2.0": "Yes (restricted)",
|
|
61
|
+
"GPL-2.0-or-later": "Yes",
|
|
62
|
+
"GPL-3.0-only": "Yes",
|
|
63
|
+
"GPL-3.0-or-later": "Yes",
|
|
64
|
+
"HPND": "No",
|
|
65
|
+
"IBM-pibs": "No",
|
|
66
|
+
"ICU": "No",
|
|
67
|
+
"IJG": "No",
|
|
68
|
+
"ImageMagick": "No",
|
|
69
|
+
"Info-ZIP": "No",
|
|
70
|
+
"IPL-1.0": "Yes",
|
|
71
|
+
"ISC": "No",
|
|
72
|
+
"JasPer-2.0": "No",
|
|
73
|
+
"LGPL-2.0-only": "Yes (restricted)",
|
|
74
|
+
"LGPL-2.0-or-later": "Yes (restricted)",
|
|
75
|
+
"LGPL-2.1-only": "Yes (restricted)",
|
|
76
|
+
"LGPL-2.1-or-later": "Yes (restricted)",
|
|
77
|
+
"LGPL-3.0-only": "Yes (restricted)",
|
|
78
|
+
"LGPL-3.0-or-later": "Yes (restricted)",
|
|
79
|
+
"Libpng": "No",
|
|
80
|
+
"libpng-2.0": "No",
|
|
81
|
+
"libtiff": "No",
|
|
82
|
+
"LicenseRef-scancode-bsla-no-advert": "No",
|
|
83
|
+
"LicenseRef-scancode-info-zip-2003-05": "No",
|
|
84
|
+
"LicenseRef-scancode-ppp": "No",
|
|
85
|
+
"Minpack": "No",
|
|
86
|
+
"MirOS": "No",
|
|
87
|
+
"MIT": "No",
|
|
88
|
+
"MIT-0": "No",
|
|
89
|
+
"MIT-CMU": "No",
|
|
90
|
+
"MPL-1.1": "Yes (restricted)",
|
|
91
|
+
"MPL-2.0": "Yes (restricted)",
|
|
92
|
+
"MPL-2.0-no-copyleft-exception": "Yes (restricted)",
|
|
93
|
+
"MS-PL": "Questionable",
|
|
94
|
+
"MS-RL": "Yes (restricted)",
|
|
95
|
+
"NBPL-1.0": "No",
|
|
96
|
+
"NCSA": "No",
|
|
97
|
+
"NTP": "No",
|
|
98
|
+
"OFL-1.1": "Yes (restricted)",
|
|
99
|
+
"OGC-1.0": "No",
|
|
100
|
+
"OLDAP-2.8": "No",
|
|
101
|
+
"OpenSSL": "Questionable",
|
|
102
|
+
"OSL-3.0": "Yes",
|
|
103
|
+
"PHP-3.01": "No",
|
|
104
|
+
"PostgreSQL": "No",
|
|
105
|
+
"PSF-2.0": "No",
|
|
106
|
+
"Python-2.0": "No",
|
|
107
|
+
"Qhull": "No",
|
|
108
|
+
"RSA-MD": "No",
|
|
109
|
+
"Saxpath": "No",
|
|
110
|
+
"SGI-B-2.0": "No",
|
|
111
|
+
"Sleepycat": "Yes",
|
|
112
|
+
"SMLNJ": "No",
|
|
113
|
+
"Spencer-86": "No",
|
|
114
|
+
"SSH-OpenSSH": "No",
|
|
115
|
+
"SSH-short": "No",
|
|
116
|
+
"SunPro": "No",
|
|
117
|
+
"Ubuntu-font-1.0": "Yes (restricted)",
|
|
118
|
+
"Unicode-3.0": "No",
|
|
119
|
+
"Unicode-DFS-2015": "No",
|
|
120
|
+
"Unicode-DFS-2016": "No",
|
|
121
|
+
"Unlicense": "No",
|
|
122
|
+
"UPL-1.0": "No",
|
|
123
|
+
"W3C": "No",
|
|
124
|
+
"W3C-19980720": "No",
|
|
125
|
+
"W3C-20150513": "No",
|
|
126
|
+
"WTFPL": "No",
|
|
127
|
+
"X11": "No",
|
|
128
|
+
"XFree86-1.1": "No",
|
|
129
|
+
"Zlib": "No",
|
|
130
|
+
"zlib-acknowledgement": "No",
|
|
131
|
+
"ZPL-2.0": "No"
|
|
132
|
+
}
|
|
133
|
+
}
|
scanoss/filecount.py
CHANGED
|
@@ -26,6 +26,7 @@ import csv
|
|
|
26
26
|
import os
|
|
27
27
|
import pathlib
|
|
28
28
|
import sys
|
|
29
|
+
from contextlib import nullcontext
|
|
29
30
|
|
|
30
31
|
from progress.spinner import Spinner
|
|
31
32
|
|
|
@@ -105,48 +106,46 @@ class FileCount(ScanossBase):
|
|
|
105
106
|
"""
|
|
106
107
|
success = True
|
|
107
108
|
if not scan_dir:
|
|
108
|
-
raise Exception(
|
|
109
|
+
raise Exception('ERROR: Please specify a folder to scan')
|
|
109
110
|
if not os.path.exists(scan_dir) or not os.path.isdir(scan_dir):
|
|
110
111
|
raise Exception(f'ERROR: Specified folder does not exist or is not a folder: {scan_dir}')
|
|
111
112
|
|
|
112
113
|
self.print_msg(f'Searching {scan_dir} for files to count...')
|
|
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
|
-
if spinner:
|
|
149
|
-
spinner.finish()
|
|
114
|
+
spinner_ctx = Spinner('Searching ') if (not self.quiet and self.isatty) else nullcontext()
|
|
115
|
+
|
|
116
|
+
with spinner_ctx as spinner:
|
|
117
|
+
file_types = {}
|
|
118
|
+
file_count = 0
|
|
119
|
+
file_size = 0
|
|
120
|
+
for root, dirs, files in os.walk(scan_dir):
|
|
121
|
+
self.print_trace(f'U Root: {root}, Dirs: {dirs}, Files {files}')
|
|
122
|
+
dirs[:] = self.__filter_dirs(dirs) # Strip out unwanted directories
|
|
123
|
+
filtered_files = self.__filter_files(files) # Strip out unwanted files
|
|
124
|
+
self.print_trace(f'F Root: {root}, Dirs: {dirs}, Files {filtered_files}')
|
|
125
|
+
for file in filtered_files: # Cycle through each filtered file
|
|
126
|
+
path = os.path.join(root, file)
|
|
127
|
+
f_size = 0
|
|
128
|
+
try:
|
|
129
|
+
f_size = os.stat(path).st_size
|
|
130
|
+
except Exception as e:
|
|
131
|
+
self.print_trace(f'Ignoring missing symlink file: {file} ({e})') # broken symlink
|
|
132
|
+
if f_size > 0: # Ignore broken links and empty files
|
|
133
|
+
file_count = file_count + 1
|
|
134
|
+
file_size = file_size + f_size
|
|
135
|
+
f_suffix = pathlib.Path(file).suffix
|
|
136
|
+
if not f_suffix or f_suffix == '':
|
|
137
|
+
f_suffix = 'no_suffix'
|
|
138
|
+
self.print_trace(f'Counting {path} ({f_suffix} - {f_size})..')
|
|
139
|
+
fc = file_types.get(f_suffix)
|
|
140
|
+
if not fc:
|
|
141
|
+
fc = [1, f_size]
|
|
142
|
+
else:
|
|
143
|
+
fc[0] = fc[0] + 1
|
|
144
|
+
fc[1] = fc[1] + f_size
|
|
145
|
+
file_types[f_suffix] = fc
|
|
146
|
+
if spinner:
|
|
147
|
+
spinner.next()
|
|
148
|
+
# End for loop
|
|
150
149
|
self.print_stderr(f'Found {file_count:,.0f} files with a total size of {file_size / (1 << 20):,.2f} MB.')
|
|
151
150
|
if file_types:
|
|
152
151
|
csv_dict = []
|
|
@@ -26,6 +26,8 @@ import json
|
|
|
26
26
|
from dataclasses import dataclass
|
|
27
27
|
from typing import Dict, List
|
|
28
28
|
|
|
29
|
+
from scanoss.constants import DEFAULT_COPYLEFT_LICENSE_SOURCES
|
|
30
|
+
|
|
29
31
|
from ...policy_check.policy_check import PolicyCheck, PolicyOutput, PolicyStatus
|
|
30
32
|
from ...utils.markdown_utils import generate_jira_table, generate_table
|
|
31
33
|
from ...utils.scan_result_processor import ScanResultProcessor
|
|
@@ -63,6 +65,7 @@ class Copyleft(PolicyCheck[Component]):
|
|
|
63
65
|
include: str = None,
|
|
64
66
|
exclude: str = None,
|
|
65
67
|
explicit: str = None,
|
|
68
|
+
license_sources: list = None,
|
|
66
69
|
):
|
|
67
70
|
"""
|
|
68
71
|
Initialise the Copyleft class.
|
|
@@ -77,6 +80,7 @@ class Copyleft(PolicyCheck[Component]):
|
|
|
77
80
|
:param include: Licenses to include in the analysis
|
|
78
81
|
:param exclude: Licenses to exclude from the analysis
|
|
79
82
|
:param explicit: Explicitly defined licenses
|
|
83
|
+
:param license_sources: List of license sources to check
|
|
80
84
|
"""
|
|
81
85
|
super().__init__(
|
|
82
86
|
debug, trace, quiet, format_type, status, name='Copyleft Policy', output=output
|
|
@@ -85,6 +89,7 @@ class Copyleft(PolicyCheck[Component]):
|
|
|
85
89
|
self.filepath = filepath
|
|
86
90
|
self.output = output
|
|
87
91
|
self.status = status
|
|
92
|
+
self.license_sources = license_sources or DEFAULT_COPYLEFT_LICENSE_SOURCES
|
|
88
93
|
self.results_processor = ScanResultProcessor(
|
|
89
94
|
self.debug,
|
|
90
95
|
self.trace,
|
|
@@ -92,7 +97,8 @@ class Copyleft(PolicyCheck[Component]):
|
|
|
92
97
|
self.filepath,
|
|
93
98
|
include,
|
|
94
99
|
exclude,
|
|
95
|
-
explicit
|
|
100
|
+
explicit,
|
|
101
|
+
self.license_sources)
|
|
96
102
|
|
|
97
103
|
def _json(self, components: list[Component]) -> PolicyOutput:
|
|
98
104
|
"""
|
|
@@ -22,96 +22,90 @@ SPDX-License-Identifier: MIT
|
|
|
22
22
|
THE SOFTWARE.
|
|
23
23
|
"""
|
|
24
24
|
|
|
25
|
-
from
|
|
25
|
+
from scanoss.osadl import Osadl
|
|
26
26
|
|
|
27
|
-
|
|
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',
|
|
49
|
-
}
|
|
27
|
+
from ...scanossbase import ScanossBase
|
|
50
28
|
|
|
51
29
|
|
|
52
30
|
class LicenseUtil(ScanossBase):
|
|
53
31
|
"""
|
|
54
32
|
A utility class for handling software licenses, particularly copyleft licenses.
|
|
55
33
|
|
|
56
|
-
|
|
57
|
-
|
|
34
|
+
Uses OSADL (Open Source Automation Development Lab) authoritative copyleft data
|
|
35
|
+
with optional include/exclude/explicit filters.
|
|
58
36
|
"""
|
|
59
37
|
|
|
60
38
|
BASE_SPDX_ORG_URL = 'https://spdx.org/licenses'
|
|
61
|
-
BASE_OSADL_URL = 'https://www.osadl.org/fileadmin/checklists/unreflicenses'
|
|
62
39
|
|
|
63
40
|
def __init__(self, debug: bool = False, trace: bool = True, quiet: bool = False):
|
|
64
41
|
super().__init__(debug, trace, quiet)
|
|
65
|
-
self.
|
|
66
|
-
self.
|
|
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()
|
|
67
46
|
|
|
68
47
|
def init(self, include: str = None, exclude: str = None, explicit: str = None):
|
|
69
48
|
"""
|
|
70
|
-
Initialize
|
|
71
|
-
|
|
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
|
|
49
|
+
Initialize copyleft license filters.
|
|
76
50
|
|
|
77
|
-
:param include: Comma-separated
|
|
78
|
-
:param exclude: Comma-separated
|
|
79
|
-
:param explicit: Comma-separated
|
|
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)
|
|
80
54
|
"""
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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)
|
|
87
61
|
if explicit:
|
|
88
|
-
|
|
89
|
-
self.
|
|
90
|
-
self.print_debug(f'Copyleft licenses: ${self.copyleft_licenses}')
|
|
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}')
|
|
91
64
|
return
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if include:
|
|
95
|
-
include = include.strip()
|
|
65
|
+
|
|
66
|
+
# Parse include list (mark these as copyleft in addition to OSADL)
|
|
96
67
|
if include:
|
|
97
|
-
|
|
98
|
-
self.
|
|
99
|
-
|
|
100
|
-
|
|
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)
|
|
101
72
|
if exclude:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
self.copyleft_licenses.discard(lic)
|
|
105
|
-
self.print_debug(f'Copyleft licenses: ${self.copyleft_licenses}')
|
|
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}')
|
|
106
75
|
|
|
107
76
|
def is_copyleft(self, spdxid: str) -> bool:
|
|
108
77
|
"""
|
|
109
|
-
Check if a
|
|
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
|
|
110
85
|
|
|
111
|
-
:param spdxid:
|
|
112
|
-
:return: True if
|
|
86
|
+
:param spdxid: SPDX license identifier
|
|
87
|
+
:return: True if copyleft, False otherwise
|
|
113
88
|
"""
|
|
114
|
-
|
|
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)
|
|
115
109
|
|
|
116
110
|
def get_spdx_url(self, spdxid: str) -> str:
|
|
117
111
|
"""
|
|
@@ -122,14 +116,6 @@ class LicenseUtil(ScanossBase):
|
|
|
122
116
|
"""
|
|
123
117
|
return f'{self.BASE_SPDX_ORG_URL}/{spdxid}.html'
|
|
124
118
|
|
|
125
|
-
def get_osadl_url(self, spdxid: str) -> str:
|
|
126
|
-
"""
|
|
127
|
-
Generate the URL for the OSADL (Open Source Automation Development Lab) page of a license.
|
|
128
|
-
|
|
129
|
-
:param spdxid: The SPDX identifier of the license
|
|
130
|
-
:return: The URL of the OSADL page for the given license
|
|
131
|
-
"""
|
|
132
|
-
return f'{self.BASE_OSADL_URL}/{spdxid}.txt'
|
|
133
119
|
|
|
134
120
|
|
|
135
121
|
#
|
|
@@ -71,11 +71,13 @@ class ScanResultProcessor(ScanossBase):
|
|
|
71
71
|
include: str = None,
|
|
72
72
|
exclude: str = None,
|
|
73
73
|
explicit: str = None,
|
|
74
|
+
license_sources: list = None,
|
|
74
75
|
):
|
|
75
76
|
super().__init__(debug, trace, quiet)
|
|
76
77
|
self.result_file_path = result_file_path
|
|
77
78
|
self.license_util = LicenseUtil()
|
|
78
79
|
self.license_util.init(include, exclude, explicit)
|
|
80
|
+
self.license_sources = license_sources
|
|
79
81
|
self.results = self._load_input_file()
|
|
80
82
|
|
|
81
83
|
def get_results(self) -> Dict[str, Any]:
|
|
@@ -162,9 +164,11 @@ class ScanResultProcessor(ScanossBase):
|
|
|
162
164
|
self.print_debug(f'WARNING: Results missing licenses. Skipping: {new_component}')
|
|
163
165
|
return
|
|
164
166
|
|
|
165
|
-
|
|
167
|
+
# Select licenses based on configuration (filtering or priority mode)
|
|
168
|
+
selected_licenses = self._select_licenses(new_component['licenses'])
|
|
169
|
+
|
|
166
170
|
# Process licenses for this component
|
|
167
|
-
for license_item in
|
|
171
|
+
for license_item in selected_licenses:
|
|
168
172
|
if license_item.get('name'):
|
|
169
173
|
spdxid = license_item['name']
|
|
170
174
|
source = license_item.get('source')
|
|
@@ -309,19 +313,26 @@ class ScanResultProcessor(ScanossBase):
|
|
|
309
313
|
component['licenses'] = []
|
|
310
314
|
return results_list
|
|
311
315
|
|
|
312
|
-
def
|
|
316
|
+
def _select_licenses(self, licenses_data):
|
|
313
317
|
"""
|
|
314
|
-
Select licenses based on
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
318
|
+
Select licenses based on configuration.
|
|
319
|
+
|
|
320
|
+
Two modes:
|
|
321
|
+
- Filtering mode: If license_sources specified, filter to those sources
|
|
322
|
+
- Priority mode: Otherwise, use original priority-based selection
|
|
319
323
|
|
|
320
|
-
|
|
321
|
-
|
|
324
|
+
Args:
|
|
325
|
+
licenses_data: List of license dictionaries
|
|
322
326
|
|
|
323
|
-
Returns:
|
|
327
|
+
Returns:
|
|
328
|
+
Filtered list of licenses based on configuration
|
|
324
329
|
"""
|
|
330
|
+
# Filtering mode, when license_sources is explicitly provided
|
|
331
|
+
if self.license_sources:
|
|
332
|
+
sources_to_include = set(self.license_sources) | {'unknown'}
|
|
333
|
+
return [lic for lic in licenses_data
|
|
334
|
+
if lic.get('source') in sources_to_include or lic.get('source') is None]
|
|
335
|
+
|
|
325
336
|
# Define priority order (highest to lowest)
|
|
326
337
|
priority_sources = ['component_declared', 'license_file', 'file_header', 'scancode']
|
|
327
338
|
|