Skip to content

Commit 469218c

Browse files
Amend how to handle path without files to scan for SCANOSS
1 parent 321a768 commit 469218c

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

src/fosslight_source/cli.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,26 @@ def main():
8585
logger, _result_log = init_log(os.path.join(output_path, "fosslight_src_log_"+start_time+".txt"),
8686
True, logging.INFO, logging.DEBUG, _PKG_NAME, path_to_scan)
8787

88-
if selected_scanner == 'scancode':
89-
success, _result_log["Scan Result"], scanned_result, license_list = run_scan(path_to_scan, output_file_name,
90-
write_json_file, -1, True,
91-
print_matched_text, format, True)
92-
elif selected_scanner == 'scanoss':
93-
scanned_result = run_scanoss_py(path_to_scan, output_file_name, format, True, write_json_file)
94-
elif selected_scanner == 'all' or selected_scanner == '':
95-
success, _result_log["Scan Result"], scanned_result, license_list = run_all_scanners(path_to_scan, output_file_name,
96-
write_json_file, -1,
97-
print_matched_text, format, True)
88+
if os.path.isdir(path_to_scan):
89+
90+
if selected_scanner == 'scancode':
91+
success, _result_log["Scan Result"], scanned_result, license_list = run_scan(path_to_scan, output_file_name,
92+
write_json_file, -1, True,
93+
print_matched_text, format, True)
94+
elif selected_scanner == 'scanoss':
95+
scanned_result = run_scanoss_py(path_to_scan, output_file_name, format, True, write_json_file)
96+
elif selected_scanner == 'all' or selected_scanner == '':
97+
success, _result_log["Scan Result"], scanned_result, license_list = run_all_scanners(path_to_scan, output_file_name,
98+
write_json_file, -1,
99+
print_matched_text, format, True)
100+
else:
101+
print_help_msg_source()
102+
sys.exit(1)
103+
create_report_file(start_time, scanned_result, license_list, selected_scanner, print_matched_text,
104+
output_path, output_file, output_extension)
98105
else:
99-
print_help_msg_source()
106+
logger.error(f"Check the path to scan. : {path_to_scan}")
100107
sys.exit(1)
101-
create_report_file(start_time, scanned_result, license_list, selected_scanner, print_matched_text,
102-
output_path, output_file, output_extension)
103108

104109

105110
def create_report_file(start_time, scanned_result, license_list, selected_scanner, need_license=False,

src/fosslight_source/run_scanoss.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from ._parsing_scanoss_file import parsing_extraInfo # scanoss
1717
import shutil
1818
from pathlib import Path
19+
import platform
20+
from ._help import print_help_msg_source
1921

2022
logger = logging.getLogger(constant.LOGGER_NAME)
2123
warnings.filterwarnings("ignore", category=FutureWarning)
@@ -41,12 +43,20 @@ def run_scanoss_py(path_to_scan, output_file_name="", format="", called_by_cli=F
4143
:return scanoss_file_list: list of ScanItem (scanned result by files).
4244
"""
4345
success, msg, output_path, output_file, output_extension = check_output_format(output_file_name, format)
46+
_windows = platform.system() == "Windows"
47+
4448
if not called_by_cli:
4549
global logger
4650
start_time = datetime.now().strftime('%Y%m%d_%H%M%S')
4751
logger, _result_log = init_log(os.path.join(output_path, f"fosslight_src_log_{start_time}.txt"),
4852
True, logging.INFO, logging.DEBUG, _PKG_NAME, path_to_scan)
4953

54+
if path_to_scan == "":
55+
if _windows:
56+
path_to_scan = os.getcwd()
57+
else:
58+
print_help_msg_source()
59+
5060
scanoss_file_list = []
5161
try:
5262
pkg_resources.get_distribution("scanoss")
@@ -76,7 +86,7 @@ def run_scanoss_py(path_to_scan, output_file_name="", format="", called_by_cli=F
7686
st_python = json.load(st_json)
7787
scanoss_file_list = parsing_scanResult(st_python)
7888
except Exception as error:
79-
logger.warning(f"SCANOSS Parsing {path_to_scan}: {error}")
89+
logger.debug(f"SCANOSS Parsing {path_to_scan}: {error}")
8090

8191
logger.info(f"|---Number of files detected with SCANOSS: {(len(scanoss_file_list))}")
8292

0 commit comments

Comments
 (0)