Skip to content

Commit d15c3c8

Browse files
authored
Merge pull request #95 from fosslight/temp_jk
Remove the code of filtering fille name in convert mode
2 parents 8489c91 + 0f4f436 commit d15c3c8

File tree

9 files changed

+122
-122
lines changed

9 files changed

+122
-122
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ binaryornot
33
requests
44
reuse
55
PyYAML
6-
fosslight_util>=1.4.3
6+
fosslight_util>=1.4.7

src/fosslight_oss_pkg/_convert.py

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
from datetime import datetime
1111
from pathlib import Path
1212
from yaml import safe_dump
13-
from fosslight_prechecker._help import print_help_msg
1413
from fosslight_util.constant import LOGGER_NAME
1514
from fosslight_util.set_log import init_log
1615
from fosslight_util.output_format import check_output_format
16+
from fosslight_util.parsing_yaml import find_sbom_yaml_files
1717
from ._parsing_excel import convert_excel_to_yaml, convert_yml_to_excel
1818

1919
CUSTOMIZED_FORMAT_FOR_PRECHECKER = {'yaml': '.yaml', 'excel': '.xlsx'}
@@ -40,12 +40,19 @@ def find_report_file(path_to_find):
4040
return ""
4141

4242

43+
def check_extension_and_format(file, format):
44+
if (file.endswith((".yaml", ".yml")) and format == "yaml") or \
45+
(file.endswith(".xlsx") and format == "excel"):
46+
logger.error(f"File extension is not matched with input format({format})")
47+
sys.exit(1)
48+
49+
4350
def convert_report(base_path, output_name, format, need_log_file=True, sheet_names=""):
44-
oss_pkg_files = ["oss-pkg-info.yml", "oss-pkg-info.yaml"]
51+
oss_yaml_files = []
52+
oss_report_files = "" # TODO: Change to list type for multiple Report files
4553
file_option_on = False
4654
convert_yml_mode = False
4755
convert_excel_mode = False
48-
report_to_read = ""
4956
output_report = ""
5057
output_yaml = ""
5158
now = datetime.now().strftime('%Y%m%d_%H-%M-%S')
@@ -68,54 +75,50 @@ def convert_report(base_path, output_name, format, need_log_file=True, sheet_nam
6875
output_yaml = os.path.join(output_path, output_name)
6976
else:
7077
output_report = os.path.join(os.path.abspath(output_path), f"FOSSLight-Report_{now}")
71-
output_yaml = os.path.join(os.path.abspath(output_path), f"oss-pkg-info_{now}")
78+
output_yaml = os.path.join(os.path.abspath(output_path), f"fosslight-sbom-info_{now}")
7279
else:
7380
logger.error(f"Format error - {msg}")
7481
sys.exit(1)
7582

83+
if base_path == "":
84+
base_path = output_path
85+
7686
if os.path.isdir(base_path):
77-
if output_extension == ".yaml":
78-
logger.error("Format error - can make only .xlsx file")
79-
sys.exit(1)
80-
convert_yml_mode = True
87+
oss_yaml_files = find_sbom_yaml_files(base_path)
88+
if oss_yaml_files:
89+
convert_yml_mode = True
8190
else:
8291
if base_path != "":
83-
if base_path.endswith(".xlsx"):
84-
if output_extension == '.xlsx':
85-
logger.error("Format error - can make only .yaml file")
86-
sys.exit(1)
87-
p = re.compile(r"[\s\S]*OSS[\s\S]*-Report[\s\S]*.xlsx", re.I)
88-
if p.search(base_path):
92+
files_to_convert = base_path.split(",")
93+
for file in files_to_convert:
94+
check_extension_and_format(file, format)
95+
if file.endswith(".xlsx"):
8996
convert_excel_mode = True
90-
report_to_read = base_path
91-
elif base_path.endswith((".yaml", ".yml")):
92-
if output_extension == '.yaml':
93-
logger.error("Format error - can make only .xlsx file")
94-
sys.exit(1)
95-
p = re.compile(r"oss-pkg-info[\s\S]*.ya?ml", re.I)
96-
if p.search(base_path):
97-
oss_pkg_files = base_path.split(',')
97+
oss_report_files = file
98+
elif file.endswith((".yaml", ".yml")):
9899
convert_yml_mode = True
99100
file_option_on = True
100-
else:
101-
logger.error("Not support file name or extension - only support for FOSSLight-Report*.xlsx or oss-pkg-info*.yaml file")
102-
sys.exit(1)
101+
oss_yaml_files.append(file)
102+
else:
103+
logger.error("Not support file name or extension")
104+
sys.exit(1)
103105

104106
if not convert_yml_mode and not convert_excel_mode:
105107
if is_window:
106108
convert_yml_mode = True
107109
base_path = os.getcwd()
108-
report_to_read = find_report_file(base_path)
109-
if report_to_read != "":
110+
oss_report_files = find_report_file(base_path)
111+
if oss_report_files != "":
110112
convert_excel_mode = True
111113
else:
112-
print_help_msg()
114+
logger.info("fosslight_prechecker: can't convert anything")
115+
logger.info("Try 'fosslight_prechecker -h for more information")
113116

114117
if convert_yml_mode:
115-
convert_yml_to_excel(oss_pkg_files, output_report, file_option_on, base_path, is_window)
118+
convert_yml_to_excel(oss_yaml_files, output_report, file_option_on, base_path)
116119

117120
if convert_excel_mode:
118-
convert_excel_to_yaml(report_to_read, output_yaml, sheet_names)
121+
convert_excel_to_yaml(oss_report_files, output_yaml, sheet_names)
119122

120123
try:
121124
_str_final_result_log = safe_dump(_result_log, allow_unicode=True, sort_keys=True)

src/fosslight_oss_pkg/_parsing_excel.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sys
88
import yaml
99
from fosslight_util.constant import LOGGER_NAME
10-
from fosslight_util.parsing_yaml import find_all_oss_pkg_files, parsing_yml
10+
from fosslight_util.parsing_yaml import parsing_yml
1111
from fosslight_util.output_format import write_output_file
1212
from fosslight_util.write_yaml import create_yaml_with_ossitem
1313
from fosslight_util.read_excel import read_oss_report
@@ -16,33 +16,30 @@
1616
IDX_CANNOT_FOUND = -1
1717

1818

19-
def convert_yml_to_excel(oss_pkg_files, output_file, file_option_on, base_path, window):
19+
def convert_yml_to_excel(oss_yaml_files, output_file, file_option_on, base_path):
2020
items_to_print = []
2121
sheet_list = {}
2222

23-
if not file_option_on:
24-
oss_pkg_files = find_all_oss_pkg_files(base_path, oss_pkg_files)
25-
26-
for oss_pkg_file in oss_pkg_files:
23+
for yaml_file in oss_yaml_files:
2724
try:
28-
if os.path.isfile(oss_pkg_file):
29-
logger.warning(f"Read data from : {oss_pkg_file}")
25+
if os.path.isfile(yaml_file):
26+
logger.info(f"Read data from : {yaml_file}")
3027

3128
if file_option_on:
32-
base_path = os.path.dirname(oss_pkg_file)
33-
oss_items, _ = parsing_yml(oss_pkg_file, base_path)
29+
base_path = os.path.dirname(yaml_file)
30+
oss_items, _ = parsing_yml(yaml_file, base_path)
3431
for item in oss_items:
3532
items_to_print.extend(item.get_print_array())
3633
except Exception as ex:
3734
logger.error(f"Read yaml file: {ex}")
3835

3936
try:
40-
sheet_list["SRC_FL_Reuse"] = items_to_print
37+
sheet_list["SRC_FL_Prechecker"] = items_to_print
4138
success, msg, result_file = write_output_file(output_file, '.xlsx',
4239
sheet_list)
4340
if success:
4441
if result_file:
45-
logger.info(f"Output: {result_file}")
42+
logger.warning(f"Output: {result_file}")
4643
else:
4744
logger.warning("Nothing is detected to convert so output file is not generated.")
4845
else:

src/fosslight_prechecker/_add.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from yaml import safe_dump
1313
from fosslight_util.set_log import init_log
1414
from fosslight_util.spdx_licenses import get_spdx_licenses_json
15-
from fosslight_util.parsing_yaml import find_all_oss_pkg_files, parsing_yml
15+
from fosslight_util.parsing_yaml import find_sbom_yaml_files, parsing_yml
1616
from fosslight_util.output_format import check_output_format
1717
from datetime import datetime
1818
from fosslight_prechecker._precheck import precheck_for_project, precheck_for_files, dump_error_msg, get_path_to_find
@@ -298,24 +298,24 @@ def is_exclude_dir(dir_path):
298298

299299

300300
def download_oss_info_license(base_path, input_license=""):
301-
oss_pkg_files = ["oss-pkg-info.yml", "oss-pkg-info.yaml"]
302301
license_list = []
303302
converted_lic_list = []
303+
oss_yaml_files = []
304304
main_parser = reuse_arg_parser()
305305
prj = Project(base_path)
306306

307-
found_oss_pkg_files = find_all_oss_pkg_files(base_path, oss_pkg_files)
307+
oss_yaml_files = find_sbom_yaml_files(base_path)
308308

309309
if input_license != "":
310310
license_list.append(input_license)
311311

312-
if found_oss_pkg_files is None or len(found_oss_pkg_files) == 0:
312+
if oss_yaml_files is None or len(oss_yaml_files) == 0:
313313
logger.info("\n # There is no OSS package Info file in this path\n")
314314
return
315315
else:
316-
logger.info(f"\n # There is OSS Package Info file(s) : {found_oss_pkg_files}\n")
316+
logger.info(f"\n # There is OSS Package Info file(s) : {oss_yaml_files}\n")
317317

318-
for oss_pkg_file in found_oss_pkg_files:
318+
for oss_pkg_file in oss_yaml_files:
319319
_, license_list = parsing_yml(oss_pkg_file, base_path)
320320

321321
for lic in license_list:

src/fosslight_prechecker/_constant.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
DEFAULT_EXCLUDE_EXTENSION = ["jar", "png", "exe", "so", "a", "dll", "jpeg", "jpg", "ttf", "lib", "ttc", "pfb",
77
"pfm", "otf", "afm", "dfont", "json"]
8-
OSS_PKG_INFO_FILES = [r"oss-pkg-info[\s\S]*.yaml", "oss-pkg-info.yml", r"oss-package[\s\S]*.info", "requirement.txt",
9-
"requirements.txt", "package.json", "pom.xml", "build.gradle", "podfile.lock", "cartfile.resolved",
10-
"pubspec.yaml", "package.resolved", "go.mod", r"fosslight-sbom-info[\s\S]*.yaml"]
8+
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",
9+
"requirement.txt", "requirements.txt", "package.json", "pom.xml", "build.gradle",
10+
"podfile.lock", "cartfile.resolved", "pubspec.yaml", "package.resolved", "go.mod"]
1111
HTML_RESULT_EXPAND_LIMIT = 10
1212
HTML_RESULT_PRINT_LIMIT = 100
1313

src/fosslight_prechecker/_result.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from pathlib import Path
1414
from reuse.project import Project
1515
from fosslight_prechecker._result_html import result_for_html
16-
from fosslight_util.parsing_yaml import find_all_oss_pkg_files, parsing_yml
16+
from fosslight_util.parsing_yaml import find_sbom_yaml_files, parsing_yml
1717
from fosslight_util.output_format import check_output_format
1818
import re
1919

@@ -286,8 +286,8 @@ def result_for_summary(path_to_find, oss_pkg_info_files, license_missing_files,
286286
detected_lic.append(lic)
287287

288288
if oss_pkg_info_files:
289-
pkg_info_yaml_files = find_all_oss_pkg_files(path_to_find, oss_pkg_info_files)
290-
yaml_file = get_only_pkg_info_yaml_file(pkg_info_yaml_files)
289+
oss_yaml_files = find_sbom_yaml_files(path_to_find)
290+
yaml_file = get_only_pkg_info_yaml_file(oss_yaml_files)
291291
# Exclude files in yaml
292292
license_missing_files, copyright_missing_files = exclude_file_in_yaml(path_to_find, yaml_file,
293293
set(license_missing_files) - set(oss_pkg_info_files),

tests/convert/oss-pkg-info.yaml

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1-
libidn:
2-
- version: "1.5"
3-
source name or path:
1+
Open Source Software Package:
2+
- name: libidn
3+
version: 1.5
4+
source: http://ftp.gnu.org/gnu/libidn
5+
homepage: https://www.gnu.org/software/libidn
6+
license:
7+
- GPL-3.0
8+
- LGPL-2.1
9+
file:
410
- a.c
511
- b.c
6-
license:
7-
- "GPL-3.0"
8-
- "LGPL-2.1"
9-
download location: "http://ftp.gnu.org/gnu/libidn"
10-
homepage: "https://www.gnu.org/software/libidn"
11-
copyright text: "Copyright (c) 2002-2007, Simon Josefsson"
12-
node-backoff:
13-
- version: "2.5.0"
14-
source name or path: "src/*"
15-
license: "MIT"
16-
download location: "https://github.com/MathieuTurcotte/node-backoff"
17-
homepage: "https://www.npmjs.com/package/backoff"
18-
copyright text: "Copyright (c) 2012 Mathieu Turcotte"
12+
copyright: Copyright (c) 2002-2007, Simon Josefsson
13+
- name: node-backoff
14+
version: 2.5.0
15+
source: https://github.com/MathieuTurcotte/node-backoff
16+
homepage: https://www.npmjs.com/package/backoff
17+
license: MIT
18+
file: src/*
19+
copyright: Copyright (c) 2012 Mathieu Turcotte
1920
exclude: True
20-
rsync:
21-
- version: "2.6.9"
22-
source name or path: "test/tool"
23-
license: "GPL-2.0"
24-
download location: "https://download.samba.org/pub/rsync/src"
25-
homepage: "http://rsync.samba.org"
26-
- version: "3.1.2"
27-
source name or path: "test/tool"
28-
license: "GPL-3.0"
29-
download location: "https://download.samba.org/pub/rsync/src"
30-
homepage: "http://rsync.samba.org"
31-
copyright text:
32-
- "Copyright (c) 1996 Andrew Tridgell"
33-
- "Copyright (c) 1996 Paul Mackerras"
34-
- "Copyright (c) 2003-2015 Wayne Davison"
21+
- name: rsync
22+
version: 2.6.9
23+
source: https://download.samba.org/pub/rsync/src
24+
homepage: http://rsync.samba.org
25+
license: GPL-2.0
26+
file: test/tool
27+
- name: rsync
28+
version: 3.1.2
29+
source: https://download.samba.org/pub/rsync/src
30+
homepage: http://rsync.samba.org
31+
license: GPL-3.0
32+
file: test/tool
33+
copyright text: |
34+
Copyright (c) 1996 Andrew Tridgell
35+
Copyright (c) 1996 Paul Mackerras
36+
Copyright (c) 2003-2015 Wayne Davison

tests/convert/oss-pkg-info_old.yaml

Lines changed: 0 additions & 36 deletions
This file was deleted.

tests/convert/sbom-info.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
libidn:
2+
- version: "1.5"
3+
source name or path:
4+
- a.c
5+
- b.c
6+
license:
7+
- "GPL-3.0"
8+
- "LGPL-2.1"
9+
download location: "http://ftp.gnu.org/gnu/libidn"
10+
homepage: "https://www.gnu.org/software/libidn"
11+
copyright text: "Copyright (c) 2002-2007, Simon Josefsson"
12+
node-backoff:
13+
- version: "2.5.0"
14+
source name or path: "src/*"
15+
license: "MIT"
16+
download location: "https://github.com/MathieuTurcotte/node-backoff"
17+
homepage: "https://www.npmjs.com/package/backoff"
18+
copyright text: "Copyright (c) 2012 Mathieu Turcotte"
19+
exclude: True
20+
rsync:
21+
- version: "2.6.9"
22+
source name or path: "test/tool"
23+
license: "GPL-2.0"
24+
download location: "https://download.samba.org/pub/rsync/src"
25+
homepage: "http://rsync.samba.org"
26+
- version: "3.1.2"
27+
source name or path: "test/tool"
28+
license: "GPL-3.0"
29+
download location: "https://download.samba.org/pub/rsync/src"
30+
homepage: "http://rsync.samba.org"
31+
copyright text:
32+
- "Copyright (c) 1996 Andrew Tridgell"
33+
- "Copyright (c) 1996 Paul Mackerras"
34+
- "Copyright (c) 2003-2015 Wayne Davison"

0 commit comments

Comments
 (0)