Skip to content

Commit 4336725

Browse files
Merge pull request #143 from fosslight/refactoring
Modify run_scanners to return
2 parents bbb26f0 + ef56d17 commit 4336725

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

.github/workflows/publish-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
- name: Set up Python
6161
uses: actions/setup-python@v4
6262
with:
63-
python-version: '3.7'
63+
python-version: '3.8'
6464
- name: Install dependencies
6565
run: |
6666
python -m pip install --upgrade pip

.github/workflows/pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
strategy:
1919
matrix:
20-
python-version: [3.7, 3.8]
20+
python-version: [3.8, 3.11]
2121
steps:
2222
- uses: actions/checkout@v3
2323
- name: Set up Python ${{ matrix.python-version }}

src/fosslight_source/cli.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
logger = logging.getLogger(constant.LOGGER_NAME)
3636
warnings.filterwarnings("ignore", category=FutureWarning)
3737
_PKG_NAME = "fosslight_source"
38+
RESULT_KEY = "Scan Result"
3839

3940

4041
def main():
@@ -218,60 +219,63 @@ def merge_results(scancode_result=[], scanoss_result=[], spdx_downloads={}):
218219
return scancode_result
219220

220221

221-
def run_scanners(path_to_scan, output_file_name="", _write_json_file=False, num_cores=-1, called_by_cli=True,
222+
def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_cores=-1, called_by_cli=True,
222223
print_matched_text=False, format="", time_out=120, correct_mode=True, correct_filepath="",
223224
selected_scanner='all'):
224225
"""
225226
Run Scancode and scanoss.py for the given path.
226227
227228
:param path_to_scan: path of sourcecode to scan.
228229
:param output_file_name: path or file name (with path) for the output.
229-
:param _write_json_file: if requested, keep the raw files.
230+
:param write_json_file: if requested, keep the raw files.
230231
:param num_cores: number of cores used for scancode scanning.
231232
:param called_by_cli: if not called by cli, initialize logger.
232233
:param print_matched_text: if requested, output matched text (only for scancode).
233234
:param format: output format (excel, csv, opossum).
234235
:return success: success or failure of scancode.
235-
:return _result_log["Scan Result"]:
236+
:return result_log["Scan Result"]:
236237
:return merged_result: merged scan result of scancode and scanoss.
237238
:return license_list: matched text.(only for scancode)
238239
"""
239240
global logger
240241

241-
_start_time = datetime.now().strftime('%y%m%d_%H%M')
242+
start_time = datetime.now().strftime('%y%m%d_%H%M')
242243
scancode_result = []
243244
scanoss_result = []
244245
merged_result = []
246+
license_list = []
245247
spdx_downloads = {}
248+
result_log = {}
246249

247250
success, msg, output_path, output_file, output_extension = check_output_format(output_file_name, format)
248-
if output_extension != '.xlsx' and output_extension != "" and print_matched_text:
251+
logger, result_log = init_log(os.path.join(output_path, f"fosslight_log_src_{start_time}.txt"),
252+
True, logging.INFO, logging.DEBUG, _PKG_NAME, path_to_scan)
253+
if output_extension != '.xlsx' and output_extension and print_matched_text:
249254
logger.warning("-m option is only available for excel.")
250255
print_matched_text = False
251-
if not success:
252-
logger.error(f"Format error. {msg}")
253-
sys.exit(1)
254-
logger, _result_log = init_log(os.path.join(output_path, f"fosslight_log_src_{_start_time}.txt"),
255-
True, logging.INFO, logging.DEBUG, _PKG_NAME, path_to_scan)
256-
257-
if selected_scanner == 'scancode' or selected_scanner == 'all' or selected_scanner == '':
258-
success, _result_log["Scan Result"], scancode_result, license_list = run_scan(path_to_scan, output_file_name,
259-
_write_json_file, num_cores, True,
256+
if success:
257+
if selected_scanner == 'scancode' or selected_scanner == 'all' or selected_scanner == '':
258+
success, result_log[RESULT_KEY], scancode_result, license_list = run_scan(path_to_scan, output_file_name,
259+
write_json_file, num_cores, True,
260260
print_matched_text, format, called_by_cli,
261261
time_out, correct_mode, correct_filepath)
262-
if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '':
263-
scanoss_result = run_scanoss_py(path_to_scan, output_file_name, format, True, _write_json_file)
264-
if selected_scanner not in SCANNER_TYPE:
265-
print_help_msg_source_scanner()
266-
sys.exit(1)
267-
268-
spdx_downloads = get_spdx_downloads(path_to_scan)
269-
merged_result = merge_results(scancode_result, scanoss_result, spdx_downloads)
270-
271-
create_report_file(_start_time, merged_result, license_list, scanoss_result, selected_scanner, print_matched_text,
272-
output_path, output_file, output_extension, correct_mode, correct_filepath, path_to_scan)
262+
if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '':
263+
scanoss_result = run_scanoss_py(path_to_scan, output_file_name, format, True, write_json_file)
264+
if selected_scanner in SCANNER_TYPE:
265+
spdx_downloads = get_spdx_downloads(path_to_scan)
266+
merged_result = merge_results(scancode_result, scanoss_result, spdx_downloads)
267+
268+
create_report_file(start_time, merged_result, license_list, scanoss_result, selected_scanner, print_matched_text,
269+
output_path, output_file, output_extension, correct_mode, correct_filepath, path_to_scan)
270+
else:
271+
print_help_msg_source_scanner()
272+
result_log[RESULT_KEY] = "Unsupported scanner"
273+
success = False
274+
else:
275+
result_log[RESULT_KEY] = f"Format error. {msg}"
276+
success = False
273277

274-
return success, _result_log["Scan Result"], merged_result, license_list, scanoss_result
278+
return success, result_log.get(RESULT_KEY, ""), merged_result, license_list, scanoss_result
275279

276280

277281
if __name__ == '__main__':

0 commit comments

Comments
 (0)