fosslight-source 1.7.16__py3-none-any.whl → 2.1.0__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.
fosslight_source/_help.py CHANGED
@@ -30,10 +30,10 @@ _HELP_MESSAGE_SOURCE_SCANNER = """
30
30
  --correct_fpath <path> Path to the sbom-info.yaml file"""
31
31
 
32
32
 
33
- def print_version(pkg_name):
33
+ def print_version(pkg_name: str) -> None:
34
34
  print_package_version(pkg_name, "FOSSLight Source Scanner Version:")
35
35
 
36
36
 
37
- def print_help_msg_source_scanner():
37
+ def print_help_msg_source_scanner() -> None:
38
38
  helpMsg = PrintHelpMsg(_HELP_MESSAGE_SOURCE_SCANNER)
39
39
  helpMsg.print_help_msg(True)
@@ -20,33 +20,33 @@ class MatchedLicense:
20
20
  matched_text = ""
21
21
  priority = 0
22
22
 
23
- def __init__(self, lic, category, text, file):
23
+ def __init__(self, lic: str, category: str, text: str, file: str) -> None:
24
24
  self.files = [file]
25
25
  self.license = lic
26
26
  self.matched_text = text
27
27
  self.set_category(category)
28
28
 
29
- def __del__(self):
29
+ def __del__(self) -> None:
30
30
  pass
31
31
 
32
- def set_license(self, value):
32
+ def set_license(self, value: str) -> None:
33
33
  self.license = value
34
34
 
35
- def set_files(self, value):
35
+ def set_files(self, value: str) -> None:
36
36
  if value not in self.files:
37
37
  self.files.append(value)
38
38
 
39
- def set_category(self, value):
39
+ def set_category(self, value: str) -> None:
40
40
  self.category = value
41
41
  if value in LOW_PRIORITY:
42
42
  self.priority = 1
43
43
  else:
44
44
  self.priority = 0
45
45
 
46
- def set_matched_text(self, value):
46
+ def set_matched_text(self, value: str) -> None:
47
47
  self.matched_text = value
48
48
 
49
- def get_row_to_print(self, result_for_32_earlier=True):
49
+ def get_row_to_print(self, result_for_32_earlier: bool = True) -> list:
50
50
  if result_for_32_earlier:
51
51
  print_rows = [self.category, self.license, self.matched_text, str(len(self.files)), ','.join(self.files)]
52
52
  else:
@@ -54,7 +54,7 @@ class MatchedLicense:
54
54
  return print_rows
55
55
 
56
56
 
57
- def get_license_list_to_print(license_list):
57
+ def get_license_list_to_print(license_list: dict) -> list:
58
58
  result_for_32_earlier = any([value.category for key, value in license_list.items()])
59
59
  license_items = license_list.values()
60
60
  license_items = sorted(license_items, key=lambda row: (row.priority, row.category, row.license))
@@ -8,11 +8,12 @@ import logging
8
8
  import re
9
9
  import fosslight_util.constant as constant
10
10
  from ._license_matched import MatchedLicense
11
- from ._scan_item import ScanItem
11
+ from ._scan_item import SourceItem
12
12
  from ._scan_item import is_exclude_dir
13
13
  from ._scan_item import is_exclude_file
14
14
  from ._scan_item import replace_word
15
15
  from ._scan_item import is_notice_file
16
+ from typing import Tuple
16
17
 
17
18
  logger = logging.getLogger(constant.LOGGER_NAME)
18
19
  _exclude_directory = ["test", "tests", "doc", "docs"]
@@ -30,7 +31,7 @@ KEY_AND = r"(?<=\s)and(?=\s)"
30
31
  KEY_OR = r"(?<=\s)or(?=\s)"
31
32
 
32
33
 
33
- def get_error_from_header(header_item):
34
+ def get_error_from_header(header_item: list) -> Tuple[bool, str]:
34
35
  has_error = False
35
36
  str_error = ""
36
37
  key_error = "errors"
@@ -49,7 +50,7 @@ def get_error_from_header(header_item):
49
50
  return has_error, str_error
50
51
 
51
52
 
52
- def parsing_scancode_32_earlier(scancode_file_list, has_error=False):
53
+ def parsing_scancode_32_earlier(scancode_file_list: list, has_error: bool = False) -> Tuple[bool, list, list, dict]:
53
54
  rc = True
54
55
  msg = []
55
56
  scancode_file_item = []
@@ -75,7 +76,7 @@ def parsing_scancode_32_earlier(scancode_file_list, has_error=False):
75
76
  licenses = file.get("licenses", [])
76
77
  copyright_list = file.get("copyrights", [])
77
78
 
78
- result_item = ScanItem(file_path)
79
+ result_item = SourceItem(file_path)
79
80
 
80
81
  if has_error and "scan_errors" in file:
81
82
  error_msg = file.get("scan_errors", [])
@@ -178,7 +179,7 @@ def parsing_scancode_32_earlier(scancode_file_list, has_error=False):
178
179
  return rc, scancode_file_item, msg, license_list
179
180
 
180
181
 
181
- def split_spdx_expression(spdx_string):
182
+ def split_spdx_expression(spdx_string: str) -> list:
182
183
  license = []
183
184
  for replace in SPDX_REPLACE_WORDS:
184
185
  spdx_string = spdx_string.replace(replace, "")
@@ -186,7 +187,9 @@ def split_spdx_expression(spdx_string):
186
187
  return license
187
188
 
188
189
 
189
- def parsing_scancode_32_later(scancode_file_list, has_error=False):
190
+ def parsing_scancode_32_later(
191
+ scancode_file_list: list, has_error: bool = False
192
+ ) -> Tuple[bool, list, list, dict]:
190
193
  rc = True
191
194
  msg = []
192
195
  scancode_file_item = []
@@ -201,7 +204,7 @@ def parsing_scancode_32_later(scancode_file_list, has_error=False):
201
204
  if (not file_path) or is_binary or is_dir:
202
205
  continue
203
206
 
204
- result_item = ScanItem(file_path)
207
+ result_item = SourceItem(file_path)
205
208
 
206
209
  if has_error:
207
210
  error_msg = file.get("scan_errors", [])
@@ -274,7 +277,9 @@ def parsing_scancode_32_later(scancode_file_list, has_error=False):
274
277
  return rc, scancode_file_item, msg, license_list
275
278
 
276
279
 
277
- def parsing_file_item(scancode_file_list, has_error, need_matched_license=False):
280
+ def parsing_file_item(
281
+ scancode_file_list: list, has_error: bool, need_matched_license: bool = False
282
+ ) -> Tuple[bool, list, list, dict]:
278
283
 
279
284
  rc = True
280
285
  msg = []
@@ -6,9 +6,10 @@
6
6
  import os
7
7
  import logging
8
8
  import fosslight_util.constant as constant
9
- from ._scan_item import ScanItem
9
+ from ._scan_item import SourceItem
10
10
  from ._scan_item import is_exclude_file
11
11
  from ._scan_item import replace_word
12
+ from typing import Tuple
12
13
 
13
14
  logger = logging.getLogger(constant.LOGGER_NAME)
14
15
  SCANOSS_INFO_HEADER = ['No', 'Source Path', 'Component Declared', 'SPDX Tag',
@@ -16,26 +17,26 @@ SCANOSS_INFO_HEADER = ['No', 'Source Path', 'Component Declared', 'SPDX Tag',
16
17
  'Matched Rate (line number)', 'scanoss_fileURL']
17
18
 
18
19
 
19
- def parsing_extraInfo(scanned_result):
20
+ def parsing_extraInfo(scanned_result: dict) -> list:
20
21
  scanoss_extra_info = []
21
22
  for scan_item in scanned_result:
22
23
  license_w_source = scan_item.scanoss_reference
23
24
  if scan_item.matched_lines:
24
25
  if license_w_source:
25
- extra_item = [scan_item.file, ','.join(license_w_source['component_declared']),
26
+ extra_item = [scan_item.source_name_or_path, ','.join(license_w_source['component_declared']),
26
27
  ','.join(license_w_source['file_spdx_tag']),
27
28
  ','.join(license_w_source['file_header']),
28
29
  ','.join(license_w_source['license_file']),
29
30
  ','.join(license_w_source['scancode']),
30
31
  scan_item.matched_lines, scan_item.fileURL]
31
32
  else:
32
- extra_item = [scan_item.file, '', '', '', '', '', scan_item.matched_lines, scan_item.fileURL]
33
+ extra_item = [scan_item.source_name_or_path, '', '', '', '', '', scan_item.matched_lines, scan_item.fileURL]
33
34
  scanoss_extra_info.append(extra_item)
34
35
  scanoss_extra_info.insert(0, SCANOSS_INFO_HEADER)
35
36
  return scanoss_extra_info
36
37
 
37
38
 
38
- def parsing_scanResult(scanoss_report, path_to_scan="", path_to_exclude=[]):
39
+ def parsing_scanResult(scanoss_report: dict, path_to_scan: str = "", path_to_exclude: list = []) -> Tuple[bool, list]:
39
40
  scanoss_file_item = []
40
41
  abs_path_to_exclude = [os.path.abspath(os.path.join(path_to_scan, path)) for path in path_to_exclude]
41
42
 
@@ -43,7 +44,8 @@ def parsing_scanResult(scanoss_report, path_to_scan="", path_to_exclude=[]):
43
44
  abs_file_path = os.path.abspath(os.path.join(path_to_scan, file_path))
44
45
  if any(os.path.commonpath([abs_file_path, exclude_path]) == exclude_path for exclude_path in abs_path_to_exclude):
45
46
  continue
46
- result_item = ScanItem(file_path)
47
+ result_item = SourceItem(file_path)
48
+
47
49
  if 'id' in findings[0]:
48
50
  if "none" == findings[0]['id']:
49
51
  continue
@@ -7,6 +7,7 @@ import os
7
7
  import logging
8
8
  import re
9
9
  import fosslight_util.constant as constant
10
+ from fosslight_util.oss_item import FileItem, OssItem, get_checksum_sha1
10
11
 
11
12
  logger = logging.getLogger(constant.LOGGER_NAME)
12
13
  replace_word = ["-only", "-old-style", "-or-later", "licenseref-scancode-", "licenseref-"]
@@ -25,49 +26,36 @@ MAX_LICENSE_TOTAL_LENGTH = 600
25
26
  SUBSTRING_LICENSE_COMMENT = "Maximum character limit (License)"
26
27
 
27
28
 
28
- class ScanItem:
29
- file = ""
30
- scanoss_reference = {}
31
- exclude = False
32
- is_license_text = False
33
- oss_name = ""
34
- oss_version = ""
35
- download_location = []
36
- matched_lines = "" # Only for SCANOSS results
37
- fileURL = "" # Only for SCANOSS results
38
- license_reference = ""
39
-
40
- def __init__(self, value):
41
- self.file = value
42
- self._copyright = []
43
- self._licenses = []
44
- self.download_location = []
45
- self.comment = ""
46
- self.exclude = False
29
+ class SourceItem(FileItem):
30
+
31
+ def __init__(self, value: str) -> None:
32
+ super().__init__("")
33
+ self.source_name_or_path = value
47
34
  self.is_license_text = False
35
+ self.license_reference = ""
36
+ self.scanoss_reference = {}
37
+ self.matched_lines = "" # Only for SCANOSS results
38
+ self.fileURL = "" # Only for SCANOSS results
39
+ self.download_location = []
40
+ self.copyright = []
41
+ self._licenses = []
42
+ self.oss_name = ""
43
+ self.oss_version = ""
44
+
45
+ self.checksum = get_checksum_sha1(value)
48
46
 
49
- def __del__(self):
47
+ def __del__(self) -> None:
50
48
  pass
51
49
 
52
- def __hash__(self):
50
+ def __hash__(self) -> int:
53
51
  return hash(self.file)
54
52
 
55
53
  @property
56
- def copyright(self):
57
- return self._copyright
58
-
59
- @copyright.setter
60
- def copyright(self, value):
61
- self._copyright.extend(value)
62
- if len(self._copyright) > 0:
63
- self._copyright = list(set(self._copyright))
64
-
65
- @property
66
- def licenses(self):
54
+ def licenses(self) -> list:
67
55
  return self._licenses
68
56
 
69
57
  @licenses.setter
70
- def licenses(self, value):
58
+ def licenses(self, value: list) -> None:
71
59
  if value:
72
60
  max_length_exceed = False
73
61
  for new_lic in value:
@@ -84,30 +72,37 @@ class ScanItem:
84
72
  if max_length_exceed and (SUBSTRING_LICENSE_COMMENT not in self.comment):
85
73
  self.comment = f"{self.comment}/ {SUBSTRING_LICENSE_COMMENT}" if self.comment else SUBSTRING_LICENSE_COMMENT
86
74
 
87
- def get_file(self):
88
- return self.file
75
+ def set_oss_item(self) -> None:
76
+ self.oss_items = []
77
+ if self.download_location:
78
+ for url in self.download_location:
79
+ item = OssItem(self.oss_name, self.oss_version, self.licenses, url)
80
+ item.copyright = "\n".join(self.copyright)
81
+ item.comment = self.comment
82
+ self.oss_items.append(item)
83
+ else:
84
+ item = OssItem(self.oss_name, self.oss_version, self.licenses)
85
+ item.copyright = "\n".join(self.copyright)
86
+ item.comment = self.comment
87
+ self.oss_items.append(item)
89
88
 
90
- def get_row_to_print(self):
89
+ def get_print_array(self) -> list:
91
90
  print_rows = []
92
- if not self.download_location:
93
- print_rows.append([self.file, self.oss_name, self.oss_version, ",".join(self.licenses), "", "",
94
- "\n".join(self.copyright), "Exclude" if self.exclude else "", self.comment,
91
+ for item in self.oss_items:
92
+ print_rows.append([self.source_name_or_path, item.name, item.version, ",".join(item.license),
93
+ item.download_location, "",
94
+ item.copyright, "Exclude" if self.exclude else "", item.comment,
95
95
  self.license_reference])
96
- else:
97
- for url in self.download_location:
98
- print_rows.append([self.file, self.oss_name, self.oss_version, ",".join(self.licenses), url, "",
99
- "\n".join(self.copyright), "Exclude" if self.exclude else "", self.comment,
100
- self.license_reference])
101
96
  return print_rows
102
97
 
103
- def __eq__(self, other):
98
+ def __eq__(self, other: object) -> bool:
104
99
  if type(other) == str:
105
- return self.file == other
100
+ return self.source_name_or_path == other
106
101
  else:
107
- return self.file == other.file
102
+ return self.source_name_or_path == other.source_name_or_path
108
103
 
109
104
 
110
- def is_exclude_dir(dir_path):
105
+ def is_exclude_dir(dir_path: str) -> bool:
111
106
  if dir_path != "":
112
107
  dir_path = dir_path.lower()
113
108
  dir_path = dir_path if dir_path.endswith(
@@ -118,7 +113,7 @@ def is_exclude_dir(dir_path):
118
113
  return False
119
114
 
120
115
 
121
- def is_exclude_file(file_path, prev_dir=None, prev_dir_exclude_value=None):
116
+ def is_exclude_file(file_path: str, prev_dir: str = None, prev_dir_exclude_value: bool = None) -> bool:
122
117
  file_path = file_path.lower()
123
118
  filename = os.path.basename(file_path)
124
119
  if os.path.splitext(filename)[1] in _exclude_extension:
@@ -140,7 +135,7 @@ def is_exclude_file(file_path, prev_dir=None, prev_dir_exclude_value=None):
140
135
  return False
141
136
 
142
137
 
143
- def is_notice_file(file_path):
138
+ def is_notice_file(file_path: str) -> bool:
144
139
  pattern = r"({})(?<!w)".format("|".join(_notice_filename))
145
140
  file_path = file_path.lower()
146
141
  filename = os.path.basename(file_path)
fosslight_source/cli.py CHANGED
@@ -5,6 +5,7 @@
5
5
 
6
6
  import sys
7
7
  import os
8
+ import platform
8
9
  import warnings
9
10
  import logging
10
11
  from datetime import datetime
@@ -13,7 +14,7 @@ from fosslight_util.set_log import init_log
13
14
  from fosslight_util.timer_thread import TimerThread
14
15
  from ._help import print_version, print_help_msg_source_scanner
15
16
  from ._license_matched import get_license_list_to_print
16
- from fosslight_util.output_format import check_output_formats, write_output_file
17
+ from fosslight_util.output_format import check_output_formats_v2, write_output_file
17
18
  from fosslight_util.correct import correct_with_yaml
18
19
  from .run_scancode import run_scan
19
20
  from .run_scanoss import run_scanoss_py
@@ -21,8 +22,9 @@ from .run_scanoss import get_scanoss_extra_info
21
22
  import yaml
22
23
  import argparse
23
24
  from .run_spdx_extractor import get_spdx_downloads
24
- from ._scan_item import ScanItem
25
- from fosslight_util.cover import CoverItem
25
+ from ._scan_item import SourceItem
26
+ from fosslight_util.oss_item import ScannerItem
27
+ from typing import Tuple
26
28
 
27
29
  SRC_SHEET_NAME = 'SRC_FL_Source'
28
30
  SCANOSS_HEADER = {SRC_SHEET_NAME: ['ID', 'Source Path', 'OSS Name',
@@ -35,11 +37,11 @@ SCANNER_TYPE = ['scancode', 'scanoss', 'all', '']
35
37
 
36
38
  logger = logging.getLogger(constant.LOGGER_NAME)
37
39
  warnings.filterwarnings("ignore", category=FutureWarning)
38
- _PKG_NAME = "fosslight_source"
40
+ PKG_NAME = "fosslight_source"
39
41
  RESULT_KEY = "Scan Result"
40
42
 
41
43
 
42
- def main():
44
+ def main() -> None:
43
45
  global logger
44
46
  _result_log = {}
45
47
 
@@ -48,7 +50,7 @@ def main():
48
50
  write_json_file = False
49
51
  output_file_name = ""
50
52
  print_matched_text = False
51
- formats = ""
53
+ formats = []
52
54
  selected_scanner = ""
53
55
  correct_mode = True
54
56
 
@@ -75,7 +77,7 @@ def main():
75
77
  if args.help:
76
78
  print_help_msg_source_scanner()
77
79
  if args.version:
78
- print_version(_PKG_NAME)
80
+ print_version(PKG_NAME)
79
81
  if not args.path:
80
82
  path_to_scan = os.getcwd()
81
83
  else:
@@ -121,7 +123,7 @@ def main():
121
123
  sys.exit(1)
122
124
 
123
125
 
124
- def count_files(path_to_scan, path_to_exclude):
126
+ def count_files(path_to_scan: str, path_to_exclude: list) -> Tuple[int, int]:
125
127
  total_files = 0
126
128
  excluded_files = 0
127
129
  abs_path_to_exclude = [os.path.abspath(os.path.join(path_to_scan, path)) for path in path_to_exclude]
@@ -138,9 +140,15 @@ def count_files(path_to_scan, path_to_exclude):
138
140
  return total_files, excluded_files
139
141
 
140
142
 
141
- def create_report_file(_start_time, merged_result, license_list, scanoss_result, selected_scanner, need_license=False,
142
- output_path="", output_files=[], output_extensions=[], correct_mode=True, correct_filepath="",
143
- path_to_scan="", path_to_exclude=[]):
143
+ def create_report_file(
144
+ _start_time: str, merged_result: list,
145
+ license_list: list, scanoss_result: list,
146
+ selected_scanner: str, need_license: bool = False,
147
+ output_path: str = "", output_files: list = [],
148
+ output_extensions: list = [], correct_mode: bool = True,
149
+ correct_filepath: str = "", path_to_scan: str = "", path_to_exclude: list = [],
150
+ formats: list = []
151
+ ) -> 'ScannerItem':
144
152
  """
145
153
  Create report files for given scanned result.
146
154
 
@@ -162,33 +170,51 @@ def create_report_file(_start_time, merged_result, license_list, scanoss_result,
162
170
  # If -o does not contains file name, set default name
163
171
  while len(output_files) < len(output_extensions):
164
172
  output_files.append(None)
173
+ to_remove = [] # elements of spdx format on windows that should be removed
165
174
  for i, output_extension in enumerate(output_extensions):
166
175
  if output_files[i] is None or output_files[i] == "":
167
- if output_extension == _json_ext:
168
- output_files[i] = f"fosslight_opossum_src_{_start_time}"
176
+ if formats:
177
+ if formats[i].startswith('spdx'):
178
+ if platform.system() != 'Windows':
179
+ output_files[i] = f"fosslight_spdx_src_{_start_time}"
180
+ else:
181
+ logger.warning('spdx format is not supported on Windows. Please remove spdx from format.')
182
+ to_remove.append(i)
183
+ else:
184
+ if output_extension == _json_ext:
185
+ output_files[i] = f"fosslight_opossum_src_{_start_time}"
186
+ else:
187
+ output_files[i] = f"fosslight_report_src_{_start_time}"
169
188
  else:
170
- output_files[i] = f"fosslight_report_src_{_start_time}"
189
+ if output_extension == _json_ext:
190
+ output_files[i] = f"fosslight_opossum_src_{_start_time}"
191
+ else:
192
+ output_files[i] = f"fosslight_report_src_{_start_time}"
193
+ for index in sorted(to_remove, reverse=True):
194
+ # remove elements of spdx format on windows
195
+ del output_files[index]
196
+ del output_extensions[index]
197
+ del formats[index]
198
+ if len(output_extensions) < 1:
199
+ sys.exit(0)
171
200
 
172
201
  if not correct_filepath:
173
202
  correct_filepath = path_to_scan
174
- cover = CoverItem(tool_name=_PKG_NAME,
175
- start_time=_start_time,
176
- input_path=path_to_scan,
177
- exclude_path=path_to_exclude)
203
+
204
+ scan_item = ScannerItem(PKG_NAME, _start_time)
205
+ scan_item.set_cover_pathinfo(path_to_scan, path_to_exclude)
178
206
  files_count, removed_files_count = count_files(path_to_scan, path_to_exclude)
179
- cover.comment = f"Total number of files / removed files: {files_count} / {removed_files_count}"
207
+ scan_item.set_cover_comment(f"Total number of files / removed files: {files_count} / {removed_files_count}")
180
208
 
181
- if len(merged_result) == 0:
209
+ if not merged_result:
182
210
  if files_count < 1:
183
- cover.comment += "(No file detected.)"
211
+ scan_item.set_cover_comment("(No file detected.)")
184
212
  else:
185
- cover.comment += "(No OSS detected.)"
213
+ scan_item.set_cover_comment("(No OSS detected.)")
186
214
 
187
- sheet_list[SRC_SHEET_NAME] = []
188
215
  if merged_result:
189
- for scan_item in merged_result:
190
- for row in scan_item.get_row_to_print():
191
- sheet_list[SRC_SHEET_NAME].append(row)
216
+ sheet_list = {}
217
+ scan_item.append_file_items(merged_result, PKG_NAME)
192
218
 
193
219
  if selected_scanner == 'scanoss':
194
220
  extended_header = SCANOSS_HEADER
@@ -203,37 +229,40 @@ def create_report_file(_start_time, merged_result, license_list, scanoss_result,
203
229
  else:
204
230
  sheet_list["scancode_reference"] = get_license_list_to_print(license_list)
205
231
  sheet_list["scanoss_reference"] = get_scanoss_extra_info(scanoss_result)
232
+ if sheet_list:
233
+ scan_item.external_sheets = sheet_list
206
234
 
207
235
  if correct_mode:
208
- success, msg_correct, correct_list = correct_with_yaml(correct_filepath, path_to_scan, sheet_list)
236
+ success, msg_correct, correct_item = correct_with_yaml(correct_filepath, path_to_scan, scan_item)
209
237
  if not success:
210
238
  logger.info(f"No correction with yaml: {msg_correct}")
211
239
  else:
212
- sheet_list = correct_list
240
+ scan_item = correct_item
213
241
  logger.info("Success to correct with yaml.")
214
242
 
215
243
  combined_paths_and_files = [os.path.join(output_path, file) for file in output_files]
216
244
  results = []
217
- for combined_path_and_file, output_extension in zip(combined_paths_and_files, output_extensions):
218
- if need_license and output_extension == _json_ext and "scanoss_reference" in sheet_list:
219
- del sheet_list["scanoss_reference"]
220
- results.append(write_output_file(combined_path_and_file, output_extension, sheet_list, extended_header, "", cover))
245
+ for combined_path_and_file, output_extension, output_format in zip(combined_paths_and_files, output_extensions, formats):
246
+ # if need_license and output_extension == _json_ext and "scanoss_reference" in sheet_list:
247
+ # del sheet_list["scanoss_reference"]
248
+ results.append(write_output_file(combined_path_and_file, output_extension, scan_item, extended_header, "", output_format))
221
249
  for success, msg, result_file in results:
222
250
  if success:
223
251
  logger.info(f"Output file: {result_file}")
224
- if cover:
225
- logger.info(f'{cover.comment}')
252
+ for row in scan_item.get_cover_comment():
253
+ logger.info(row)
226
254
  else:
227
255
  logger.error(f"Fail to generate result file {result_file}. msg:({msg})")
256
+ return scan_item
228
257
 
229
258
 
230
- def merge_results(scancode_result=[], scanoss_result=[], spdx_downloads={}):
259
+ def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_downloads: dict = {}) -> list:
231
260
  """
232
261
  Merge scanner results and spdx parsing result.
233
- :param scancode_result: list of scancode results in ScanItem.
234
- :param scanoss_result: list of scanoss results in ScanItem.
262
+ :param scancode_result: list of scancode results in SourceItem.
263
+ :param scanoss_result: list of scanoss results in SourceItem.
235
264
  :param spdx_downloads: dictionary of spdx parsed results.
236
- :return merged_result: list of merged result in ScanItem.
265
+ :return merged_result: list of merged result in SourceItem.
237
266
  """
238
267
 
239
268
  # If anything that is found at SCANOSS only exist, add it to result.
@@ -247,15 +276,24 @@ def merge_results(scancode_result=[], scanoss_result=[], spdx_downloads={}):
247
276
  merged_result_item = scancode_result[scancode_result.index(file_name)]
248
277
  merged_result_item.download_location = download_location
249
278
  else:
250
- new_result_item = ScanItem(file_name)
279
+ new_result_item = SourceItem(file_name)
251
280
  new_result_item.download_location = download_location
252
281
  scancode_result.append(new_result_item)
282
+
283
+ for item in scancode_result:
284
+ item.set_oss_item()
285
+
253
286
  return scancode_result
254
287
 
255
288
 
256
- def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_cores=-1, called_by_cli=True,
257
- print_matched_text=False, formats=[], time_out=120, correct_mode=True, correct_filepath="",
258
- selected_scanner='all', path_to_exclude=[]):
289
+ def run_scanners(
290
+ path_to_scan: str, output_file_name: str = "",
291
+ write_json_file: bool = False, num_cores: int = -1,
292
+ called_by_cli: bool = True, print_matched_text: bool = False,
293
+ formats: list = [], time_out: int = 120,
294
+ correct_mode: bool = True, correct_filepath: str = "",
295
+ selected_scanner: str = 'all', path_to_exclude: list = []
296
+ ) -> Tuple[bool, str, 'ScannerItem', list, list]:
259
297
  """
260
298
  Run Scancode and scanoss.py for the given path.
261
299
 
@@ -280,11 +318,12 @@ def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_c
280
318
  license_list = []
281
319
  spdx_downloads = {}
282
320
  result_log = {}
321
+ scan_item = []
283
322
 
284
- success, msg, output_path, output_files, output_extensions = check_output_formats(output_file_name, formats)
323
+ success, msg, output_path, output_files, output_extensions, formats = check_output_formats_v2(output_file_name, formats)
285
324
 
286
325
  logger, result_log = init_log(os.path.join(output_path, f"fosslight_log_src_{start_time}.txt"),
287
- True, logging.INFO, logging.DEBUG, _PKG_NAME, path_to_scan, path_to_exclude)
326
+ True, logging.INFO, logging.DEBUG, PKG_NAME, path_to_scan, path_to_exclude)
288
327
 
289
328
  if '.xlsx' not in output_extensions and print_matched_text:
290
329
  logger.warning("-m option is only available for excel.")
@@ -302,9 +341,9 @@ def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_c
302
341
  if selected_scanner in SCANNER_TYPE:
303
342
  spdx_downloads = get_spdx_downloads(path_to_scan, path_to_exclude)
304
343
  merged_result = merge_results(scancode_result, scanoss_result, spdx_downloads)
305
- create_report_file(start_time, merged_result, license_list, scanoss_result, selected_scanner,
306
- print_matched_text, output_path, output_files, output_extensions, correct_mode,
307
- correct_filepath, path_to_scan, path_to_exclude)
344
+ scan_item = create_report_file(start_time, merged_result, license_list, scanoss_result, selected_scanner,
345
+ print_matched_text, output_path, output_files, output_extensions, correct_mode,
346
+ correct_filepath, path_to_scan, path_to_exclude, formats)
308
347
  else:
309
348
  print_help_msg_source_scanner()
310
349
  result_log[RESULT_KEY] = "Unsupported scanner"
@@ -312,7 +351,7 @@ def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_c
312
351
  else:
313
352
  result_log[RESULT_KEY] = f"Format error. {msg}"
314
353
  success = False
315
- return success, result_log.get(RESULT_KEY, ""), merged_result, license_list, scanoss_result
354
+ return success, result_log.get(RESULT_KEY, ""), scan_item, license_list, scanoss_result
316
355
 
317
356
 
318
357
  if __name__ == '__main__':
@@ -14,18 +14,23 @@ import fosslight_util.constant as constant
14
14
  from fosslight_util.set_log import init_log
15
15
  from ._parsing_scancode_file_item import parsing_file_item
16
16
  from ._parsing_scancode_file_item import get_error_from_header
17
- from ._license_matched import get_license_list_to_print
18
- from fosslight_util.output_format import check_output_formats
17
+ from fosslight_util.output_format import check_output_formats_v2
19
18
  from fosslight_binary.binary_analysis import check_binary
19
+ from typing import Tuple
20
20
 
21
21
  logger = logging.getLogger(constant.LOGGER_NAME)
22
22
  warnings.filterwarnings("ignore", category=FutureWarning)
23
23
  _PKG_NAME = "fosslight_source"
24
24
 
25
25
 
26
- def run_scan(path_to_scan, output_file_name="",
27
- _write_json_file=False, num_cores=-1, return_results=False, need_license=False, formats=[],
28
- called_by_cli=False, time_out=120, correct_mode=True, correct_filepath="", path_to_exclude=[]):
26
+ def run_scan(
27
+ path_to_scan: str, output_file_name: str = "",
28
+ _write_json_file: bool = False, num_cores: int = -1,
29
+ return_results: bool = False, need_license: bool = False,
30
+ formats: list = [], called_by_cli: bool = False,
31
+ time_out: int = 120, correct_mode: bool = True,
32
+ correct_filepath: str = "", path_to_exclude: list = []
33
+ ) -> Tuple[bool, str, list, list]:
29
34
  if not called_by_cli:
30
35
  global logger
31
36
 
@@ -41,7 +46,7 @@ def run_scan(path_to_scan, output_file_name="",
41
46
  if not correct_filepath:
42
47
  correct_filepath = path_to_scan
43
48
 
44
- success, msg, output_path, output_files, output_extensions = check_output_formats(output_file_name, formats)
49
+ success, msg, output_path, output_files, output_extensions, formats = check_output_formats_v2(output_file_name, formats)
45
50
  if success:
46
51
  if output_path == "": # if json output with _write_json_file not used, output_path won't be needed.
47
52
  output_path = os.getcwd()
@@ -100,13 +105,10 @@ def run_scan(path_to_scan, output_file_name="",
100
105
  output_json_pp=output_json_file, only_findings=True,
101
106
  license_text=True, url=True, timeout=time_out,
102
107
  include=(), ignore=tuple(total_files_to_excluded))
103
-
104
108
  if not rc:
105
109
  msg = "Source code analysis failed."
106
110
  success = False
107
-
108
111
  if results:
109
- sheet_list = {}
110
112
  has_error = False
111
113
  if "headers" in results:
112
114
  has_error, error_msg = get_error_from_header(results["headers"])
@@ -125,13 +127,8 @@ def run_scan(path_to_scan, output_file_name="",
125
127
  result_list, key=lambda row: (''.join(row.licenses)))
126
128
 
127
129
  for scan_item in result_list:
128
- if check_binary(os.path.join(path_to_scan, scan_item.file)):
130
+ if check_binary(os.path.join(path_to_scan, scan_item.source_name_or_path)):
129
131
  scan_item.exclude = True
130
-
131
- sheet_list["SRC_FL_Source"] = [scan_item.get_row_to_print() for scan_item in result_list]
132
- if need_license:
133
- sheet_list["matched_text"] = get_license_list_to_print(license_list)
134
-
135
132
  except Exception as ex:
136
133
  success = False
137
134
  msg = str(ex)
@@ -11,7 +11,7 @@ import json
11
11
  from datetime import datetime
12
12
  import fosslight_util.constant as constant
13
13
  from fosslight_util.set_log import init_log
14
- from fosslight_util.output_format import check_output_formats # , write_output_file
14
+ from fosslight_util.output_format import check_output_formats_v2 # , write_output_file
15
15
  from ._parsing_scanoss_file import parsing_scanResult # scanoss
16
16
  from ._parsing_scanoss_file import parsing_extraInfo # scanoss
17
17
  import shutil
@@ -25,12 +25,12 @@ SCANOSS_RESULT_FILE = "scanner_output.wfp"
25
25
  SCANOSS_OUTPUT_FILE = "scanoss_raw_result.json"
26
26
 
27
27
 
28
- def get_scanoss_extra_info(scanned_result):
28
+ def get_scanoss_extra_info(scanned_result: dict) -> list:
29
29
  return parsing_extraInfo(scanned_result)
30
30
 
31
31
 
32
- def run_scanoss_py(path_to_scan, output_file_name="", format="", called_by_cli=False,
33
- write_json_file=False, num_threads=-1, path_to_exclude=[]):
32
+ def run_scanoss_py(path_to_scan: str, output_file_name: str = "", format: list = [], called_by_cli: bool = False,
33
+ write_json_file: bool = False, num_threads: int = -1, path_to_exclude: list = []) -> list:
34
34
  """
35
35
  Run scanoss.py for the given path.
36
36
 
@@ -41,7 +41,7 @@ def run_scanoss_py(path_to_scan, output_file_name="", format="", called_by_cli=F
41
41
  :param write_json_file: if requested, keep the raw files.
42
42
  :return scanoss_file_list: list of ScanItem (scanned result by files).
43
43
  """
44
- success, msg, output_path, output_files, output_extensions = check_output_formats(output_file_name, format)
44
+ success, msg, output_path, output_files, output_extensions, formats = check_output_formats_v2(output_file_name, format)
45
45
 
46
46
  if not called_by_cli:
47
47
  global logger
@@ -12,7 +12,7 @@ import mmap
12
12
  logger = logging.getLogger(constant.LOGGER_NAME)
13
13
 
14
14
 
15
- def get_file_list(path_to_scan, path_to_exclude=[]):
15
+ def get_file_list(path_to_scan: str, path_to_exclude: list = []) -> list:
16
16
  file_list = []
17
17
  abs_path_to_exclude = [os.path.abspath(os.path.join(path_to_scan, path)) for path in path_to_exclude]
18
18
  for root, dirs, files in os.walk(path_to_scan):
@@ -26,7 +26,7 @@ def get_file_list(path_to_scan, path_to_exclude=[]):
26
26
  return file_list
27
27
 
28
28
 
29
- def get_spdx_downloads(path_to_scan, path_to_exclude=[]):
29
+ def get_spdx_downloads(path_to_scan: str, path_to_exclude: list = []) -> dict:
30
30
  download_dict = {}
31
31
  find_word = re.compile(rb"SPDX-PackageDownloadLocation\s*:\s*(\S+)", re.IGNORECASE)
32
32
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight-source
3
- Version: 1.7.16
3
+ Version: 2.1.0
4
4
  Summary: FOSSLight Source Scanner
5
5
  Home-page: https://github.com/fosslight/fosslight_source_scanner
6
6
  Author: LG Electronics
@@ -16,14 +16,14 @@ Classifier: Programming Language :: Python :: 3.11
16
16
  Requires-Python: >=3.8
17
17
  Description-Content-Type: text/markdown
18
18
  Requires-Dist: pyparsing
19
- Requires-Dist: scancode-toolkit==32.0.*,>=32.0.2
19
+ Requires-Dist: scancode-toolkit>=32.2.0
20
20
  Requires-Dist: scanoss
21
21
  Requires-Dist: XlsxWriter
22
- Requires-Dist: fosslight-util~=1.4.47
22
+ Requires-Dist: fosslight-util>=2.1.0
23
23
  Requires-Dist: PyYAML
24
24
  Requires-Dist: wheel>=0.38.1
25
25
  Requires-Dist: intbitset
26
- Requires-Dist: fosslight-binary
26
+ Requires-Dist: fosslight-binary>=5.0.0
27
27
  Requires-Dist: typecode-libmagic; sys_platform != "darwin"
28
28
 
29
29
  <!--
@@ -0,0 +1,16 @@
1
+ fosslight_source/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ fosslight_source/_help.py,sha256=q3eKABhBrz8hvWSvmLVszStNpL18TCYLnUuefaU4V-M,2013
3
+ fosslight_source/_license_matched.py,sha256=-3H881XQjFDafRttBsuboS3VbCPYEvPH1pwWXptknE4,2164
4
+ fosslight_source/_parsing_scancode_file_item.py,sha256=4U8wTuuNm-2-hanTxiQr2FvHTBrf2ZwESyea_E8caHU,13466
5
+ fosslight_source/_parsing_scanoss_file.py,sha256=Ss6BWTdT1Q43xTT9GBwL6XyzHT2p57ymVm04NL76Vbg,4506
6
+ fosslight_source/_scan_item.py,sha256=2RdnH5ZvrD7yjGxaHAIgSLmhq0dyW1379RScqPYJtOI,5679
7
+ fosslight_source/cli.py,sha256=ekeAOx6C3-MQxKU3415ZHx8R1Q_aRttnWp9d9b4TRxE,15522
8
+ fosslight_source/run_scancode.py,sha256=GRX1eSppx8d7OHm2VOv3wJBPzI6m5dY6DU8bgg8HCO4,7083
9
+ fosslight_source/run_scanoss.py,sha256=jTX_yfSc5-OhrVuejpoA97Y6n80dNE1L5dXTe0utNgM,5234
10
+ fosslight_source/run_spdx_extractor.py,sha256=Hr9sTv06cJaVITy8amwexIW2FV8_rUcFw6hKmR9ZYws,1990
11
+ fosslight_source-2.1.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
12
+ fosslight_source-2.1.0.dist-info/METADATA,sha256=OABbodeXRrCuqx6Gnn-Wyo8HVQI4iz17NTNpSAOUR7g,3314
13
+ fosslight_source-2.1.0.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
14
+ fosslight_source-2.1.0.dist-info/entry_points.txt,sha256=NzFURHC4L8uf1PmnZ2uGQcZxR7UbYCgjetb_9aPHV-w,114
15
+ fosslight_source-2.1.0.dist-info/top_level.txt,sha256=C2vw-0OIent84Vq-UEk1gt_kK1EL8dIItzBzp3WNyA4,17
16
+ fosslight_source-2.1.0.dist-info/RECORD,,
@@ -1,16 +0,0 @@
1
- fosslight_source/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- fosslight_source/_help.py,sha256=XODSRDGc2LYZsxYT-VOLHrkLLVipGd6BGS6K4C39c7A,1992
3
- fosslight_source/_license_matched.py,sha256=XdD1VErNKk4_ys_kIMNxwftEDwa3ONlgSjf44ti6hmE,2046
4
- fosslight_source/_parsing_scancode_file_item.py,sha256=87WI1aJmixQWQMrYRN0A7Q-cPxLJqdMkvJiz6xu9Zoc,13237
5
- fosslight_source/_parsing_scanoss_file.py,sha256=RjiGv0g22KUeXWKwxnFoxIKcdUcrVXFRb_UCiN4OdhY,4390
6
- fosslight_source/_scan_item.py,sha256=rTpl6X4qL7pjVbkSG2LRsTsmhHEvpd30dpYc4ldyvbA,5427
7
- fosslight_source/cli.py,sha256=28xmXweT5OAiL3d9bKjePg2IKKqaJrIDQn2ehkgM3ms,13905
8
- fosslight_source/run_scancode.py,sha256=99vrFb9G9wlkRZwNipuTLZ7j-l5ucogSkgUVT8n0ucA,7267
9
- fosslight_source/run_scanoss.py,sha256=-Na96WLdU73_Mv6HIo2ex2U0cy4YDWMgbmG4eEnht3c,5146
10
- fosslight_source/run_spdx_extractor.py,sha256=nwPbb36cFcZsssdecp3lDHgtyM19nuFdiPxrVhtJ2bI,1948
11
- fosslight_source-1.7.16.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
12
- fosslight_source-1.7.16.dist-info/METADATA,sha256=dykrrD9GvQW_wfHHjNIAbc5oQwRuTbO3HfsbP2G6JCI,3318
13
- fosslight_source-1.7.16.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
14
- fosslight_source-1.7.16.dist-info/entry_points.txt,sha256=NzFURHC4L8uf1PmnZ2uGQcZxR7UbYCgjetb_9aPHV-w,114
15
- fosslight_source-1.7.16.dist-info/top_level.txt,sha256=C2vw-0OIent84Vq-UEk1gt_kK1EL8dIItzBzp3WNyA4,17
16
- fosslight_source-1.7.16.dist-info/RECORD,,