Skip to content

Commit ebec30e

Browse files
authored
Merge pull request #162 from fosslight/ref
Refactoring OSS item
2 parents 0dce60c + cf07931 commit ebec30e

File tree

3 files changed

+44
-30
lines changed

3 files changed

+44
-30
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ binaryornot
33
requests
44
reuse==1.1.2
55
PyYAML
6-
fosslight_util~=1.4.43
6+
fosslight_util~=2.0.0
77
jinja2

src/fosslight_oss_pkg/_parsing_excel.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from fosslight_util.constant import LOGGER_NAME
99
from fosslight_util.parsing_yaml import parsing_yml
1010
from fosslight_util.output_format import write_output_file
11+
from fosslight_util.oss_item import ScannerItem
12+
from fosslight_prechecker._constant import PKG_NAME
13+
from datetime import datetime
1114

1215
logger = logging.getLogger(LOGGER_NAME)
1316

@@ -41,8 +44,9 @@ def convert_yml_to_excel(
4144
base_path: str
4245
) -> None:
4346
sheet_list = {}
44-
header = {}
45-
47+
start_time = datetime.now().strftime('%y%m%d_%H%M')
48+
scan_item = ScannerItem(PKG_NAME, start_time)
49+
scan_item.set_cover_pathinfo(base_path, "")
4650
for yaml_file in oss_yaml_files:
4751
try:
4852
if os.path.isfile(yaml_file):
@@ -52,27 +56,30 @@ def convert_yml_to_excel(
5256

5357
if file_option_on:
5458
base_path = os.path.dirname(yaml_file)
55-
oss_items, _, _ = parsing_yml(yaml_file, base_path)
56-
# if oss_items is abnormal(empty or invalid)
57-
if not oss_items:
59+
file_items, _, _ = parsing_yml(yaml_file, base_path)
60+
# if file_items is abnormal(empty or invalid)
61+
if not file_items:
5862
continue
5963

60-
for item in oss_items:
61-
items_to_print.extend(item.get_print_array())
6264
if not base_path.endswith(f"{os.sep}"):
6365
base_path += f"{os.sep}"
64-
yaml_file = yaml_file.replace(base_path, '')
65-
yaml_file = yaml_file.replace(os.sep, '_')
66-
yaml_file_sheet = get_sheet_name(yaml_file, sheet_list)
66+
tmp_yaml_file = yaml_file.replace(base_path, '')
67+
tmp_yaml_file = tmp_yaml_file.replace(os.sep, '_')
68+
yaml_file_sheet = get_sheet_name(tmp_yaml_file, sheet_list)
6769

6870
if yaml_file_sheet:
69-
sheet_list[yaml_file_sheet] = items_to_print
70-
header[yaml_file_sheet] = HEADER_CONTENT
71+
scan_item.set_cover_comment(f"Converted file:{yaml_file}")
72+
row_items = [HEADER_CONTENT]
73+
for file_item in file_items:
74+
row_items.extend(file_item.get_print_array())
75+
sheet_list[yaml_file_sheet] = row_items
76+
7177
except Exception as ex:
7278
logger.error(f"Read yaml file: {ex}")
7379

7480
try:
75-
success, msg, result_file = write_output_file(output_file, '.xlsx', sheet_list, header)
81+
scan_item.external_sheets = sheet_list
82+
success, msg, result_file = write_output_file(output_file, '.xlsx', scan_item)
7683
if success:
7784
if result_file:
7885
logger.warning(f"Output: {result_file}")

src/fosslight_prechecker/_result.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ def create_result_file(output_file_name, format='', _start_time=""):
210210
return result_file, output_path, output_extension
211211

212212

213-
def get_path_in_yaml(oss_item):
214-
path_in_yaml = [os.path.join(oss_item.relative_path, file) for file in oss_item.source_name_or_path]
213+
def get_path_in_yaml(file_item):
214+
path_in_yaml = [os.path.join(file_item.relative_path, file_item.source_name_or_path)]
215215
path_in_yaml = [path.replace('\\', '/') for path in path_in_yaml]
216216
return path_in_yaml
217217

@@ -244,20 +244,27 @@ def exclude_file_in_yaml(path_to_find, yaml_files, license_missing_files, copyri
244244
cop_present_path = []
245245
abnormal_yaml_files = {}
246246

247-
for file in yaml_files:
248-
oss_items, _, err_reason = parsing_yml(file, path_to_find, False)
249-
# if oss_items is abnormal(empty or invalid)
250-
if not oss_items:
251-
abnormal_yaml_files[file] = err_reason
252-
253-
for oss_item in oss_items:
254-
if oss_item.exclude:
255-
excluded_path.extend(get_path_in_yaml(oss_item))
256-
else:
257-
if oss_item.license:
258-
lic_present_path.extend(get_path_in_yaml(oss_item))
259-
if oss_item.copyright:
260-
cop_present_path.extend(get_path_in_yaml(oss_item))
247+
for yaml_file in yaml_files:
248+
file_items, _, err_reason = parsing_yml(yaml_file, path_to_find, False)
249+
# if file_items is abnormal(empty or invalid)
250+
if not file_items:
251+
abnormal_yaml_files[yaml_file] = err_reason
252+
253+
for file_item in file_items:
254+
license_added = False
255+
copyright_added = False
256+
excluded_file = False
257+
for oss_item in file_item.oss_items:
258+
if (not excluded_file) and oss_item.exclude:
259+
excluded_file = True
260+
excluded_path.extend(get_path_in_yaml(file_item))
261+
else:
262+
if (not license_added) and oss_item.license:
263+
license_added = True
264+
lic_present_path.extend(get_path_in_yaml(file_item))
265+
if (not copyright_added) and oss_item.copyright:
266+
copyright_added = True
267+
cop_present_path.extend(get_path_in_yaml(file_item))
261268

262269
total_missing_files = list(license_missing_files.union(copyright_missing_files))
263270
files_with_exclude_removed = extract_files_in_path(excluded_path, total_missing_files, True)

0 commit comments

Comments
 (0)