Skip to content

Commit 2c642fb

Browse files
committed
Print message for error files
1 parent 2d204fa commit 2c642fb

File tree

13 files changed

+13233
-262
lines changed

13 files changed

+13233
-262
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: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,33 @@ 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+
if len(errors) > 0:
109+
has_error = True
110+
str_error = ",".join(errors)
111+
break
112+
except Exception as ex:
113+
logger.debug("error_parsing_header:"+str(ex))
114+
return has_error, str_error
115+
116+
117+
def parsing_file_item(scancode_file_list, has_error):
100118

101119
rc = True
102120
scancode_file_item = []
103121
msg ="TOTAL FILE COUNT: "+str(len(scancode_file_list))+"\n"
104122

105123
prev_dir = ""
106124
prev_dir_value = False
125+
107126
for file in scancode_file_list:
108127
try:
109128
is_binary = False
@@ -124,6 +143,14 @@ def parsing_file_item(scancode_file_list):
124143

125144
result_item = ScanCodeItem(file_path)
126145

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

@@ -174,10 +201,11 @@ def parsing_file_item(scancode_file_list):
174201

175202
if is_exclude_file(file_path, prev_dir, prev_dir_value):
176203
result_item.set_exclude(True)
177-
178204
scancode_file_item.append(result_item)
205+
179206
except Exception as ex:
180207
msg += "* Error Parsing item:"+str(ex)
181208
rc = False
209+
logger.debug(msg)
182210

183211
return rc, scancode_file_item, msg.strip()

src/fosslight_source/convert_scancode.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from fosslight_util.set_log import init_log
1515
from fosslight_util.set_log import init_log_item
1616
import yaml
17-
from ._parsing_scancode_file_item import parsing_file_item
17+
from ._parsing_scancode_file_item import parsing_file_item, get_error_from_header
1818
from fosslight_util.write_excel import write_excel_and_csv
1919
from ._help import print_help_msg_convert
2020

@@ -80,8 +80,11 @@ def get_detected_licenses_from_scancode(scancode_json_file):
8080
logger.info("Start parsing " + scancode_json_file)
8181
with open(scancode_json_file, "r") as st_json:
8282
st_python = json.load(st_json)
83-
rc, file_list, msg= parsing_file_item(st_python["files"])
83+
has_error, str_error = get_error_from_header(st_python["headers"])
84+
rc, file_list, msg= parsing_file_item(st_python["files"], has_error)
8485
logger.info("|---"+msg)
86+
if has_error:
87+
logger.info("|---Scan error:"+str_error)
8588
except Exception as error:
8689
logger.warning("Parsing "+scancode_json_file+":"+str(error))
8790
logger.info("|---Number of files detected: " + str(len(file_list)))

src/fosslight_source/run_scancode.py

Lines changed: 24 additions & 15 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

@@ -98,24 +99,32 @@ def run_scan(path_to_scan, output_file_name="",
9899
output_json_pp=output_json_file,
99100
only_findings=True)
100101
if not rc:
101-
msg += "Source code analysis failed."
102+
msg = "Source code analysis failed."
102103
success = False
103104
if results:
104105
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"
106+
has_error = False
107+
if len(results.keys()) > 0 and not success:
108+
success = True
109+
msg = "[Minor_error]"
110+
if "headers" in results:
111+
has_error, error_msg = get_error_from_header(results["headers"])
112+
if has_error:
113+
_result_log["Error_files"] = error_msg
114+
msg += "Failed to analyze :"+ error_msg
115+
if "files" in results:
116+
rc, result_list, parsing_msg = parsing_file_item(results["files"], has_error)
117+
_result_log["Parsing Log"] = parsing_msg
118+
if rc:
119+
result_list = sorted(
120+
result_list, key=lambda row: (''.join(row.licenses)))
121+
sheet_list["SRC"] = [scan_item.get_row_to_print() for scan_item in result_list]
122+
123+
success_to_write, writing_msg = write_excel_and_csv(
124+
output_file, sheet_list)
125+
logger.info("Writing excel :"+str(success_to_write)+ " "+writing_msg)
126+
if success_to_write:
127+
_result_log["OSS Report"] = output_file +".xlsx"
119128
except Exception as ex:
120129
success = False
121130
msg = str(ex)

0 commit comments

Comments
 (0)