Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
tox
pytest
pytest-cov
pytest-flake8
17 changes: 10 additions & 7 deletions src/fosslight_source/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,32 @@
from fosslight_util.help import PrintHelpMsg

_HELP_MESSAGE_SOURCE = """
Usage: fosslight_source [option1] <arg1> [option2] <arg2>...
Usage: fosslight_source [option1] <arg1> [option2] <arg2>...

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.
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 <source_path>\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 <file_name>\t\t Output file name"""

_HELP_MESSAGE_CONVERT = """
Usage: fosslight_convert [option1] <arg1> [option2] <arg2>...
Usage: fosslight_convert [option1] <arg1> [option2] <arg2>...

FOSSLigtht_convert converts the result of executing ScanCode in json format into OSS Report format.

Options:
Mandatory
-p <path_dir>\t\t Path of ScanCode json files

Optional
-h\t\t\t\t Print help message
-o <file_name>\t\t Output file name"""
Expand All @@ -38,6 +40,7 @@ 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)
6 changes: 3 additions & 3 deletions src/fosslight_source/_parsing_scancode_file_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def get_error_from_header(header_item):
error_cnt = len(errors)
if error_cnt > 0:
has_error = True
str_error ='{}...({})'.format(errors[0], error_cnt)
str_error = '{}...({})'.format(errors[0], error_cnt)
break
except Exception as ex:
logger.debug("error_parsing_header:"+str(ex))
Expand All @@ -119,7 +119,7 @@ def parsing_file_item(scancode_file_list, has_error):

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

prev_dir = ""
prev_dir_value = False
Expand Down Expand Up @@ -147,7 +147,7 @@ def parsing_file_item(scancode_file_list, has_error):
if has_error and "scan_errors" in file:
error_msg = file["scan_errors"]
if len(error_msg) > 0:
logger.debug("test_msg"+file_path+":"+ str(error_msg))
logger.debug("test_msg" + file_path + ":" + str(error_msg))
result_item.set_comment(",".join(error_msg))
scancode_file_item.append(result_item)
continue
Expand Down
19 changes: 9 additions & 10 deletions src/fosslight_source/convert_scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os
import sys
import json
import platform
from datetime import datetime
import logging
import fosslight_util.constant as constant
Expand Down Expand Up @@ -51,12 +50,12 @@ 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.warning("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)
logger.info("Writing excel :" + str(success_to_write) + " " + writing_msg)
if success_to_write:
_result_log["OSS Report"] = excel_name+".xlsx"
_result_log["OSS Report"] = excel_name + ".xlsx"

except Exception as ex:
success = False
Expand All @@ -69,7 +68,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.warning("Failed to print result log.: "+ str(ex))
logger.warning("Failed to print result log.: " + str(ex))

return file_list

Expand All @@ -81,12 +80,12 @@ def get_detected_licenses_from_scancode(scancode_json_file):
with open(scancode_json_file, "r") as st_json:
st_python = json.load(st_json)
has_error, str_error = get_error_from_header(st_python["headers"])
rc, file_list, msg= parsing_file_item(st_python["files"], has_error)
rc, file_list, msg = parsing_file_item(st_python["files"], has_error)
logger.info("|---"+msg)
if has_error:
logger.info("|---Scan error:"+str_error)
except Exception as error:
logger.warning("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

Expand All @@ -108,8 +107,8 @@ def main():
path_to_find_bin = arg
elif opt == "-o":
output_file_name = arg
except Exception as error:
pass
except Exception:
print_help_msg_convert()

if output_file_name == "":
output_dir = os.getcwd()
Expand All @@ -118,7 +117,7 @@ def main():
oss_report_name = output_file_name
output_dir = os.path.dirname(os.path.abspath(output_file_name))

logger = init_log(os.path.join(output_dir, "fosslight_src_log_"+start_time+".txt"))
logger = init_log(os.path.join(output_dir, "fosslight_src_log_" + start_time + ".txt"))

convert_json_to_excel(path_to_find_bin, oss_report_name)

Expand Down
12 changes: 7 additions & 5 deletions src/fosslight_source/run_scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,19 @@ def run_scan(path_to_scan, output_file_name="",
processes=num_cores,
output_json_pp=output_json_file,
only_findings=True)

if not rc:
msg = "Source code analysis failed."
success = False

if results:
sheet_list = {}
has_error = False
if "headers" in results:
has_error, error_msg = get_error_from_header(results["headers"])
if has_error:
_result_log["Error_files"] = error_msg
msg = "Failed to analyze :"+ error_msg
msg = "Failed to analyze :" + error_msg
if "files" in results:
rc, result_list, parsing_msg = parsing_file_item(results["files"], has_error)
_result_log["Parsing Log"] = parsing_msg
Expand All @@ -121,13 +123,13 @@ def run_scan(path_to_scan, output_file_name="",

success_to_write, writing_msg = write_excel_and_csv(
output_file, sheet_list)
logger.info("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"
_result_log["OSS Report"] = output_file + ".xlsx"
except Exception as ex:
success = False
msg = str(ex)
logger.error("Analyze "+path_to_scan+":"+msg)
logger.error("Analyze " + path_to_scan + ":" + msg)
else:
success = False
msg = "Check the path to scan. :" + path_to_scan
Expand All @@ -142,7 +144,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.warning("Failed to print result log. "+ str(ex))
logger.warning("Failed to print result log. " + str(ex))
return success, _result_log["Scan Result"], result_list


Expand Down
4 changes: 0 additions & 4 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
# Copyright (c) 2020 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0

import getopt
import os
import sys
import json
from datetime import datetime
import logging
import fosslight_util.constant as constant
Expand All @@ -19,7 +16,6 @@
def main():
global logger

argv = sys.argv[1:]
path_to_find_bin = os.path.abspath("tests/test_files/test")
start_time = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
output_file_name = ""
Expand Down
11 changes: 11 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ install_command = pip install {opts} {packages}
basepython= python3.6
whitelist_externals = cat

[flake8]
max-line-length = 130
exclude = .tox/*

[pytest]
filterwarnings = ignore::DeprecationWarning

[testenv:test_run]
deps =
-r{toxinidir}/requirements-dev.txt

setenv =
PYTHONPATH=.

Expand All @@ -20,3 +30,4 @@ commands =
fosslight_convert -p test_scan/scan_result.json -o test_convert/convert_result
cat test_convert/convert_result.csv
python tests/cli_test.py
pytest -v --flake8