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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ pyparsing<=3.0.4;python_full_version<"3.6.8"
scancode-toolkit==31.2.6
XlsxWriter
typecode-libmagic
fosslight_util>=1.4.0
fosslight_util>=1.4.24
PyYAML
wheel
4 changes: 3 additions & 1 deletion src/fosslight_source/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
-s <scanner>\t Select which scanner to be run (scancode, scanoss, all)
-j\t\t\t Generate raw result of scanners in json format
-t <float>\t\t Stop scancode scanning if scanning takes longer than a timeout in seconds.
-c <core>\t\t Select the number of cores to be scanned with ScanCode."""
-c <core>\t\t Select the number of cores to be scanned with ScanCode.
--no_correction\t Enter if you don't want to correct OSS information with sbom-info.yaml
--correct_fpath\t Path to the sbom-info.yaml file"""
Copy link
Contributor

@soimkim soimkim May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dd-jy , --correct_fpath <path>\t 로 변경 필요해보입니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soimkim
변경 필요한 사유가 있을까요? help 메시지 정렬과 동작에 이상 없어보여 문의드립니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<path> 를 입력하면 깃헙에서 뭔가 tag인지 안보이네요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#122 에 수정하였습니다~



def print_version(pkg_name):
Expand Down
28 changes: 24 additions & 4 deletions src/fosslight_source/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from ._help import print_version, print_help_msg_source_scanner
from ._license_matched import get_license_list_to_print
from fosslight_util.output_format import check_output_format, write_output_file
from fosslight_util.correct import correct_with_yaml
from .run_scancode import run_scan
from .run_scanoss import run_scanoss_py
from .run_scanoss import get_scanoss_extra_info
Expand Down Expand Up @@ -47,6 +48,8 @@ def main():
print_matched_text = False
format = ""
selected_scanner = ""
correct_mode = True
correct_filepath = os.getcwd()

scanned_result = []
license_list = []
Expand All @@ -64,6 +67,8 @@ def main():
parser.add_argument('-s', '--scanner', nargs=1, type=str, required=False, default='all')
parser.add_argument('-t', '--timeout', type=int, required=False, default=120)
parser.add_argument('-c', '--cores', type=int, required=False, default=-1)
parser.add_argument('--no_correction', action='store_true', required=False)
parser.add_argument('--correct_fpath', nargs=1, type=str, required=False)

args = parser.parse_args()

Expand All @@ -84,6 +89,10 @@ def main():
format = ''.join(args.format)
if args.scanner:
selected_scanner = ''.join(args.scanner)
if args.no_correction:
correct_mode = False
if args.correct_fpath:
correct_filepath = ''.join(args.correct_fpath)

time_out = args.timeout
core = args.cores
Expand All @@ -108,7 +117,8 @@ def main():
success, _result_log["Scan Result"], scanned_result, license_list = run_scan(path_to_scan, output_file_name,
write_json_file, core, True,
print_matched_text, format, True,
time_out)
time_out, correct_mode,
correct_filepath)
elif selected_scanner == 'scanoss':
scanned_result = run_scanoss_py(path_to_scan, output_file_name, format, True, write_json_file)
elif selected_scanner == 'all' or selected_scanner == '':
Expand All @@ -120,7 +130,7 @@ def main():
print_help_msg_source_scanner()
sys.exit(1)
create_report_file(_start_time, scanned_result, license_list, selected_scanner, print_matched_text,
output_path, output_file, output_extension)
output_path, output_file, output_extension, correct_mode, correct_filepath, path_to_scan)
try:
logger.info(yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True))
except Exception as ex:
Expand All @@ -131,7 +141,8 @@ def main():


def create_report_file(_start_time, scanned_result, license_list, selected_scanner, need_license=False,
output_path="", output_file="", output_extension=""):
output_path="", output_file="", output_extension="", correct_mode=True, correct_filepath="",
path_to_scan=""):
"""
Create report files for given scanned result.

Expand Down Expand Up @@ -178,6 +189,14 @@ def create_report_file(_start_time, scanned_result, license_list, selected_scann
sheet_list["scancode_reference"] = get_license_list_to_print(license_list)
sheet_list["scanoss_reference"] = get_scanoss_extra_info(scanned_result)

if correct_mode:
success, msg_correct, correct_list = correct_with_yaml(correct_filepath, path_to_scan, sheet_list)
if not success:
logger.info(f"No correction with yaml: {msg_correct}")
else:
sheet_list = correct_list
logger.info("Success to correct with yaml.")

output_file_without_ext = os.path.join(output_path, output_file)
success_to_write, writing_msg, result_file = write_output_file(output_file_without_ext, output_extension,
sheet_list, extended_header)
Expand Down Expand Up @@ -216,7 +235,8 @@ def run_all_scanners(path_to_scan, output_file_name="", _write_json_file=False,
success, _result_log["Scan Result"], scancode_result, license_list = run_scan(path_to_scan, output_file_name,
_write_json_file, num_cores,
True, need_license,
format, called_by_cli, time_out)
format, called_by_cli, time_out,
False, "")
scanoss_result = run_scanoss_py(path_to_scan, output_file_name, format, called_by_cli, _write_json_file)

for file_in_scancode_result in scancode_result:
Expand Down
12 changes: 10 additions & 2 deletions src/fosslight_source/run_scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ._parsing_scancode_file_item import get_error_from_header
from ._license_matched import get_license_list_to_print
from fosslight_util.output_format import check_output_format, write_output_file
from fosslight_util.correct import correct_with_yaml

logger = logging.getLogger(constant.LOGGER_NAME)
warnings.filterwarnings("ignore", category=FutureWarning)
Expand All @@ -24,7 +25,7 @@

def run_scan(path_to_scan, output_file_name="",
_write_json_file=False, num_cores=-1, return_results=False, need_license=False, format="",
called_by_cli=False, time_out=120):
called_by_cli=False, time_out=120, correct_mode=True, correct_filepath=""):
if not called_by_cli:
global logger

Expand Down Expand Up @@ -100,13 +101,20 @@ def run_scan(path_to_scan, output_file_name="",

output_file_without_ext = os.path.join(output_path, output_file)
if not called_by_cli:
if correct_mode:
success, msg_correct, correct_list = correct_with_yaml(correct_filepath,
path_to_scan, sheet_list)
if not success:
logger.info(f"No correction with yaml: {msg_correct}")
else:
sheet_list = correct_list
logger.info("Success to correct with yaml.")
success_to_write, writing_msg, result_file = write_output_file(output_file_without_ext,
output_extension, sheet_list)
if success_to_write:
logger.info(f"Writing Output file({result_file}, success:{success_to_write}")
else:
logger.error(f"Fail to generate result file. msg:({writing_msg})")

except Exception as ex:
success = False
msg = str(ex)
Expand Down