From 44c6882fe6b3cf69e4368ac4d6685acac1d4c157 Mon Sep 17 00:00:00 2001 From: Soim Date: Mon, 8 Jul 2024 14:42:33 +0900 Subject: [PATCH] Change the json key and value format --- src/fosslight_scanner/_parse_setting.py | 24 +++++++----------------- src/fosslight_scanner/cli.py | 3 ++- tests/setting.json | 12 +++++------- tox.ini | 4 ++-- 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/fosslight_scanner/_parse_setting.py b/src/fosslight_scanner/_parse_setting.py index 6cde55e..83c73ad 100644 --- a/src/fosslight_scanner/_parse_setting.py +++ b/src/fosslight_scanner/_parse_setting.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -import os def parse_setting_json(data): @@ -10,10 +9,9 @@ def parse_setting_json(data): mode = data.get('mode', []) path = data.get('path', []) dep_argument = data.get('dep_argument', '') - outputDir = data.get('outputDir', '') - outputFile = data.get('outputFile', '') + output = data.get('output', '') format = data.get('format', '') - link = data.get('link', []) + link = data.get('link', "") db_url = data.get('db_url', '') timer = data.get('timer', False) raw = data.get('raw', False) @@ -21,10 +19,10 @@ def parse_setting_json(data): no_correction = data.get('no_correction', False) correct_fpath = data.get('correct_fpath', '') ui = data.get('ui', False) - exclude_path = data.get('exclude_path', []) + exclude_path = data.get('exclude', []) - str_lists = [mode, path, link, exclude_path] - strings = [dep_argument, outputDir, outputFile, format, db_url, correct_fpath] + str_lists = [mode, path, exclude_path] + strings = [dep_argument, output, format, db_url, correct_fpath, link] booleans = [timer, raw, no_correction, ui] is_incorrect = False @@ -48,16 +46,8 @@ def parse_setting_json(data): is_incorrect = True core = -1 - if (is_incorrect): + if is_incorrect: print('Ignoring some values with incorrect format in the setting file.') - if not mode: - mode = ['all'] - final_mode = mode[0].split() - if (not ("compare" in final_mode) and (len(path) > 0)): - path = [path[0]] - link = link[0] if (link and not path) else '' - output = os.path.join(outputDir, outputFile) - - return final_mode, path, dep_argument, output, format, link, db_url, timer, \ + return mode, path, dep_argument, output, format, link, db_url, timer, \ raw, core, no_correction, correct_fpath, ui, exclude_path diff --git a/src/fosslight_scanner/cli.py b/src/fosslight_scanner/cli.py index 21365bb..2a61c65 100644 --- a/src/fosslight_scanner/cli.py +++ b/src/fosslight_scanner/cli.py @@ -9,11 +9,12 @@ from .fosslight_scanner import run_main, PKG_NAME from ._parse_setting import parse_setting_json from fosslight_util.help import print_package_version +import os.path def set_args(mode, path, dep_argument, output, format, link, db_url, timer, raw, core, no_correction, correct_fpath, ui, setting, exclude_path): - if (setting): + if setting and os.path.isfile(setting): try: with open(setting, 'r', encoding='utf-8') as file: data = json.load(file) diff --git a/tests/setting.json b/tests/setting.json index df90fcb..8f0bece 100644 --- a/tests/setting.json +++ b/tests/setting.json @@ -1,11 +1,10 @@ { - "mode": ["binary source"], + "mode": ["binary", "source"], "path": ["tests"], - "link": [], + "link": "", "dep_argument": "", - "outputDir": "test_result_parse_setting", - "outputFile": "", - "exclude_path": ["test", "sample_license.txt"], + "output": "test_result_dir", + "exclude": ["test", "sample_license.txt"], "format": "excel", "db_url": "", "timer": false, @@ -13,6 +12,5 @@ "core": -1, "no_correction": false, "correct_fpath": "", - "ui": false, - "type": "analyze" + "ui": false } diff --git a/tox.ini b/tox.ini index 93e8b73..61f92a0 100644 --- a/tox.ini +++ b/tox.ini @@ -31,7 +31,7 @@ commands = fosslight binary source -o test_result_multi_mode/test.xlsx -p tests -r fosslight -o test_result_exclude_path/test.xlsx -p tests -e test sample_license.txt fosslight dependency -o test_result_wget -w "https://github.com/LGE-OSS/example.git" - fosslight -f yaml -s tests/setting.json + fosslight source -s tests/setting.json ls test_result_wget [testenv:release] @@ -44,5 +44,5 @@ commands = fosslight binary dependency -o test_result_multi_mode/test.xlsx -p tests -r fosslight -o test_result_exclude_path/test.xlsx -p tests -e test sample_license.txt fosslight source -o test_result_wget -w "https://github.com/LGE-OSS/example.git" - fosslight -f yaml -s tests/setting.json + fosslight binary -s tests/setting.json pytest -v --flake8