From b68da92348a897c1e2496913697021ad85475264 Mon Sep 17 00:00:00 2001 From: "Jaekwon.bang" Date: Fri, 14 May 2021 16:55:56 +0900 Subject: [PATCH 1/6] Change file name help.py -> _help.py --- src/fosslight_source/convert_scancode.py | 2 +- src/fosslight_source/help.py | 43 ------------------------ src/fosslight_source/run_scancode.py | 2 +- 3 files changed, 2 insertions(+), 45 deletions(-) delete mode 100644 src/fosslight_source/help.py diff --git a/src/fosslight_source/convert_scancode.py b/src/fosslight_source/convert_scancode.py index 7610e1d..611d32d 100755 --- a/src/fosslight_source/convert_scancode.py +++ b/src/fosslight_source/convert_scancode.py @@ -16,7 +16,7 @@ import yaml from ._parsing_scancode_file_item import parsing_file_item from fosslight_util.write_excel import write_excel_and_csv -from .help import print_help_msg_convert +from ._help import print_help_msg_convert logger = logging.getLogger(constant.LOGGER_NAME) _PKG_NAME = "fosslight_source" diff --git a/src/fosslight_source/help.py b/src/fosslight_source/help.py deleted file mode 100644 index 3899fd0..0000000 --- a/src/fosslight_source/help.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (c) 2021 LG Electronics Inc. -# SPDX-License-Identifier: Apache-2.0 -from fosslight_util.help import PrintHelpMsg - -_HELP_MESSAGE_SOURCE = """ - Usage: fosslight_source [option1] [option2] ... - - FOSSLight Source uses ScanCode, a source code scanner, to detect the copyright and license phrases contained in the file. - Some files (ex- build script), binary files, directory and files in specific directories (ex-test) are excluded from the result. - And removes words such as “-only” and “-old-style” from the license name to be printed. The output result is generated in Excel format. - - Options: - Mandatory - -p \t\t Path to analyze source - - Optional - -h\t\t\t\t Print help message - -j\t\t\t\t Generate additional result of executing ScanCode in json format - -o \t\t Output file name""" - -_HELP_MESSAGE_CONVERT = """ - Usage: fosslight_convert [option1] [option2] ... - - FOSSLigtht_convert converts the result of executing ScanCode in json format into OSS Report format. - - Options: - Mandatory - -p \t\t Path of ScanCode json files - - Optional - -h\t\t\t\t Print help message - -o \t\t Output file name""" - - -def print_help_msg_source(): - helpMsg = PrintHelpMsg(_HELP_MESSAGE_SOURCE) - helpMsg.print_help_msg(True) - -def print_help_msg_convert(): - helpMsg = PrintHelpMsg(_HELP_MESSAGE_CONVERT) - helpMsg.print_help_msg(True) diff --git a/src/fosslight_source/run_scancode.py b/src/fosslight_source/run_scancode.py index a624d64..c58a65e 100755 --- a/src/fosslight_source/run_scancode.py +++ b/src/fosslight_source/run_scancode.py @@ -19,7 +19,7 @@ from fosslight_util.timer_thread import TimerThread from ._parsing_scancode_file_item import parsing_file_item from fosslight_util.write_excel import write_excel_and_csv -from .help import print_help_msg_source +from ._help import print_help_msg_source logger = logging.getLogger(constant.LOGGER_NAME) warnings.filterwarnings("ignore", category=FutureWarning) From 1fdfe3ece0d2fc9b1b3997e1f1b5c5ebd0008160 Mon Sep 17 00:00:00 2001 From: Soim Kim Date: Sat, 15 May 2021 11:08:42 +0900 Subject: [PATCH 2/6] Add file for the help message --- src/fosslight_source/_help.py | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/fosslight_source/_help.py diff --git a/src/fosslight_source/_help.py b/src/fosslight_source/_help.py new file mode 100644 index 0000000..3899fd0 --- /dev/null +++ b/src/fosslight_source/_help.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 LG Electronics Inc. +# SPDX-License-Identifier: Apache-2.0 +from fosslight_util.help import PrintHelpMsg + +_HELP_MESSAGE_SOURCE = """ + Usage: fosslight_source [option1] [option2] ... + + FOSSLight Source uses ScanCode, a source code scanner, to detect the copyright and license phrases contained in the file. + Some files (ex- build script), binary files, directory and files in specific directories (ex-test) are excluded from the result. + And removes words such as “-only” and “-old-style” from the license name to be printed. The output result is generated in Excel format. + + Options: + Mandatory + -p \t\t Path to analyze source + + Optional + -h\t\t\t\t Print help message + -j\t\t\t\t Generate additional result of executing ScanCode in json format + -o \t\t Output file name""" + +_HELP_MESSAGE_CONVERT = """ + Usage: fosslight_convert [option1] [option2] ... + + FOSSLigtht_convert converts the result of executing ScanCode in json format into OSS Report format. + + Options: + Mandatory + -p \t\t Path of ScanCode json files + + Optional + -h\t\t\t\t Print help message + -o \t\t Output file name""" + + +def print_help_msg_source(): + helpMsg = PrintHelpMsg(_HELP_MESSAGE_SOURCE) + helpMsg.print_help_msg(True) + +def print_help_msg_convert(): + helpMsg = PrintHelpMsg(_HELP_MESSAGE_CONVERT) + helpMsg.print_help_msg(True) From 500699c2b73dee21ccef3c52085c9116b7b9c022 Mon Sep 17 00:00:00 2001 From: Soim Kim Date: Sat, 15 May 2021 11:52:10 +0900 Subject: [PATCH 3/6] Change log level by message --- src/fosslight_source/convert_scancode.py | 19 +++++++++---------- src/fosslight_source/run_scancode.py | 14 +++++++------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/fosslight_source/convert_scancode.py b/src/fosslight_source/convert_scancode.py index 611d32d..78ea208 100755 --- a/src/fosslight_source/convert_scancode.py +++ b/src/fosslight_source/convert_scancode.py @@ -20,7 +20,6 @@ logger = logging.getLogger(constant.LOGGER_NAME) _PKG_NAME = "fosslight_source" -_ERROR_PREFIX = "* Error : " def convert_json_to_excel(scancode_json, excel_name): @@ -52,25 +51,25 @@ def convert_json_to_excel(scancode_json, excel_name): file_list, key=lambda row: (''.join(row.licenses))) sheet_list["SRC_" + file_name] = [scan_item.get_row_to_print() for scan_item in file_list] except Exception as ex: - pass + logger.warn("Error parsing "+file+":"+str(ex)) success_to_write, writing_msg = write_excel_and_csv(excel_name, sheet_list) - logger.warn("* Writing excel :"+str(success_to_write)+ " "+writing_msg) + logger.info("Writing excel :"+str(success_to_write)+ " "+writing_msg) if success_to_write: _result_log["OSS Report"] = excel_name+".xlsx" except Exception as ex: success = False - msg = _ERROR_PREFIX+str(ex) + logger.warn(str(ex)) scan_result_msg = str(success)+" "+msg _result_log["Scan Result"] = scan_result_msg.strip() try: _str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True) - logger.warn("\n"+_str_final_result_log) + logger.info(_str_final_result_log) except Exception as ex: - logger.warn(_ERROR_PREFIX+"Failed to print result log. "+ str(ex)) + logger.warn("Failed to print result log.: "+ str(ex)) return file_list @@ -78,14 +77,14 @@ def convert_json_to_excel(scancode_json, excel_name): def get_detected_licenses_from_scancode(scancode_json_file): file_list = [] try: - logger.warn("Start parsing " + scancode_json_file) + logger.info("Start parsing " + scancode_json_file) with open(scancode_json_file, "r") as st_json: st_python = json.load(st_json) rc, file_list, msg= parsing_file_item(st_python["files"]) - logger.warn("|---"+msg) + logger.info("|---"+msg) except Exception as error: - logger.warn(_ERROR_PREFIX+"Parsing -"+str(error)) - logger.warn("|---Number of files detected: " + str(len(file_list))) + logger.warn("Parsing "+scancode_json_file+":"+str(error)) + logger.info("|---Number of files detected: " + str(len(file_list))) return file_list diff --git a/src/fosslight_source/run_scancode.py b/src/fosslight_source/run_scancode.py index c58a65e..2c49fe1 100755 --- a/src/fosslight_source/run_scancode.py +++ b/src/fosslight_source/run_scancode.py @@ -24,7 +24,6 @@ logger = logging.getLogger(constant.LOGGER_NAME) warnings.filterwarnings("ignore", category=FutureWarning) _PKG_NAME = "fosslight_source" -_ERROR_PREFIX = "* Error : " def main(): @@ -99,7 +98,7 @@ def run_scan(path_to_scan, output_file_name="", output_json_pp=output_json_file, only_findings=True) if not rc: - msg += _ERROR_PREFIX+"Source code analysis failed.\n" + msg += "Source code analysis failed." success = False if results: sheet_list = {} @@ -114,15 +113,16 @@ def run_scan(path_to_scan, output_file_name="", success_to_write, writing_msg = write_excel_and_csv( output_file, sheet_list) - logger.warn("* Writing excel :"+str(success_to_write)+ " "+writing_msg) + logger.info("Writing excel :"+str(success_to_write)+ " "+writing_msg) if success_to_write: _result_log["OSS Report"] = output_file +".xlsx" except Exception as ex: success = False - msg = _ERROR_PREFIX + str(ex)+"\n" + msg = str(ex) + logger.error("Analyze "+path_to_scan+":"+msg) else: success = False - msg = _ERROR_PREFIX+"Check the path to scan. :" + path_to_scan+"\n" + msg = "Check the path to scan. :" + path_to_scan if not return_results: result_list = [] @@ -131,9 +131,9 @@ def run_scan(path_to_scan, output_file_name="", _result_log["Output Directory"] = output_dir try: _str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True) - logger.warn("\n"+_str_final_result_log) + logger.info(_str_final_result_log) except Exception as ex: - logger.warn(_ERROR_PREFIX+"Failed to print result log. "+ str(ex)) + logger.warn("Failed to print result log. "+ str(ex)) return success, _str_final_result_log, result_list From 5063f418bb6ccbe4ff532b3bc01a8758bfa030d4 Mon Sep 17 00:00:00 2001 From: Soim Kim Date: Sat, 15 May 2021 11:53:50 +0900 Subject: [PATCH 4/6] Return only result when call it as function --- src/fosslight_source/run_scancode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fosslight_source/run_scancode.py b/src/fosslight_source/run_scancode.py index 2c49fe1..0895810 100755 --- a/src/fosslight_source/run_scancode.py +++ b/src/fosslight_source/run_scancode.py @@ -134,7 +134,7 @@ def run_scan(path_to_scan, output_file_name="", logger.info(_str_final_result_log) except Exception as ex: logger.warn("Failed to print result log. "+ str(ex)) - return success, _str_final_result_log, result_list + return success, _result_log["Scan Result"], result_list if __name__ == '__main__': From 32ecd7de40ded32a2b6d534d3ae17f5cf60eb3ef Mon Sep 17 00:00:00 2001 From: Soim Kim Date: Sat, 15 May 2021 11:57:11 +0900 Subject: [PATCH 5/6] Update version to 1.4.7 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 98951ad..26b3d88 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ if __name__ == "__main__": setup( name='fosslight_source', - version='1.4.6', + version='1.4.7', package_dir={"": "src"}, packages=find_packages(where='src'), description='FOSSLight Source', From 2d204fac6e29a7cd55158e9479962da280911891 Mon Sep 17 00:00:00 2001 From: Soim Kim Date: Sat, 15 May 2021 14:38:01 +0900 Subject: [PATCH 6/6] Replace logger.warn with logger.warning --- src/fosslight_source/convert_scancode.py | 8 ++++---- src/fosslight_source/run_scancode.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/fosslight_source/convert_scancode.py b/src/fosslight_source/convert_scancode.py index 78ea208..ef7ee21 100755 --- a/src/fosslight_source/convert_scancode.py +++ b/src/fosslight_source/convert_scancode.py @@ -51,7 +51,7 @@ def convert_json_to_excel(scancode_json, excel_name): file_list, key=lambda row: (''.join(row.licenses))) sheet_list["SRC_" + file_name] = [scan_item.get_row_to_print() for scan_item in file_list] except Exception as ex: - logger.warn("Error parsing "+file+":"+str(ex)) + logger.warning("Error parsing "+file+":"+str(ex)) success_to_write, writing_msg = write_excel_and_csv(excel_name, sheet_list) logger.info("Writing excel :"+str(success_to_write)+ " "+writing_msg) @@ -60,7 +60,7 @@ def convert_json_to_excel(scancode_json, excel_name): except Exception as ex: success = False - logger.warn(str(ex)) + logger.warning(str(ex)) scan_result_msg = str(success)+" "+msg _result_log["Scan Result"] = scan_result_msg.strip() @@ -69,7 +69,7 @@ def convert_json_to_excel(scancode_json, excel_name): _str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True) logger.info(_str_final_result_log) except Exception as ex: - logger.warn("Failed to print result log.: "+ str(ex)) + logger.warning("Failed to print result log.: "+ str(ex)) return file_list @@ -83,7 +83,7 @@ def get_detected_licenses_from_scancode(scancode_json_file): rc, file_list, msg= parsing_file_item(st_python["files"]) logger.info("|---"+msg) except Exception as error: - logger.warn("Parsing "+scancode_json_file+":"+str(error)) + logger.warning("Parsing "+scancode_json_file+":"+str(error)) logger.info("|---Number of files detected: " + str(len(file_list))) return file_list diff --git a/src/fosslight_source/run_scancode.py b/src/fosslight_source/run_scancode.py index 0895810..705e647 100755 --- a/src/fosslight_source/run_scancode.py +++ b/src/fosslight_source/run_scancode.py @@ -133,7 +133,7 @@ def run_scan(path_to_scan, output_file_name="", _str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True) logger.info(_str_final_result_log) except Exception as ex: - logger.warn("Failed to print result log. "+ str(ex)) + logger.warning("Failed to print result log. "+ str(ex)) return success, _result_log["Scan Result"], result_list