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
15 changes: 6 additions & 9 deletions src/fosslight_source/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ def main():
timer.setDaemon(True)
timer.start()

start_time = datetime.now().strftime('%Y%m%d_%H%M%S')
_start_time = datetime.now().strftime('%y%m%d_%H%M')
success, msg, output_path, output_file, output_extension = check_output_format(output_file_name, format)
if not success:
logger.error(f"Format error. {msg}")
sys.exit(1)
logger, _result_log = init_log(os.path.join(output_path, "fosslight_src_log_"+start_time+".txt"),
logger, _result_log = init_log(os.path.join(output_path, f"fosslight_log_{_start_time}.txt"),
True, logging.INFO, logging.DEBUG, _PKG_NAME, path_to_scan)

if os.path.isdir(path_to_scan):
Expand All @@ -107,7 +107,7 @@ def main():
else:
print_help_msg_source()
sys.exit(1)
create_report_file(start_time, scanned_result, license_list, selected_scanner, print_matched_text,
create_report_file(_start_time, scanned_result, license_list, selected_scanner, print_matched_text,
output_path, output_file, output_extension)
try:
logger.info(yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True))
Expand All @@ -118,7 +118,7 @@ def main():
sys.exit(1)


def create_report_file(start_time, scanned_result, license_list, selected_scanner, need_license=False,
def create_report_file(_start_time, scanned_result, license_list, selected_scanner, need_license=False,
output_path="", output_file="", output_extension=""):
"""
Create report files for given scanned result.
Expand All @@ -131,7 +131,6 @@ def create_report_file(start_time, scanned_result, license_list, selected_scanne
extended_header = {}
sheet_list = {}
_json_ext = ".json"
_yaml_ext = ".yaml"

if output_path == "":
output_path = os.getcwd()
Expand All @@ -140,11 +139,9 @@ def create_report_file(start_time, scanned_result, license_list, selected_scanne

if output_file == "":
if output_extension == _json_ext:
output_file = f"Opossum_input_{start_time}"
if output_extension == _yaml_ext:
output_file = f"fosslight-sbom-info_{start_time}"
output_file = f"fosslight_opossum_{_start_time}"
else:
output_file = f"FOSSLight-Report_{start_time}"
output_file = f"fosslight_report_{_start_time}"

if scanned_result:
scanned_result = sorted(scanned_result, key=lambda row: (''.join(row.licenses)))
Expand Down
6 changes: 3 additions & 3 deletions src/fosslight_source/convert_scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ def convert_json_to_output_report(scancode_json, output_file_name, need_license=

if output_file == "":
if output_extension == _json_ext:
output_file = "Opossum_input_" + start_time
output_file = "fosslight_opossum_" + start_time
else:
output_file = "FOSSLight-Report_" + start_time
output_file = "fosslight_report_" + start_time
else:
output_path = os.getcwd()

logger, result_log = init_log(os.path.join(output_path, "fosslight_src_log_" + start_time + ".txt"),
logger, result_log = init_log(os.path.join(output_path, "fosslight_log_" + start_time + ".txt"),
True, logging.INFO, logging.DEBUG, _PKG_NAME)
if not success:
logger.error("Fail to convert scancode: " + msg)
Expand Down
12 changes: 4 additions & 8 deletions src/fosslight_source/run_scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def run_scan(path_to_scan, output_file_name="",
result_list = []
license_list = []
_json_ext = ".json"
_yaml_ext = ".yaml"

start_time = datetime.now().strftime('%Y%m%d_%H%M%S')
_start_time = datetime.now().strftime('%y%m%d_%H%M')

success, msg, output_path, output_file, output_extension = check_output_format(output_file_name, format)
if success:
Expand All @@ -49,19 +47,17 @@ def run_scan(path_to_scan, output_file_name="",
if not called_by_cli:
if output_file == "":
if output_extension == _json_ext:
output_file = f"Opossum_input_{start_time}"
elif output_extension == _yaml_ext:
output_file = f"fosslight-sbom-info_{start_time}"
output_file = f"fosslight_opossum_{_start_time}"
else:
output_file = f"FOSSLight-Report_{start_time}"
output_file = f"fosslight_report_{_start_time}"

if _write_json_file:
output_json_file = os.path.join(output_path, "scancode_raw_result.json")
else:
output_json_file = ""

if not called_by_cli:
logger, _result_log = init_log(os.path.join(output_path, f"fosslight_src_log_{start_time}.txt"),
logger, _result_log = init_log(os.path.join(output_path, f"fosslight_log_{_start_time}.txt"),
True, logging.INFO, logging.DEBUG, _PKG_NAME, path_to_scan)

num_cores = multiprocessing.cpu_count() - 1 if num_cores < 0 else num_cores
Expand Down
4 changes: 2 additions & 2 deletions src/fosslight_source/run_scanoss.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def run_scanoss_py(path_to_scan, output_file_name="", format="", called_by_cli=F

if not called_by_cli:
global logger
start_time = datetime.now().strftime('%Y%m%d_%H%M%S')
logger, _result_log = init_log(os.path.join(output_path, f"fosslight_src_log_{start_time}.txt"),
_start_time = datetime.now().strftime('%y%m%d_%H%M')
logger, _result_log = init_log(os.path.join(output_path, f"fosslight_log_{_start_time}.txt"),
True, logging.INFO, logging.DEBUG, _PKG_NAME, path_to_scan)

scanoss_file_list = []
Expand Down
4 changes: 2 additions & 2 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ def main():
global logger

path_to_find_bin = os.path.abspath("tests/test_files/test")
start_time = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
_start_time = datetime.now().strftime('%y%m%d_%H%M')
output_file_name = ""

fosslight_report_name = "test_result_func_call/result"
output_dir = os.path.dirname(os.path.abspath(output_file_name))

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

ret = run_all_scanners(path_to_find_bin, fosslight_report_name, True, -1, True, "", False)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_files/run_scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ def run_scan(path_to_scan, output_file_name="",
result_list = []

_windows = platform.system() == "Windows"
start_time = datetime.now().strftime('%Y%m%d_%H%M%S')
_start_time = datetime.now().strftime('%y%m%d_%H%M')

if output_file_name == "":
output_file = f"FOSSLight-Report_{start_time}"
output_json_file = f"scancode_{start_time}"
output_file = f"fosslight_report_{_start_time}"
output_json_file = f"scancode_{_start_time}"
output_dir = os.getcwd()
else:
output_file = output_file_name
output_json_file = output_file_name
output_dir = os.path.dirname(os.path.abspath(output_file_name))

logger, _result_log = init_log(os.path.join(output_dir, f"fosslight_src_log_{start_time}.txt"),
logger, _result_log = init_log(os.path.join(output_dir, f"fosslight_log_{_start_time}.txt"),
True, logging.INFO, logging.DEBUG, _PKG_NAME, path_to_scan)

if path_to_scan == "":
Expand Down