Skip to content

Commit f52d4a8

Browse files
committed
Merge and Apply Flake8 again
2 parents 96c5cd0 + f933b1e commit f52d4a8

File tree

13 files changed

+13242
-268
lines changed

13 files changed

+13242
-268
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
if __name__ == "__main__":
1515
setup(
1616
name='fosslight_source',
17-
version='1.4.7',
17+
version='1.4.8',
1818
package_dir={"": "src"},
1919
packages=find_packages(where='src'),
2020
description='FOSSLight Source',

src/fosslight_source/_parsing_scancode_file_item.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,34 @@ def is_exclude_file(file_path, prev_dir, prev_dir_exclude_value):
9696
return False
9797

9898

99-
def parsing_file_item(scancode_file_list):
99+
def get_error_from_header(header_item):
100+
has_error = False
101+
str_error = ""
102+
key_error = "errors"
103+
104+
try:
105+
for header in header_item:
106+
if key_error in header:
107+
errors = header[key_error]
108+
error_cnt = len(errors)
109+
if error_cnt > 0:
110+
has_error = True
111+
str_error = '{}...({})'.format(errors[0], error_cnt)
112+
break
113+
except Exception as ex:
114+
logger.debug("error_parsing_header:"+str(ex))
115+
return has_error, str_error
116+
117+
118+
def parsing_file_item(scancode_file_list, has_error):
100119

101120
rc = True
102121
scancode_file_item = []
103122
msg = "TOTAL FILE COUNT: " + str(len(scancode_file_list)) + "\n"
104123

105124
prev_dir = ""
106125
prev_dir_value = False
126+
107127
for file in scancode_file_list:
108128
try:
109129
is_binary = False
@@ -124,6 +144,14 @@ def parsing_file_item(scancode_file_list):
124144

125145
result_item = ScanCodeItem(file_path)
126146

147+
if has_error and "scan_errors" in file:
148+
error_msg = file["scan_errors"]
149+
if len(error_msg) > 0:
150+
logger.debug("test_msg" + file_path + ":" + str(error_msg))
151+
result_item.set_comment(",".join(error_msg))
152+
scancode_file_item.append(result_item)
153+
continue
154+
127155
copyright_value_list = [x["value"] for x in copyright_list]
128156
result_item.set_copyright(copyright_value_list)
129157

@@ -174,10 +202,11 @@ def parsing_file_item(scancode_file_list):
174202

175203
if is_exclude_file(file_path, prev_dir, prev_dir_value):
176204
result_item.set_exclude(True)
177-
178205
scancode_file_item.append(result_item)
206+
179207
except Exception as ex:
180208
msg += "* Error Parsing item:"+str(ex)
181209
rc = False
210+
logger.debug(msg)
182211

183212
return rc, scancode_file_item, msg.strip()

src/fosslight_source/convert_scancode.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from fosslight_util.set_log import init_log
1414
from fosslight_util.set_log import init_log_item
1515
import yaml
16-
from ._parsing_scancode_file_item import parsing_file_item
16+
from ._parsing_scancode_file_item import parsing_file_item, get_error_from_header
1717
from fosslight_util.write_excel import write_excel_and_csv
1818
from ._help import print_help_msg_convert
1919

@@ -61,8 +61,8 @@ def convert_json_to_excel(scancode_json, excel_name):
6161
success = False
6262
logger.warning(str(ex))
6363

64-
scan_result_msg = str(success) + " " + msg
65-
_result_log["Scan Result"] = scan_result_msg.strip()
64+
scan_result_msg = str(success) if msg == "" else str(success) + "," + msg
65+
_result_log["Scan Result"] = scan_result_msg
6666

6767
try:
6868
_str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True)
@@ -79,8 +79,11 @@ def get_detected_licenses_from_scancode(scancode_json_file):
7979
logger.info("Start parsing " + scancode_json_file)
8080
with open(scancode_json_file, "r") as st_json:
8181
st_python = json.load(st_json)
82-
rc, file_list, msg = parsing_file_item(st_python["files"])
83-
logger.info("|---" + msg)
82+
has_error, str_error = get_error_from_header(st_python["headers"])
83+
rc, file_list, msg = parsing_file_item(st_python["files"], has_error)
84+
logger.info("|---"+msg)
85+
if has_error:
86+
logger.info("|---Scan error:"+str_error)
8487
except Exception as error:
8588
logger.warning("Parsing " + scancode_json_file + ":" + str(error))
8689
logger.info("|---Number of files detected: " + str(len(file_list)))

src/fosslight_source/run_scancode.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from fosslight_util.set_log import init_log_item
1919
from fosslight_util.timer_thread import TimerThread
2020
from ._parsing_scancode_file_item import parsing_file_item
21+
from ._parsing_scancode_file_item import get_error_from_header
2122
from fosslight_util.write_excel import write_excel_and_csv
2223
from ._help import print_help_msg_source
2324

@@ -97,25 +98,34 @@ def run_scan(path_to_scan, output_file_name="",
9798
processes=num_cores,
9899
output_json_pp=output_json_file,
99100
only_findings=True)
101+
100102
if not rc:
101-
msg += "Source code analysis failed."
103+
msg = "Source code analysis failed."
102104
success = False
105+
103106
if results:
104107
sheet_list = {}
105-
for key, value in results.items():
106-
if key == "files":
107-
rc, result_list, parsing_msg = parsing_file_item(value)
108-
_result_log["Parsing Log"] = parsing_msg
109-
if rc:
110-
result_list = sorted(
111-
result_list, key=lambda row: (''.join(row.licenses)))
112-
sheet_list["SRC"] = [scan_item.get_row_to_print() for scan_item in result_list]
113-
114-
success_to_write, writing_msg = write_excel_and_csv(
115-
output_file, sheet_list)
116-
logger.info("Writing excel :" + str(success_to_write) + " " + writing_msg)
117-
if success_to_write:
118-
_result_log["OSS Report"] = output_file + ".xlsx"
108+
has_error = False
109+
if "headers" in results:
110+
has_error, error_msg = get_error_from_header(results["headers"])
111+
if has_error:
112+
_result_log["Error_files"] = error_msg
113+
msg = "Failed to analyze :" + error_msg
114+
if "files" in results:
115+
rc, result_list, parsing_msg = parsing_file_item(results["files"], has_error)
116+
_result_log["Parsing Log"] = parsing_msg
117+
if rc:
118+
if not success:
119+
success = True
120+
result_list = sorted(
121+
result_list, key=lambda row: (''.join(row.licenses)))
122+
sheet_list["SRC"] = [scan_item.get_row_to_print() for scan_item in result_list]
123+
124+
success_to_write, writing_msg = write_excel_and_csv(
125+
output_file, sheet_list)
126+
logger.info("Writing excel :" + str(success_to_write) + " " + writing_msg)
127+
if success_to_write:
128+
_result_log["OSS Report"] = output_file + ".xlsx"
119129
except Exception as ex:
120130
success = False
121131
msg = str(ex)
@@ -126,8 +136,9 @@ def run_scan(path_to_scan, output_file_name="",
126136

127137
if not return_results:
128138
result_list = []
129-
scan_result_msg = str(success) + " " + msg
130-
_result_log["Scan Result"] = scan_result_msg.strip()
139+
140+
scan_result_msg = str(success) if msg == "" else str(success) + "," + msg
141+
_result_log["Scan Result"] = scan_result_msg
131142
_result_log["Output Directory"] = output_dir
132143
try:
133144
_str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True)

0 commit comments

Comments
 (0)