Skip to content

Commit 407a051

Browse files
authored
Merge pull request #9 from fosslight/develop
Return only the result when call it as a function
2 parents bc6d855 + 2d204fa commit 407a051

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
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.6',
17+
version='1.4.7',
1818
package_dir={"": "src"},
1919
packages=find_packages(where='src'),
2020
description='FOSSLight Source',
File renamed without changes.

src/fosslight_source/convert_scancode.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
import yaml
1717
from ._parsing_scancode_file_item import parsing_file_item
1818
from fosslight_util.write_excel import write_excel_and_csv
19-
from .help import print_help_msg_convert
19+
from ._help import print_help_msg_convert
2020

2121
logger = logging.getLogger(constant.LOGGER_NAME)
2222
_PKG_NAME = "fosslight_source"
23-
_ERROR_PREFIX = "* Error : "
2423

2524

2625
def convert_json_to_excel(scancode_json, excel_name):
@@ -52,40 +51,40 @@ def convert_json_to_excel(scancode_json, excel_name):
5251
file_list, key=lambda row: (''.join(row.licenses)))
5352
sheet_list["SRC_" + file_name] = [scan_item.get_row_to_print() for scan_item in file_list]
5453
except Exception as ex:
55-
pass
54+
logger.warning("Error parsing "+file+":"+str(ex))
5655

5756
success_to_write, writing_msg = write_excel_and_csv(excel_name, sheet_list)
58-
logger.warn("* Writing excel :"+str(success_to_write)+ " "+writing_msg)
57+
logger.info("Writing excel :"+str(success_to_write)+ " "+writing_msg)
5958
if success_to_write:
6059
_result_log["OSS Report"] = excel_name+".xlsx"
6160

6261
except Exception as ex:
6362
success = False
64-
msg = _ERROR_PREFIX+str(ex)
63+
logger.warning(str(ex))
6564

6665
scan_result_msg = str(success)+" "+msg
6766
_result_log["Scan Result"] = scan_result_msg.strip()
6867

6968
try:
7069
_str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True)
71-
logger.warn("\n"+_str_final_result_log)
70+
logger.info(_str_final_result_log)
7271
except Exception as ex:
73-
logger.warn(_ERROR_PREFIX+"Failed to print result log. "+ str(ex))
72+
logger.warning("Failed to print result log.: "+ str(ex))
7473

7574
return file_list
7675

7776

7877
def get_detected_licenses_from_scancode(scancode_json_file):
7978
file_list = []
8079
try:
81-
logger.warn("Start parsing " + scancode_json_file)
80+
logger.info("Start parsing " + scancode_json_file)
8281
with open(scancode_json_file, "r") as st_json:
8382
st_python = json.load(st_json)
8483
rc, file_list, msg= parsing_file_item(st_python["files"])
85-
logger.warn("|---"+msg)
84+
logger.info("|---"+msg)
8685
except Exception as error:
87-
logger.warn(_ERROR_PREFIX+"Parsing -"+str(error))
88-
logger.warn("|---Number of files detected: " + str(len(file_list)))
86+
logger.warning("Parsing "+scancode_json_file+":"+str(error))
87+
logger.info("|---Number of files detected: " + str(len(file_list)))
8988
return file_list
9089

9190

src/fosslight_source/run_scancode.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
from fosslight_util.timer_thread import TimerThread
2020
from ._parsing_scancode_file_item import parsing_file_item
2121
from fosslight_util.write_excel import write_excel_and_csv
22-
from .help import print_help_msg_source
22+
from ._help import print_help_msg_source
2323

2424
logger = logging.getLogger(constant.LOGGER_NAME)
2525
warnings.filterwarnings("ignore", category=FutureWarning)
2626
_PKG_NAME = "fosslight_source"
27-
_ERROR_PREFIX = "* Error : "
2827

2928

3029
def main():
@@ -99,7 +98,7 @@ def run_scan(path_to_scan, output_file_name="",
9998
output_json_pp=output_json_file,
10099
only_findings=True)
101100
if not rc:
102-
msg += _ERROR_PREFIX+"Source code analysis failed.\n"
101+
msg += "Source code analysis failed."
103102
success = False
104103
if results:
105104
sheet_list = {}
@@ -114,15 +113,16 @@ def run_scan(path_to_scan, output_file_name="",
114113

115114
success_to_write, writing_msg = write_excel_and_csv(
116115
output_file, sheet_list)
117-
logger.warn("* Writing excel :"+str(success_to_write)+ " "+writing_msg)
116+
logger.info("Writing excel :"+str(success_to_write)+ " "+writing_msg)
118117
if success_to_write:
119118
_result_log["OSS Report"] = output_file +".xlsx"
120119
except Exception as ex:
121120
success = False
122-
msg = _ERROR_PREFIX + str(ex)+"\n"
121+
msg = str(ex)
122+
logger.error("Analyze "+path_to_scan+":"+msg)
123123
else:
124124
success = False
125-
msg = _ERROR_PREFIX+"Check the path to scan. :" + path_to_scan+"\n"
125+
msg = "Check the path to scan. :" + path_to_scan
126126

127127
if not return_results:
128128
result_list = []
@@ -131,10 +131,10 @@ def run_scan(path_to_scan, output_file_name="",
131131
_result_log["Output Directory"] = output_dir
132132
try:
133133
_str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True)
134-
logger.warn("\n"+_str_final_result_log)
134+
logger.info(_str_final_result_log)
135135
except Exception as ex:
136-
logger.warn(_ERROR_PREFIX+"Failed to print result log. "+ str(ex))
137-
return success, _str_final_result_log, result_list
136+
logger.warning("Failed to print result log. "+ str(ex))
137+
return success, _result_log["Scan Result"], result_list
138138

139139

140140
if __name__ == '__main__':

0 commit comments

Comments
 (0)