Skip to content

Commit a249cbd

Browse files
authored
Merge pull request #111 from fosslight/develop
Fix bug for not working options(-n, i)
2 parents 48ffef5 + 4fe3d0f commit a249cbd

File tree

7 files changed

+39
-35
lines changed

7 files changed

+39
-35
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ It uses [reuse-tool][ret] to check whether the [source code's copyright and lice
1616
Please see the [**User Guide**](https://fosslight.org/fosslight-guide-en/scanner/1_prechecker.html) for more information on how to install and run it.
1717
Here a short summary:
1818

19-
- `lint` --- Check whether the [source code's copyright and license writing rules][rule] are complied with.
19+
- `lint` --- (Default) Check whether the [source code's copyright and license writing rules][rule] are complied with.
2020

2121
- `convert` --- Convert [sbom-info.yaml](https://github.com/fosslight/fosslight_prechecker/blob/main/tests/convert/sbom-info.yaml) or [oss-pkg-info.yaml](https://github.com/fosslight/fosslight_prechecker/blob/main/tests/convert/oss-pkg-info.yaml) to [fosslight_report.xlsx](https://fosslight.org/fosslight-guide-en/learn/2_fosslight_report.html).
2222

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ flake8==3.9.2
33
pytest
44
pytest-cov
55
pytest-flake8
6+
importlib-metadata==4.2.0

src/fosslight_prechecker/_add.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def input_license_while_running():
124124
input_license = ""
125125

126126
logger.info("# Select a license to write in the license missing files ")
127-
select = input(" 1.MIT, 2.Apache-2.0, 3.LGE-Proprietary, 4.Manaully Input, 5.Not select now : ")
127+
select = input("\t1.MIT\n \t2.Apache-2.0\n \t3.LGE-Proprietary\n \t4.Manual Input\n \t5.Not select now\n- Choose one from the list: ")
128128
if select == '1' or select == 'MIT':
129129
input_license = 'MIT'
130130
elif select == '2' or select == 'Apache-2.0':
@@ -140,7 +140,7 @@ def input_license_while_running():
140140

141141
def input_copyright_while_running():
142142
input_copyright = ""
143-
input_copyright = input("# Input Copyright to write in the copyright missing files (ex, <year> <name>) : ")
143+
input_copyright = input("# Input Copyright to write in the copyright missing files (ex, <year> <name>): ")
144144
if input_copyright == 'Quit' or input_copyright == 'quit' or input_copyright == 'Q':
145145
return
146146

@@ -419,7 +419,7 @@ def add_content(target_path="", input_license="", input_copyright="", output_pat
419419
all_files_list = get_allfiles_list(path_to_find)
420420

421421
# Get missing license / copyright file list
422-
missing_license, missing_copyright, _, project, _ = precheck_for_project(path_to_find, need_log_file)
422+
missing_license, missing_copyright, _, project, _ = precheck_for_project(path_to_find)
423423

424424
# Print Skipped Files
425425
missing_license_filtered, missing_copyright_filtered = \

src/fosslight_prechecker/_constant.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Copyright (c) 2022 LG Electronics Inc.
44
# SPDX-License-Identifier: GPL-3.0-only
55

6+
PKG_NAME = "fosslight_prechecker"
67
DEFAULT_EXCLUDE_EXTENSION = ["jar", "png", "exe", "so", "a", "dll", "jpeg", "jpg", "ttf", "lib", "ttc", "pfb",
78
"pfm", "otf", "afm", "dfont", "json"]
89
OSS_PKG_INFO_FILES = [r"oss-pkg-info[\s\S]*.ya?ml", r"oss-package[\s\S]*.info", r"sbom-info[\s\S]*.ya?ml",

src/fosslight_prechecker/_help.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
Parameters:
1717
Mode
18-
lint\t\t Check whether the copyright and license writing rules are complied with
18+
lint\t\t (Default) Check whether the copyright and license writing rules are complied with
1919
convert\t\t Convert sbom_info.yaml -> FOSSLight-Report.xlsx
2020
add\t\t\t Add missing license and copyright
2121

src/fosslight_prechecker/_precheck.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
from reuse.project import Project
1919
from reuse.report import ProjectReport
2020
from fosslight_prechecker._result import write_result_file, create_result_file, result_for_summary, ResultItem
21-
from fosslight_prechecker._constant import DEFAULT_EXCLUDE_EXTENSION, OSS_PKG_INFO_FILES
21+
from fosslight_prechecker._constant import DEFAULT_EXCLUDE_EXTENSION, OSS_PKG_INFO_FILES, PKG_NAME
2222

2323
is_windows = platform.system() == 'Windows'
24-
PKG_NAME = "fosslight_prechecker"
2524
REUSE_CONFIG_FILE = ".reuse/dep5"
2625
DEFAULT_EXCLUDE_EXTENSION_FILES = [] # Exclude files from reuse
2726
_turn_on_default_reuse_config = True
@@ -158,7 +157,7 @@ def precheck_for_files(path, files):
158157
return missing_license_list, missing_copyright_list, prj
159158

160159

161-
def precheck_for_project(path_to_find, need_log_file):
160+
def precheck_for_project(path_to_find):
162161
missing_license = []
163162
missing_copyright = []
164163

@@ -167,18 +166,9 @@ def precheck_for_project(path_to_find, need_log_file):
167166
need_rollback, temp_file_name, temp_dir_name = create_reuse_dep5_file(path_to_find)
168167

169168
try:
170-
if need_log_file:
171-
# Use ProgressBar
172-
timer = TimerThread()
173-
timer.setDaemon(True)
174-
timer.start()
175-
176169
project = Project(path_to_find)
177170
report = ProjectReport.generate(project)
178171

179-
if need_log_file:
180-
timer.stop = True
181-
182172
# File list that missing license text
183173
missing_license = [str(sub) for sub in set(report.files_without_licenses)]
184174
if not path_to_find.endswith("/"):
@@ -268,10 +258,18 @@ def run_lint(target_path, disable, output_file_name, format='', need_log_file=Tr
268258
oss_pkg_info = []
269259
_turn_on_default_reuse_config = not disable
270260

261+
if need_log_file:
262+
# Use ProgressBar
263+
timer = TimerThread()
264+
timer.setDaemon(True)
265+
timer.start()
266+
271267
if _check_only_file_mode:
272268
license_missing_files, copyright_missing_files, project = precheck_for_files(path_to_find, file_to_check_list)
273269
else:
274-
license_missing_files, copyright_missing_files, oss_pkg_info, project, report = precheck_for_project(path_to_find, need_log_file)
270+
license_missing_files, copyright_missing_files, oss_pkg_info, project, report = precheck_for_project(path_to_find)
271+
if need_log_file:
272+
timer.stop = True
275273

276274
result_item = result_for_summary(path_to_find,
277275
oss_pkg_info,

src/fosslight_prechecker/cli.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,27 @@
66
import sys
77
import os
88
from fosslight_util.help import print_package_version
9-
from fosslight_prechecker._help import print_help_msg
10-
from fosslight_prechecker._precheck import run_lint, PKG_NAME
119
from fosslight_oss_pkg._convert import convert_report
10+
from fosslight_prechecker._help import print_help_msg
11+
from fosslight_prechecker._constant import PKG_NAME
1212
from fosslight_prechecker._add import add_content
13+
from fosslight_prechecker._precheck import run_lint
14+
15+
16+
def run_main(mode, path, output, format, no_log, disable, copyright, license):
17+
if mode == "lint":
18+
run_lint(path, disable, output, format, no_log)
19+
elif mode == "add":
20+
add_content(path, license, copyright, output, no_log)
21+
elif mode == "convert":
22+
convert_report(path, output, format, no_log)
23+
else:
24+
print("Not supported mode. Select one of 'lint', 'add', or 'convert'")
1325

1426

1527
def main():
1628
parser = argparse.ArgumentParser(description='FOSSLight Prechecker', prog='fosslight_prechecker', add_help=False)
17-
parser.add_argument('mode', nargs='?', help='lint | convert | add', choices=['lint', 'add', 'convert'])
29+
parser.add_argument('mode', nargs='?', help='lint(default) | convert | add', choices=['lint', 'add', 'convert'], default='lint')
1830
parser.add_argument('-h', '--help', help='Print help message', action='store_true', dest='help')
1931
parser.add_argument('-i', '--ignore', help='Do not write log to file', action='store_false', dest='log')
2032
parser.add_argument('-v', '--version', help='Print FOSSLight Prechecker version', action='store_true', dest='version')
@@ -29,24 +41,16 @@ def main():
2941
except SystemExit:
3042
sys.exit(0)
3143

32-
if args.help:
33-
print_help_msg()
34-
35-
if args.version:
36-
print_package_version(PKG_NAME, "FOSSLight Prechecker Version")
37-
sys.exit(0)
38-
3944
if not args.path:
4045
args.path = os.getcwd()
4146

42-
if args.mode == "lint":
43-
run_lint(args.path, args.disable, args.output, args.format, args.log)
44-
elif args.mode == "convert":
45-
convert_report(args.path, args.output, args.format, args.log)
46-
elif args.mode == "add":
47-
add_content(args.path, args.license, args.copyright, args.output, args.log)
48-
else:
47+
if args.help:
4948
print_help_msg()
49+
elif args.version:
50+
print_package_version(PKG_NAME, "FOSSLight Prechecker Version")
51+
else:
52+
run_main(args.mode, args.path, args.output, args.format,
53+
args.log, args.disable, args.copyright, args.license)
5054

5155

5256
if __name__ == "__main__":

0 commit comments

Comments
 (0)