Skip to content

Commit 7900f49

Browse files
authored
Merge pull request #10 from fosslight/develop
Print message for error items
2 parents 3eb09f4 + f933b1e commit 7900f49

File tree

13 files changed

+13238
-266
lines changed

13 files changed

+13238
-266
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: 7 additions & 4 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

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

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

6868
try:
6969
_str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True)
@@ -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: 26 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

@@ -98,24 +99,31 @@ 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 "headers" in results:
108+
has_error, error_msg = get_error_from_header(results["headers"])
109+
if has_error:
110+
_result_log["Error_files"] = error_msg
111+
msg = "Failed to analyze :"+ error_msg
112+
if "files" in results:
113+
rc, result_list, parsing_msg = parsing_file_item(results["files"], has_error)
114+
_result_log["Parsing Log"] = parsing_msg
115+
if rc:
116+
if not success:
117+
success = True
118+
result_list = sorted(
119+
result_list, key=lambda row: (''.join(row.licenses)))
120+
sheet_list["SRC"] = [scan_item.get_row_to_print() for scan_item in result_list]
121+
122+
success_to_write, writing_msg = write_excel_and_csv(
123+
output_file, sheet_list)
124+
logger.info("Writing excel :"+str(success_to_write)+ " "+writing_msg)
125+
if success_to_write:
126+
_result_log["OSS Report"] = output_file +".xlsx"
119127
except Exception as ex:
120128
success = False
121129
msg = str(ex)
@@ -126,8 +134,9 @@ def run_scan(path_to_scan, output_file_name="",
126134

127135
if not return_results:
128136
result_list = []
129-
scan_result_msg = str(success)+" "+msg
130-
_result_log["Scan Result"] = scan_result_msg.strip()
137+
138+
scan_result_msg = str(success) if msg == "" else str(success) + "," + msg
139+
_result_log["Scan Result"] = scan_result_msg
131140
_result_log["Output Directory"] = output_dir
132141
try:
133142
_str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True)

0 commit comments

Comments
 (0)