fosslight-util 1.4.39__tar.gz → 1.4.41__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.
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/PKG-INFO +1 -1
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/setup.py +1 -1
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/correct.py +4 -3
- fosslight_util-1.4.41/src/fosslight_util/cover.py +44 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/download.py +2 -2
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/help.py +3 -1
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/oss_item.py +58 -11
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/output_format.py +15 -20
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/parsing_yaml.py +6 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/read_excel.py +4 -1
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/write_excel.py +71 -16
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/write_yaml.py +11 -6
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util.egg-info/PKG-INFO +1 -1
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util.egg-info/SOURCES.txt +1 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/LICENSE +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/MANIFEST.in +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/README.md +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/requirements.txt +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/setup.cfg +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/__init__.py +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/_get_downloadable_url.py +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/compare_yaml.py +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/constant.py +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/convert_excel_to_yaml.py +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/resources/frequentLicenselist.json +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/resources/frequent_license_nick_list.json +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/resources/licenses.json +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/set_log.py +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/spdx_licenses.py +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/timer_thread.py +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/write_opossum.py +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/write_scancodejson.py +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/write_spdx.py +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util/write_txt.py +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util.egg-info/dependency_links.txt +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util.egg-info/entry_points.txt +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util.egg-info/requires.txt +0 -0
- {fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util.egg-info/top_level.txt +0 -0
|
@@ -48,12 +48,13 @@ def correct_with_yaml(correct_filepath, path_to_scan, scanner_oss_list):
|
|
|
48
48
|
if sheet_name not in constant.supported_sheet_and_scanner.keys():
|
|
49
49
|
continue
|
|
50
50
|
correct_contents = copy.deepcopy(sheet_contents)
|
|
51
|
+
scanner_name = constant.supported_sheet_and_scanner[sheet_name]
|
|
51
52
|
for idx, oss_raw_item in enumerate(sheet_contents):
|
|
52
53
|
if len(oss_raw_item) < 9:
|
|
53
54
|
logger.warning(f"sheet list is too short ({len(oss_raw_item)}): {oss_raw_item}")
|
|
54
55
|
continue
|
|
55
56
|
oss_item = OssItem('')
|
|
56
|
-
oss_item.set_sheet_item(oss_raw_item)
|
|
57
|
+
oss_item.set_sheet_item(oss_raw_item, scanner_name)
|
|
57
58
|
|
|
58
59
|
matched_yi = []
|
|
59
60
|
oss_rel_path = os.path.normpath(os.path.join(rel_path, oss_item.source_name_or_path[0]))
|
|
@@ -75,13 +76,13 @@ def correct_with_yaml(correct_filepath, path_to_scan, scanner_oss_list):
|
|
|
75
76
|
if matched_oss_item.comment:
|
|
76
77
|
matched_oss_item.comment += '/'
|
|
77
78
|
matched_oss_item.comment += 'Loaded from sbom-info.yaml'
|
|
78
|
-
matched_oss_array = matched_oss_item.get_print_array()[0]
|
|
79
|
+
matched_oss_array = matched_oss_item.get_print_array(scanner_name)[0]
|
|
79
80
|
correct_contents.append(matched_oss_array)
|
|
80
81
|
oss_item.exclude = True
|
|
81
82
|
if oss_item.comment:
|
|
82
83
|
oss_item.comment += '/'
|
|
83
84
|
oss_item.comment += 'Excluded by sbom-info.yaml'
|
|
84
|
-
correct_contents[idx] = oss_item.get_print_array()[0]
|
|
85
|
+
correct_contents[idx] = oss_item.get_print_array(scanner_name)[0]
|
|
85
86
|
|
|
86
87
|
if sheet_name == 'SRC_FL_Source':
|
|
87
88
|
for n_idx, ni in enumerate(matched_yaml):
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# Copyright (c) 2024 LG Electronics Inc.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
from fosslight_util.help import print_package_version
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class CoverItem:
|
|
12
|
+
tool_name_key = "Tool name"
|
|
13
|
+
tool_version_key = "Tool version"
|
|
14
|
+
start_time_key = "Start time"
|
|
15
|
+
python_ver_key = "Python version"
|
|
16
|
+
analyzed_path_key = "Analyzed path"
|
|
17
|
+
comment_key = "Comment"
|
|
18
|
+
|
|
19
|
+
def __init__(self, tool_name="", start_time="", input_path="", comment=""):
|
|
20
|
+
self.tool_name = tool_name
|
|
21
|
+
if start_time:
|
|
22
|
+
date, time = start_time.split('_')
|
|
23
|
+
self.start_time = f'{date}, {time[0:2]}:{time[2:4]}'
|
|
24
|
+
else:
|
|
25
|
+
self.start_time = ""
|
|
26
|
+
self.input_path = os.path.abspath(input_path)
|
|
27
|
+
self.comment = comment
|
|
28
|
+
|
|
29
|
+
self.tool_version = print_package_version(self.tool_name, "", False)
|
|
30
|
+
self.python_version = f'{sys.version_info.major}.{sys.version_info.minor}'
|
|
31
|
+
|
|
32
|
+
def __del__(self):
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
def get_print_json(self):
|
|
36
|
+
json_item = {}
|
|
37
|
+
json_item[self.tool_name_key] = self.tool_name
|
|
38
|
+
json_item[self.tool_version_key] = self.tool_version
|
|
39
|
+
json_item[self.start_time_key] = self.start_time
|
|
40
|
+
json_item[self.python_ver_key] = self.python_version
|
|
41
|
+
json_item[self.analyzed_path_key] = self.input_path
|
|
42
|
+
json_item[self.comment_key] = self.comment
|
|
43
|
+
|
|
44
|
+
return json_item
|
|
@@ -62,7 +62,7 @@ def change_src_link_to_https(src_link):
|
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
def parse_src_link(src_link):
|
|
65
|
-
src_info = {}
|
|
65
|
+
src_info = {"url": src_link}
|
|
66
66
|
src_link_changed = ""
|
|
67
67
|
if src_link.startswith("git://") or src_link.startswith("https://") or src_link.startswith("http://"):
|
|
68
68
|
src_link_split = src_link.split(';')
|
|
@@ -79,7 +79,7 @@ def parse_src_link(src_link):
|
|
|
79
79
|
src_info["url"] = src_link_changed
|
|
80
80
|
src_info["branch"] = branch_info
|
|
81
81
|
src_info["tag"] = tag_info
|
|
82
|
-
|
|
82
|
+
return src_info
|
|
83
83
|
|
|
84
84
|
|
|
85
85
|
def main():
|
|
@@ -52,10 +52,12 @@ def print_package_version(pkg_name, msg="", exitopt=True):
|
|
|
52
52
|
if msg == "":
|
|
53
53
|
msg = f"{pkg_name} Version:"
|
|
54
54
|
cur_version = pkg_resources.get_distribution(pkg_name).version
|
|
55
|
-
print(f'{msg} {cur_version}')
|
|
56
55
|
|
|
57
56
|
if exitopt:
|
|
57
|
+
print(f'{msg} {cur_version}')
|
|
58
58
|
sys.exit(0)
|
|
59
|
+
else:
|
|
60
|
+
return cur_version
|
|
59
61
|
|
|
60
62
|
|
|
61
63
|
def print_help_msg_download(exitOpt=True):
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import logging
|
|
7
7
|
import os
|
|
8
|
-
from fosslight_util.constant import LOGGER_NAME
|
|
8
|
+
from fosslight_util.constant import LOGGER_NAME, FL_DEPENDENCY, FL_BINARY
|
|
9
9
|
|
|
10
10
|
_logger = logging.getLogger(LOGGER_NAME)
|
|
11
11
|
|
|
@@ -25,6 +25,11 @@ class OssItem:
|
|
|
25
25
|
self._yocto_recipe = []
|
|
26
26
|
self._yocto_package = []
|
|
27
27
|
self.is_binary = False
|
|
28
|
+
self._depends_on = []
|
|
29
|
+
self.purl = ""
|
|
30
|
+
self.bin_vulnerability = ""
|
|
31
|
+
self.bin_tlsh = ""
|
|
32
|
+
self.bin_sha1 = ""
|
|
28
33
|
|
|
29
34
|
def __del__(self):
|
|
30
35
|
pass
|
|
@@ -123,11 +128,29 @@ class OssItem:
|
|
|
123
128
|
self._yocto_package = [item.strip() for item in self._yocto_package]
|
|
124
129
|
self._yocto_package = list(set(self._yocto_package))
|
|
125
130
|
|
|
126
|
-
|
|
131
|
+
@property
|
|
132
|
+
def depends_on(self):
|
|
133
|
+
return self._depends_on
|
|
134
|
+
|
|
135
|
+
@depends_on.setter
|
|
136
|
+
def depends_on(self, value):
|
|
137
|
+
if not value:
|
|
138
|
+
self._depends_on = []
|
|
139
|
+
else:
|
|
140
|
+
if not isinstance(value, list):
|
|
141
|
+
value = value.split(",")
|
|
142
|
+
self._depends_on.extend(value)
|
|
143
|
+
self._depends_on = [item.strip() for item in self._depends_on]
|
|
144
|
+
self._depends_on = list(set(self._depends_on))
|
|
145
|
+
|
|
146
|
+
def set_sheet_item(self, item, scanner_name=''):
|
|
127
147
|
if len(item) < 9:
|
|
128
148
|
_logger.warning(f"sheet list is too short ({len(item)}): {item}")
|
|
129
149
|
return
|
|
130
|
-
|
|
150
|
+
if scanner_name == FL_DEPENDENCY:
|
|
151
|
+
self.purl = item[0]
|
|
152
|
+
else:
|
|
153
|
+
self.source_name_or_path = item[0]
|
|
131
154
|
self.name = item[1]
|
|
132
155
|
self.version = item[2]
|
|
133
156
|
self.license = item[3]
|
|
@@ -137,19 +160,39 @@ class OssItem:
|
|
|
137
160
|
self.exclude = item[7]
|
|
138
161
|
self.comment = item[8]
|
|
139
162
|
|
|
140
|
-
|
|
163
|
+
if len(item) >= 10 and scanner_name == FL_DEPENDENCY:
|
|
164
|
+
self.depends_on = item[9]
|
|
165
|
+
if len(item) >= 10 and scanner_name == FL_BINARY:
|
|
166
|
+
self.bin_vulnerability = item[9]
|
|
167
|
+
if len(item) >= 12:
|
|
168
|
+
self.bin_tlsh = item[10]
|
|
169
|
+
self.bin_sha1 = item[11]
|
|
170
|
+
|
|
171
|
+
def get_print_array(self, scanner_name=''):
|
|
141
172
|
items = []
|
|
142
|
-
if
|
|
143
|
-
self.source_name_or_path
|
|
173
|
+
if scanner_name != FL_DEPENDENCY:
|
|
174
|
+
if len(self.source_name_or_path) == 0:
|
|
175
|
+
self.source_name_or_path.append("")
|
|
144
176
|
if len(self.license) == 0:
|
|
145
177
|
self.license.append("")
|
|
146
178
|
|
|
147
179
|
exclude = "Exclude" if self.exclude else ""
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
180
|
+
lic = ",".join(self.license)
|
|
181
|
+
if scanner_name == FL_DEPENDENCY:
|
|
182
|
+
items = [self.purl, self.name, self.version, lic,
|
|
183
|
+
self.download_location, self.homepage, self.copyright, exclude, self.comment]
|
|
184
|
+
if len(self.depends_on) > 0:
|
|
185
|
+
items.append(",".join(self.depends_on))
|
|
186
|
+
else:
|
|
187
|
+
for source_name_or_path in self.source_name_or_path:
|
|
188
|
+
if scanner_name == FL_BINARY:
|
|
189
|
+
oss_item = [os.path.join(self.relative_path, source_name_or_path), self.name, self.version, lic,
|
|
190
|
+
self.download_location, self.homepage, self.copyright, exclude, self.comment,
|
|
191
|
+
self.bin_vulnerability, self.bin_tlsh, self.bin_sha1]
|
|
192
|
+
else:
|
|
193
|
+
oss_item = [os.path.join(self.relative_path, source_name_or_path), self.name, self.version, lic,
|
|
194
|
+
self.download_location, self.homepage, self.copyright, exclude, self.comment]
|
|
195
|
+
items.append(oss_item)
|
|
153
196
|
return items
|
|
154
197
|
|
|
155
198
|
def get_print_json(self):
|
|
@@ -171,6 +214,10 @@ class OssItem:
|
|
|
171
214
|
json_item["exclude"] = self.exclude
|
|
172
215
|
if self.comment != "":
|
|
173
216
|
json_item["comment"] = self.comment
|
|
217
|
+
if len(self.depends_on) > 0:
|
|
218
|
+
json_item["depends on"] = self.depends_on
|
|
219
|
+
if self.purl != "":
|
|
220
|
+
json_item["purl"] = self.purl
|
|
174
221
|
|
|
175
222
|
return json_item
|
|
176
223
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# Copyright (c) 2021 LG Electronics Inc.
|
|
4
4
|
# SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
import os
|
|
6
|
-
from fosslight_util.write_excel import write_result_to_excel, write_result_to_csv
|
|
6
|
+
from fosslight_util.write_excel import write_result_to_excel, write_result_to_csv
|
|
7
7
|
from fosslight_util.write_opossum import write_opossum
|
|
8
8
|
from fosslight_util.write_yaml import write_yaml
|
|
9
9
|
|
|
@@ -56,29 +56,24 @@ def check_output_format(output='', format='', customized_format={}):
|
|
|
56
56
|
return success, msg, output_path, output_file, output_extension
|
|
57
57
|
|
|
58
58
|
|
|
59
|
-
def write_output_file(output_file_without_ext, file_extension, sheet_list, extended_header={}, hide_header={}):
|
|
59
|
+
def write_output_file(output_file_without_ext, file_extension, sheet_list, extended_header={}, hide_header={}, cover=""):
|
|
60
60
|
success = True
|
|
61
61
|
msg = ''
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
file_extension = '.xlsx'
|
|
67
|
-
result_file = output_file_without_ext + file_extension
|
|
63
|
+
if file_extension == '':
|
|
64
|
+
file_extension = '.xlsx'
|
|
65
|
+
result_file = output_file_without_ext + file_extension
|
|
68
66
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
else:
|
|
78
|
-
success = False
|
|
79
|
-
msg = f'Not supported file extension({file_extension})'
|
|
67
|
+
if file_extension == '.xlsx':
|
|
68
|
+
success, msg = write_result_to_excel(result_file, sheet_list, extended_header, hide_header, cover)
|
|
69
|
+
elif file_extension == '.csv':
|
|
70
|
+
success, msg, result_file = write_result_to_csv(result_file, sheet_list)
|
|
71
|
+
elif file_extension == '.json':
|
|
72
|
+
success, msg = write_opossum(result_file, sheet_list)
|
|
73
|
+
elif file_extension == '.yaml':
|
|
74
|
+
success, msg, result_file = write_yaml(result_file, sheet_list, False)
|
|
80
75
|
else:
|
|
81
|
-
|
|
82
|
-
msg =
|
|
76
|
+
success = False
|
|
77
|
+
msg = f'Not supported file extension({file_extension})'
|
|
83
78
|
|
|
84
79
|
return success, msg, result_file
|
|
@@ -115,6 +115,12 @@ def set_value_switch(oss, key, value, yaml_file=""):
|
|
|
115
115
|
oss.yocto_package = value
|
|
116
116
|
elif key == 'yocto_recipe':
|
|
117
117
|
oss.yocto_recipe = value
|
|
118
|
+
elif key == 'vulnerability link':
|
|
119
|
+
oss.bin_vulnerability = value
|
|
120
|
+
elif key == 'tlsh':
|
|
121
|
+
oss.bin_tlsh = value
|
|
122
|
+
elif key == 'sha1':
|
|
123
|
+
oss.bin_sha1 = value
|
|
118
124
|
else:
|
|
119
125
|
if yaml_file != "":
|
|
120
126
|
_logger.debug(f"file:{yaml_file} - key:{key} cannot be parsed")
|
|
@@ -75,7 +75,10 @@ def read_oss_report(excel_file: str, sheet_names: str = "") -> List[OssItem]:
|
|
|
75
75
|
"Exclude": IDX_CANNOT_FOUND,
|
|
76
76
|
"Copyright Text": IDX_CANNOT_FOUND,
|
|
77
77
|
"Comment": IDX_CANNOT_FOUND,
|
|
78
|
-
"File Name or Path": IDX_CANNOT_FOUND
|
|
78
|
+
"File Name or Path": IDX_CANNOT_FOUND,
|
|
79
|
+
"Vulnerability Link": IDX_CANNOT_FOUND,
|
|
80
|
+
"TLSH": IDX_CANNOT_FOUND,
|
|
81
|
+
"SHA1": IDX_CANNOT_FOUND
|
|
79
82
|
}
|
|
80
83
|
num_cols = xl_sheet.ncols
|
|
81
84
|
num_rows = xl_sheet.nrows
|
|
@@ -13,6 +13,7 @@ import copy
|
|
|
13
13
|
from pathlib import Path
|
|
14
14
|
import fosslight_util.constant as constant
|
|
15
15
|
from jsonmerge import merge
|
|
16
|
+
from fosslight_util.cover import CoverItem
|
|
16
17
|
|
|
17
18
|
_HEADER = {'BIN (': ['ID', 'Binary Name', 'Source Code Path',
|
|
18
19
|
'NOTICE.html', 'OSS Name', 'OSS Version',
|
|
@@ -31,6 +32,7 @@ _EMPTY_ITEM_MSG = "* There is no item"\
|
|
|
31
32
|
IDX_FILE = 0
|
|
32
33
|
IDX_EXCLUDE = 7
|
|
33
34
|
logger = logging.getLogger(constant.LOGGER_NAME)
|
|
35
|
+
COVER_SHEET_NAME = 'Scanner Info'
|
|
34
36
|
|
|
35
37
|
|
|
36
38
|
def write_excel_and_csv(filename_without_extension, sheet_list, ignore_os=False, extended_header={}, hide_header={}):
|
|
@@ -105,9 +107,9 @@ def get_header_row(sheet_name, sheet_content, extended_header={}):
|
|
|
105
107
|
if sheet_name.startswith(header_key):
|
|
106
108
|
selected_header = merged_headers[header_key]
|
|
107
109
|
break
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
if len(sheet_content) > 0:
|
|
111
|
+
if not selected_header:
|
|
112
|
+
selected_header = sheet_content.pop(0)
|
|
111
113
|
return selected_header, sheet_content
|
|
112
114
|
|
|
113
115
|
|
|
@@ -166,16 +168,18 @@ def write_result_to_csv(output_file, sheet_list_origin, separate_sheet=False, ex
|
|
|
166
168
|
return success, error_msg, output
|
|
167
169
|
|
|
168
170
|
|
|
169
|
-
def write_result_to_excel(out_file_name, sheet_list, extended_header={}, hide_header={}):
|
|
171
|
+
def write_result_to_excel(out_file_name, sheet_list, extended_header={}, hide_header={}, cover=""):
|
|
170
172
|
success = True
|
|
171
173
|
error_msg = ""
|
|
172
174
|
|
|
173
175
|
try:
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
Path(output_dir).mkdir(parents=True, exist_ok=True)
|
|
176
|
+
output_dir = os.path.dirname(out_file_name)
|
|
177
|
+
Path(output_dir).mkdir(parents=True, exist_ok=True)
|
|
177
178
|
|
|
178
|
-
|
|
179
|
+
workbook = xlsxwriter.Workbook(out_file_name)
|
|
180
|
+
if cover:
|
|
181
|
+
write_cover_sheet(workbook, cover)
|
|
182
|
+
if sheet_list:
|
|
179
183
|
for sheet_name, sheet_contents in sheet_list.items():
|
|
180
184
|
selected_header, sheet_content_without_header = get_header_row(sheet_name, sheet_contents[:], extended_header)
|
|
181
185
|
try:
|
|
@@ -188,13 +192,33 @@ def write_result_to_excel(out_file_name, sheet_list, extended_header={}, hide_he
|
|
|
188
192
|
|
|
189
193
|
if hide_header:
|
|
190
194
|
hide_column(worksheet, selected_header, hide_header)
|
|
191
|
-
|
|
195
|
+
workbook.close()
|
|
192
196
|
except Exception as ex:
|
|
193
197
|
error_msg = str(ex)
|
|
194
198
|
success = False
|
|
195
199
|
return success, error_msg
|
|
196
200
|
|
|
197
201
|
|
|
202
|
+
def write_cover_sheet(workbook, cover):
|
|
203
|
+
worksheet = workbook.add_worksheet(COVER_SHEET_NAME)
|
|
204
|
+
|
|
205
|
+
format_bold = workbook.add_format({'bold': True})
|
|
206
|
+
worksheet.merge_range('A1:B1', 'About the scanner', format_bold)
|
|
207
|
+
|
|
208
|
+
key_format = workbook.add_format({'bold': True, 'font_color': 'white', 'bg_color': 'navy'})
|
|
209
|
+
item_format = workbook.add_format()
|
|
210
|
+
item_format.set_text_wrap()
|
|
211
|
+
|
|
212
|
+
cover_json = cover.get_print_json()
|
|
213
|
+
row = 1
|
|
214
|
+
for item in cover_json:
|
|
215
|
+
worksheet.write(row, 0, item, key_format)
|
|
216
|
+
worksheet.write(row, 1, cover_json[item], item_format)
|
|
217
|
+
row += 1
|
|
218
|
+
worksheet.set_column(0, 0, 30)
|
|
219
|
+
worksheet.set_column(1, 1, 100)
|
|
220
|
+
|
|
221
|
+
|
|
198
222
|
def write_result_to_sheet(worksheet, sheet_contents):
|
|
199
223
|
row = 1
|
|
200
224
|
for row_item in sheet_contents:
|
|
@@ -221,7 +245,33 @@ def create_worksheet(workbook, sheet_name, header_row):
|
|
|
221
245
|
return worksheet
|
|
222
246
|
|
|
223
247
|
|
|
224
|
-
def
|
|
248
|
+
def merge_cover_comment(find_excel_dir, merge_files=''):
|
|
249
|
+
FIND_EXTENSION = '.xlsx'
|
|
250
|
+
merge_comment = []
|
|
251
|
+
cover_comment = ''
|
|
252
|
+
try:
|
|
253
|
+
files = os.listdir(find_excel_dir)
|
|
254
|
+
|
|
255
|
+
if len([name for name in files if name.endswith(FIND_EXTENSION)]) > 0:
|
|
256
|
+
for file in files:
|
|
257
|
+
if merge_files:
|
|
258
|
+
if file not in merge_files:
|
|
259
|
+
continue
|
|
260
|
+
if file.endswith(FIND_EXTENSION):
|
|
261
|
+
file = os.path.join(find_excel_dir, file)
|
|
262
|
+
df_excel = pd.read_excel(file, sheet_name=COVER_SHEET_NAME, index_col=0, engine='openpyxl')
|
|
263
|
+
if not df_excel.empty:
|
|
264
|
+
tool_name = df_excel.loc[CoverItem.tool_name_key].values[0]
|
|
265
|
+
comment = df_excel.loc[CoverItem.comment_key].values[0]
|
|
266
|
+
merge_comment.append(str(f"[{tool_name}] {comment}"))
|
|
267
|
+
cover_comment = '\n'.join(merge_comment)
|
|
268
|
+
except Exception as ex:
|
|
269
|
+
logger.warning(f'Fail to merge comment of Scanner info: {str(ex)}')
|
|
270
|
+
|
|
271
|
+
return cover_comment
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def merge_excels(find_excel_dir, final_out, merge_files='', cover=''):
|
|
225
275
|
success = True
|
|
226
276
|
msg = ""
|
|
227
277
|
FIND_EXTENSION = '.xlsx'
|
|
@@ -231,7 +281,7 @@ def merge_excels(find_excel_dir, final_out, merge_files=''):
|
|
|
231
281
|
|
|
232
282
|
if len([name for name in files if name.endswith(FIND_EXTENSION)]) > 0:
|
|
233
283
|
writer = pd.ExcelWriter(final_out)
|
|
234
|
-
|
|
284
|
+
write_cover_sheet(writer.book, cover)
|
|
235
285
|
for file in files:
|
|
236
286
|
if merge_files:
|
|
237
287
|
if file not in merge_files:
|
|
@@ -243,13 +293,18 @@ def merge_excels(find_excel_dir, final_out, merge_files=''):
|
|
|
243
293
|
excel_file = pd.ExcelFile(file, engine='openpyxl')
|
|
244
294
|
|
|
245
295
|
for sheet_name in excel_file.sheet_names:
|
|
246
|
-
|
|
296
|
+
if sheet_name == COVER_SHEET_NAME:
|
|
297
|
+
continue
|
|
247
298
|
df_excel = pd.read_excel(
|
|
248
299
|
file, sheet_name=sheet_name, engine='openpyxl')
|
|
249
|
-
if sheet_name
|
|
250
|
-
|
|
251
|
-
df_excel.to_excel(writer,
|
|
252
|
-
|
|
300
|
+
if sheet_name in added_sheet_names:
|
|
301
|
+
sheet_name = f"{f_short_name}_{sheet_name}"
|
|
302
|
+
df_excel.to_excel(writer, sheet_name, index=False)
|
|
303
|
+
added_sheet_names.append(sheet_name)
|
|
304
|
+
|
|
305
|
+
if sheet_name == 'BIN_FL_Binary':
|
|
306
|
+
bin_sheet = writer.sheets[sheet_name]
|
|
307
|
+
bin_sheet.set_column("L:M", None, None, {"hidden": True}) # 'TLSH', 'SHA1' column hide
|
|
253
308
|
writer.close()
|
|
254
309
|
except Exception as ex:
|
|
255
310
|
msg = str(ex)
|
|
@@ -35,11 +35,16 @@ def write_yaml(output_file, sheet_list_origin, separate_yaml=False):
|
|
|
35
35
|
for sheet_name, sheet_contents in sheet_list.items():
|
|
36
36
|
if sheet_name not in constant.supported_sheet_and_scanner.keys():
|
|
37
37
|
continue
|
|
38
|
+
scanner_name = constant.supported_sheet_and_scanner[sheet_name]
|
|
39
|
+
sheet_contents_with_scanner = []
|
|
40
|
+
for i in sheet_contents:
|
|
41
|
+
i.insert(0, scanner_name)
|
|
42
|
+
sheet_contents_with_scanner.append(i)
|
|
38
43
|
if not separate_yaml:
|
|
39
|
-
merge_sheet.extend(
|
|
44
|
+
merge_sheet.extend(sheet_contents_with_scanner)
|
|
40
45
|
else:
|
|
41
46
|
output_file = f'{separate_output_file}_{sheet_name}.yaml'
|
|
42
|
-
convert_sheet_to_yaml(
|
|
47
|
+
convert_sheet_to_yaml(sheet_contents_with_scanner, output_file)
|
|
43
48
|
output_files.append(output_file)
|
|
44
49
|
|
|
45
50
|
if not separate_yaml:
|
|
@@ -61,13 +66,13 @@ def write_yaml(output_file, sheet_list_origin, separate_yaml=False):
|
|
|
61
66
|
return success, error_msg, output
|
|
62
67
|
|
|
63
68
|
|
|
64
|
-
def convert_sheet_to_yaml(
|
|
65
|
-
|
|
69
|
+
def convert_sheet_to_yaml(sheet_contents_with_scanner, output_file):
|
|
70
|
+
sheet_contents_with_scanner = [list(t) for t in set(tuple(e) for e in sorted(sheet_contents_with_scanner))]
|
|
66
71
|
|
|
67
72
|
yaml_dict = {}
|
|
68
|
-
for sheet_item in
|
|
73
|
+
for sheet_item in sheet_contents_with_scanner:
|
|
69
74
|
item = OssItem('')
|
|
70
|
-
item.set_sheet_item(sheet_item)
|
|
75
|
+
item.set_sheet_item(sheet_item[1:], sheet_item[0])
|
|
71
76
|
create_yaml_with_ossitem(item, yaml_dict)
|
|
72
77
|
|
|
73
78
|
with open(output_file, 'w') as f:
|
|
@@ -9,6 +9,7 @@ src/fosslight_util/compare_yaml.py
|
|
|
9
9
|
src/fosslight_util/constant.py
|
|
10
10
|
src/fosslight_util/convert_excel_to_yaml.py
|
|
11
11
|
src/fosslight_util/correct.py
|
|
12
|
+
src/fosslight_util/cover.py
|
|
12
13
|
src/fosslight_util/download.py
|
|
13
14
|
src/fosslight_util/help.py
|
|
14
15
|
src/fosslight_util/oss_item.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{fosslight_util-1.4.39 → fosslight_util-1.4.41}/src/fosslight_util.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|