fosslight-source 1.7.16__tar.gz → 2.0.0__tar.gz

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 (23) hide show
  1. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/PKG-INFO +1 -1
  2. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/requirements.txt +2 -2
  3. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/setup.py +1 -1
  4. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/src/fosslight_source/_parsing_scancode_file_item.py +3 -3
  5. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/src/fosslight_source/_parsing_scanoss_file.py +4 -4
  6. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/src/fosslight_source/_scan_item.py +33 -40
  7. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/src/fosslight_source/cli.py +36 -32
  8. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/src/fosslight_source/run_scancode.py +1 -10
  9. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/src/fosslight_source.egg-info/PKG-INFO +1 -1
  10. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/src/fosslight_source.egg-info/requires.txt +2 -2
  11. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/LICENSE +0 -0
  12. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/MANIFEST.in +0 -0
  13. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/README.md +0 -0
  14. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/setup.cfg +0 -0
  15. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/src/fosslight_source/__init__.py +0 -0
  16. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/src/fosslight_source/_help.py +0 -0
  17. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/src/fosslight_source/_license_matched.py +0 -0
  18. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/src/fosslight_source/run_scanoss.py +0 -0
  19. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/src/fosslight_source/run_spdx_extractor.py +0 -0
  20. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/src/fosslight_source.egg-info/SOURCES.txt +0 -0
  21. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/src/fosslight_source.egg-info/dependency_links.txt +0 -0
  22. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/src/fosslight_source.egg-info/entry_points.txt +0 -0
  23. {fosslight_source-1.7.16 → fosslight_source-2.0.0}/src/fosslight_source.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight_source
3
- Version: 1.7.16
3
+ Version: 2.0.0
4
4
  Summary: FOSSLight Source Scanner
5
5
  Home-page: https://github.com/fosslight/fosslight_source_scanner
6
6
  Author: LG Electronics
@@ -2,9 +2,9 @@ pyparsing
2
2
  scancode-toolkit>=32.0.2,==32.0.*
3
3
  scanoss
4
4
  XlsxWriter
5
- fosslight_util~=1.4.47
5
+ fosslight_util>=2.0.0
6
6
  PyYAML
7
7
  wheel>=0.38.1
8
8
  intbitset
9
- fosslight_binary
9
+ fosslight_binary>=5.0.0
10
10
  typecode-libmagic;sys_platform!="darwin"
@@ -14,7 +14,7 @@ with open('requirements.txt', 'r', 'utf-8') as f:
14
14
  if __name__ == "__main__":
15
15
  setup(
16
16
  name='fosslight_source',
17
- version='1.7.16',
17
+ version='2.0.0',
18
18
  package_dir={"": "src"},
19
19
  packages=find_packages(where='src'),
20
20
  description='FOSSLight Source Scanner',
@@ -8,7 +8,7 @@ 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
@@ -75,7 +75,7 @@ def parsing_scancode_32_earlier(scancode_file_list, has_error=False):
75
75
  licenses = file.get("licenses", [])
76
76
  copyright_list = file.get("copyrights", [])
77
77
 
78
- result_item = ScanItem(file_path)
78
+ result_item = SourceItem(file_path)
79
79
 
80
80
  if has_error and "scan_errors" in file:
81
81
  error_msg = file.get("scan_errors", [])
@@ -201,7 +201,7 @@ def parsing_scancode_32_later(scancode_file_list, has_error=False):
201
201
  if (not file_path) or is_binary or is_dir:
202
202
  continue
203
203
 
204
- result_item = ScanItem(file_path)
204
+ result_item = SourceItem(file_path)
205
205
 
206
206
  if has_error:
207
207
  error_msg = file.get("scan_errors", [])
@@ -6,7 +6,7 @@
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
12
 
@@ -22,14 +22,14 @@ def parsing_extraInfo(scanned_result):
22
22
  license_w_source = scan_item.scanoss_reference
23
23
  if scan_item.matched_lines:
24
24
  if license_w_source:
25
- extra_item = [scan_item.file, ','.join(license_w_source['component_declared']),
25
+ extra_item = [scan_item.source_name_or_path, ','.join(license_w_source['component_declared']),
26
26
  ','.join(license_w_source['file_spdx_tag']),
27
27
  ','.join(license_w_source['file_header']),
28
28
  ','.join(license_w_source['license_file']),
29
29
  ','.join(license_w_source['scancode']),
30
30
  scan_item.matched_lines, scan_item.fileURL]
31
31
  else:
32
- extra_item = [scan_item.file, '', '', '', '', '', scan_item.matched_lines, scan_item.fileURL]
32
+ extra_item = [scan_item.source_name_or_path, '', '', '', '', '', scan_item.matched_lines, scan_item.fileURL]
33
33
  scanoss_extra_info.append(extra_item)
34
34
  scanoss_extra_info.insert(0, SCANOSS_INFO_HEADER)
35
35
  return scanoss_extra_info
@@ -43,7 +43,7 @@ def parsing_scanResult(scanoss_report, path_to_scan="", path_to_exclude=[]):
43
43
  abs_file_path = os.path.abspath(os.path.join(path_to_scan, file_path))
44
44
  if any(os.path.commonpath([abs_file_path, exclude_path]) == exclude_path for exclude_path in abs_path_to_exclude):
45
45
  continue
46
- result_item = ScanItem(file_path)
46
+ result_item = SourceItem(file_path)
47
47
  if 'id' in findings[0]:
48
48
  if "none" == findings[0]['id']:
49
49
  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
10
11
 
11
12
  logger = logging.getLogger(constant.LOGGER_NAME)
12
13
  replace_word = ["-only", "-old-style", "-or-later", "licenseref-scancode-", "licenseref-"]
@@ -25,26 +26,21 @@ 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 = ""
29
+ class SourceItem(FileItem):
39
30
 
40
31
  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
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 = ""
48
44
 
49
45
  def __del__(self):
50
46
  pass
@@ -52,16 +48,6 @@ class ScanItem:
52
48
  def __hash__(self):
53
49
  return hash(self.file)
54
50
 
55
- @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
51
  @property
66
52
  def licenses(self):
67
53
  return self._licenses
@@ -84,27 +70,34 @@ class ScanItem:
84
70
  if max_length_exceed and (SUBSTRING_LICENSE_COMMENT not in self.comment):
85
71
  self.comment = f"{self.comment}/ {SUBSTRING_LICENSE_COMMENT}" if self.comment else SUBSTRING_LICENSE_COMMENT
86
72
 
87
- def get_file(self):
88
- return self.file
73
+ def set_oss_item(self):
74
+ self.oss_items = []
75
+ if self.download_location:
76
+ for url in self.download_location:
77
+ item = OssItem(self.oss_name, self.oss_version, self.licenses, url)
78
+ item.copyright = "\n".join(self.copyright)
79
+ item.comment = self.comment
80
+ self.oss_items.append(item)
81
+ else:
82
+ item = OssItem(self.oss_name, self.oss_version, self.licenses)
83
+ item.copyright = "\n".join(self.copyright)
84
+ item.comment = self.comment
85
+ self.oss_items.append(item)
89
86
 
90
- def get_row_to_print(self):
87
+ def get_print_array(self):
91
88
  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,
89
+ for item in self.oss_items:
90
+ print_rows.append([self.source_name_or_path, item.name, item.version, ",".join(item.license),
91
+ item.download_location, "",
92
+ item.copyright, "Exclude" if self.exclude else "", item.comment,
95
93
  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
94
  return print_rows
102
95
 
103
96
  def __eq__(self, other):
104
97
  if type(other) == str:
105
- return self.file == other
98
+ return self.source_name_or_path == other
106
99
  else:
107
- return self.file == other.file
100
+ return self.source_name_or_path == other.source_name_or_path
108
101
 
109
102
 
110
103
  def is_exclude_dir(dir_path):
@@ -21,8 +21,8 @@ from .run_scanoss import get_scanoss_extra_info
21
21
  import yaml
22
22
  import argparse
23
23
  from .run_spdx_extractor import get_spdx_downloads
24
- from ._scan_item import ScanItem
25
- from fosslight_util.cover import CoverItem
24
+ from ._scan_item import SourceItem
25
+ from fosslight_util.oss_item import ScannerItem
26
26
 
27
27
  SRC_SHEET_NAME = 'SRC_FL_Source'
28
28
  SCANOSS_HEADER = {SRC_SHEET_NAME: ['ID', 'Source Path', 'OSS Name',
@@ -35,7 +35,7 @@ SCANNER_TYPE = ['scancode', 'scanoss', 'all', '']
35
35
 
36
36
  logger = logging.getLogger(constant.LOGGER_NAME)
37
37
  warnings.filterwarnings("ignore", category=FutureWarning)
38
- _PKG_NAME = "fosslight_source"
38
+ PKG_NAME = "fosslight_source"
39
39
  RESULT_KEY = "Scan Result"
40
40
 
41
41
 
@@ -75,7 +75,7 @@ def main():
75
75
  if args.help:
76
76
  print_help_msg_source_scanner()
77
77
  if args.version:
78
- print_version(_PKG_NAME)
78
+ print_version(PKG_NAME)
79
79
  if not args.path:
80
80
  path_to_scan = os.getcwd()
81
81
  else:
@@ -171,24 +171,21 @@ def create_report_file(_start_time, merged_result, license_list, scanoss_result,
171
171
 
172
172
  if not correct_filepath:
173
173
  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)
174
+
175
+ scan_item = ScannerItem(PKG_NAME, _start_time)
176
+ scan_item.set_cover_pathinfo(path_to_scan, path_to_exclude)
178
177
  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}"
178
+ scan_item.set_cover_comment(f"Total number of files / removed files: {files_count} / {removed_files_count}")
180
179
 
181
- if len(merged_result) == 0:
180
+ if not merged_result:
182
181
  if files_count < 1:
183
- cover.comment += "(No file detected.)"
182
+ scan_item.set_cover_comment("(No file detected.)")
184
183
  else:
185
- cover.comment += "(No OSS detected.)"
184
+ scan_item.set_cover_comment("(No OSS detected.)")
186
185
 
187
- sheet_list[SRC_SHEET_NAME] = []
188
186
  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)
187
+ sheet_list = {}
188
+ scan_item.append_file_items(merged_result, PKG_NAME)
192
189
 
193
190
  if selected_scanner == 'scanoss':
194
191
  extended_header = SCANOSS_HEADER
@@ -203,37 +200,40 @@ def create_report_file(_start_time, merged_result, license_list, scanoss_result,
203
200
  else:
204
201
  sheet_list["scancode_reference"] = get_license_list_to_print(license_list)
205
202
  sheet_list["scanoss_reference"] = get_scanoss_extra_info(scanoss_result)
203
+ if sheet_list:
204
+ scan_item.external_sheets = sheet_list
206
205
 
207
206
  if correct_mode:
208
- success, msg_correct, correct_list = correct_with_yaml(correct_filepath, path_to_scan, sheet_list)
207
+ success, msg_correct, correct_item = correct_with_yaml(correct_filepath, path_to_scan, scan_item)
209
208
  if not success:
210
209
  logger.info(f"No correction with yaml: {msg_correct}")
211
210
  else:
212
- sheet_list = correct_list
211
+ scan_item = correct_item
213
212
  logger.info("Success to correct with yaml.")
214
213
 
215
214
  combined_paths_and_files = [os.path.join(output_path, file) for file in output_files]
216
215
  results = []
217
216
  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))
217
+ # if need_license and output_extension == _json_ext and "scanoss_reference" in sheet_list:
218
+ # del sheet_list["scanoss_reference"]
219
+ results.append(write_output_file(combined_path_and_file, output_extension, scan_item, extended_header, ""))
221
220
  for success, msg, result_file in results:
222
221
  if success:
223
222
  logger.info(f"Output file: {result_file}")
224
- if cover:
225
- logger.info(f'{cover.comment}')
223
+ for row in scan_item.get_cover_comment():
224
+ logger.info(row)
226
225
  else:
227
226
  logger.error(f"Fail to generate result file {result_file}. msg:({msg})")
227
+ return scan_item
228
228
 
229
229
 
230
230
  def merge_results(scancode_result=[], scanoss_result=[], spdx_downloads={}):
231
231
  """
232
232
  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.
233
+ :param scancode_result: list of scancode results in SourceItem.
234
+ :param scanoss_result: list of scanoss results in SourceItem.
235
235
  :param spdx_downloads: dictionary of spdx parsed results.
236
- :return merged_result: list of merged result in ScanItem.
236
+ :return merged_result: list of merged result in SourceItem.
237
237
  """
238
238
 
239
239
  # If anything that is found at SCANOSS only exist, add it to result.
@@ -247,9 +247,13 @@ def merge_results(scancode_result=[], scanoss_result=[], spdx_downloads={}):
247
247
  merged_result_item = scancode_result[scancode_result.index(file_name)]
248
248
  merged_result_item.download_location = download_location
249
249
  else:
250
- new_result_item = ScanItem(file_name)
250
+ new_result_item = SourceItem(file_name)
251
251
  new_result_item.download_location = download_location
252
252
  scancode_result.append(new_result_item)
253
+
254
+ for item in scancode_result:
255
+ item.set_oss_item()
256
+
253
257
  return scancode_result
254
258
 
255
259
 
@@ -284,7 +288,7 @@ def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_c
284
288
  success, msg, output_path, output_files, output_extensions = check_output_formats(output_file_name, formats)
285
289
 
286
290
  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)
291
+ True, logging.INFO, logging.DEBUG, PKG_NAME, path_to_scan, path_to_exclude)
288
292
 
289
293
  if '.xlsx' not in output_extensions and print_matched_text:
290
294
  logger.warning("-m option is only available for excel.")
@@ -302,9 +306,9 @@ def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_c
302
306
  if selected_scanner in SCANNER_TYPE:
303
307
  spdx_downloads = get_spdx_downloads(path_to_scan, path_to_exclude)
304
308
  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)
309
+ scan_item = create_report_file(start_time, merged_result, license_list, scanoss_result, selected_scanner,
310
+ print_matched_text, output_path, output_files, output_extensions, correct_mode,
311
+ correct_filepath, path_to_scan, path_to_exclude)
308
312
  else:
309
313
  print_help_msg_source_scanner()
310
314
  result_log[RESULT_KEY] = "Unsupported scanner"
@@ -312,7 +316,7 @@ def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_c
312
316
  else:
313
317
  result_log[RESULT_KEY] = f"Format error. {msg}"
314
318
  success = False
315
- return success, result_log.get(RESULT_KEY, ""), merged_result, license_list, scanoss_result
319
+ return success, result_log.get(RESULT_KEY, ""), scan_item, license_list, scanoss_result
316
320
 
317
321
 
318
322
  if __name__ == '__main__':
@@ -14,7 +14,6 @@ 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
17
  from fosslight_util.output_format import check_output_formats
19
18
  from fosslight_binary.binary_analysis import check_binary
20
19
 
@@ -100,13 +99,10 @@ def run_scan(path_to_scan, output_file_name="",
100
99
  output_json_pp=output_json_file, only_findings=True,
101
100
  license_text=True, url=True, timeout=time_out,
102
101
  include=(), ignore=tuple(total_files_to_excluded))
103
-
104
102
  if not rc:
105
103
  msg = "Source code analysis failed."
106
104
  success = False
107
-
108
105
  if results:
109
- sheet_list = {}
110
106
  has_error = False
111
107
  if "headers" in results:
112
108
  has_error, error_msg = get_error_from_header(results["headers"])
@@ -125,13 +121,8 @@ def run_scan(path_to_scan, output_file_name="",
125
121
  result_list, key=lambda row: (''.join(row.licenses)))
126
122
 
127
123
  for scan_item in result_list:
128
- if check_binary(os.path.join(path_to_scan, scan_item.file)):
124
+ if check_binary(os.path.join(path_to_scan, scan_item.source_name_or_path)):
129
125
  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
126
  except Exception as ex:
136
127
  success = False
137
128
  msg = str(ex)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight-source
3
- Version: 1.7.16
3
+ Version: 2.0.0
4
4
  Summary: FOSSLight Source Scanner
5
5
  Home-page: https://github.com/fosslight/fosslight_source_scanner
6
6
  Author: LG Electronics
@@ -2,11 +2,11 @@ pyparsing
2
2
  scancode-toolkit==32.0.*,>=32.0.2
3
3
  scanoss
4
4
  XlsxWriter
5
- fosslight_util~=1.4.47
5
+ fosslight_util>=2.0.0
6
6
  PyYAML
7
7
  wheel>=0.38.1
8
8
  intbitset
9
- fosslight_binary
9
+ fosslight_binary>=5.0.0
10
10
 
11
11
  [:sys_platform != "darwin"]
12
12
  typecode-libmagic