Skip to content

Commit

Permalink
Merge pull request #111 from fosslight/develop
Browse files Browse the repository at this point in the history
Fix bug for not working options(-n, i)
  • Loading branch information
bjk7119 authored Oct 25, 2022
2 parents 48ffef5 + 4fe3d0f commit a249cbd
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ It uses [reuse-tool][ret] to check whether the [source code's copyright and lice
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.
Here a short summary:

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

- `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).

Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ flake8==3.9.2
pytest
pytest-cov
pytest-flake8
importlib-metadata==4.2.0
6 changes: 3 additions & 3 deletions src/fosslight_prechecker/_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def input_license_while_running():
input_license = ""

logger.info("# Select a license to write in the license missing files ")
select = input(" 1.MIT, 2.Apache-2.0, 3.LGE-Proprietary, 4.Manaully Input, 5.Not select now : ")
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: ")
if select == '1' or select == 'MIT':
input_license = 'MIT'
elif select == '2' or select == 'Apache-2.0':
Expand All @@ -140,7 +140,7 @@ def input_license_while_running():

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

Expand Down Expand Up @@ -419,7 +419,7 @@ def add_content(target_path="", input_license="", input_copyright="", output_pat
all_files_list = get_allfiles_list(path_to_find)

# Get missing license / copyright file list
missing_license, missing_copyright, _, project, _ = precheck_for_project(path_to_find, need_log_file)
missing_license, missing_copyright, _, project, _ = precheck_for_project(path_to_find)

# Print Skipped Files
missing_license_filtered, missing_copyright_filtered = \
Expand Down
1 change: 1 addition & 0 deletions src/fosslight_prechecker/_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright (c) 2022 LG Electronics Inc.
# SPDX-License-Identifier: GPL-3.0-only

PKG_NAME = "fosslight_prechecker"
DEFAULT_EXCLUDE_EXTENSION = ["jar", "png", "exe", "so", "a", "dll", "jpeg", "jpg", "ttf", "lib", "ttc", "pfb",
"pfm", "otf", "afm", "dfont", "json"]
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",
Expand Down
2 changes: 1 addition & 1 deletion src/fosslight_prechecker/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Parameters:
Mode
lint\t\t Check whether the copyright and license writing rules are complied with
lint\t\t (Default) Check whether the copyright and license writing rules are complied with
convert\t\t Convert sbom_info.yaml -> FOSSLight-Report.xlsx
add\t\t\t Add missing license and copyright
Expand Down
24 changes: 11 additions & 13 deletions src/fosslight_prechecker/_precheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
from reuse.project import Project
from reuse.report import ProjectReport
from fosslight_prechecker._result import write_result_file, create_result_file, result_for_summary, ResultItem
from fosslight_prechecker._constant import DEFAULT_EXCLUDE_EXTENSION, OSS_PKG_INFO_FILES
from fosslight_prechecker._constant import DEFAULT_EXCLUDE_EXTENSION, OSS_PKG_INFO_FILES, PKG_NAME

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


def precheck_for_project(path_to_find, need_log_file):
def precheck_for_project(path_to_find):
missing_license = []
missing_copyright = []

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

try:
if need_log_file:
# Use ProgressBar
timer = TimerThread()
timer.setDaemon(True)
timer.start()

project = Project(path_to_find)
report = ProjectReport.generate(project)

if need_log_file:
timer.stop = True

# File list that missing license text
missing_license = [str(sub) for sub in set(report.files_without_licenses)]
if not path_to_find.endswith("/"):
Expand Down Expand Up @@ -268,10 +258,18 @@ def run_lint(target_path, disable, output_file_name, format='', need_log_file=Tr
oss_pkg_info = []
_turn_on_default_reuse_config = not disable

if need_log_file:
# Use ProgressBar
timer = TimerThread()
timer.setDaemon(True)
timer.start()

if _check_only_file_mode:
license_missing_files, copyright_missing_files, project = precheck_for_files(path_to_find, file_to_check_list)
else:
license_missing_files, copyright_missing_files, oss_pkg_info, project, report = precheck_for_project(path_to_find, need_log_file)
license_missing_files, copyright_missing_files, oss_pkg_info, project, report = precheck_for_project(path_to_find)
if need_log_file:
timer.stop = True

result_item = result_for_summary(path_to_find,
oss_pkg_info,
Expand Down
38 changes: 21 additions & 17 deletions src/fosslight_prechecker/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,27 @@
import sys
import os
from fosslight_util.help import print_package_version
from fosslight_prechecker._help import print_help_msg
from fosslight_prechecker._precheck import run_lint, PKG_NAME
from fosslight_oss_pkg._convert import convert_report
from fosslight_prechecker._help import print_help_msg
from fosslight_prechecker._constant import PKG_NAME
from fosslight_prechecker._add import add_content
from fosslight_prechecker._precheck import run_lint


def run_main(mode, path, output, format, no_log, disable, copyright, license):
if mode == "lint":
run_lint(path, disable, output, format, no_log)
elif mode == "add":
add_content(path, license, copyright, output, no_log)
elif mode == "convert":
convert_report(path, output, format, no_log)
else:
print("Not supported mode. Select one of 'lint', 'add', or 'convert'")


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

if args.help:
print_help_msg()

if args.version:
print_package_version(PKG_NAME, "FOSSLight Prechecker Version")
sys.exit(0)

if not args.path:
args.path = os.getcwd()

if args.mode == "lint":
run_lint(args.path, args.disable, args.output, args.format, args.log)
elif args.mode == "convert":
convert_report(args.path, args.output, args.format, args.log)
elif args.mode == "add":
add_content(args.path, args.license, args.copyright, args.output, args.log)
else:
if args.help:
print_help_msg()
elif args.version:
print_package_version(PKG_NAME, "FOSSLight Prechecker Version")
else:
run_main(args.mode, args.path, args.output, args.format,
args.log, args.disable, args.copyright, args.license)


if __name__ == "__main__":
Expand Down

0 comments on commit a249cbd

Please sign in to comment.