Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the json key and value format #99

Merged
merged 1 commit into from
Jul 8, 2024
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
24 changes: 7 additions & 17 deletions src/fosslight_scanner/_parse_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,27 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os


def parse_setting_json(data):
# check type, if invalid = init value
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)
core = data.get('core', -1)
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

Expand All @@ -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
3 changes: 2 additions & 1 deletion src/fosslight_scanner/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 5 additions & 7 deletions tests/setting.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{
"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,
"raw": true,
"core": -1,
"no_correction": false,
"correct_fpath": "",
"ui": false,
"type": "analyze"
"ui": false
}
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Loading