Skip to content

Commit

Permalink
Merge pull request #162 from fosslight/ref
Browse files Browse the repository at this point in the history
Refactoring OSS item
  • Loading branch information
soimkim authored Sep 8, 2024
2 parents 0dce60c + cf07931 commit ebec30e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 30 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ binaryornot
requests
reuse==1.1.2
PyYAML
fosslight_util~=1.4.43
fosslight_util~=2.0.0
jinja2
33 changes: 20 additions & 13 deletions src/fosslight_oss_pkg/_parsing_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from fosslight_util.constant import LOGGER_NAME
from fosslight_util.parsing_yaml import parsing_yml
from fosslight_util.output_format import write_output_file
from fosslight_util.oss_item import ScannerItem
from fosslight_prechecker._constant import PKG_NAME
from datetime import datetime

logger = logging.getLogger(LOGGER_NAME)

Expand Down Expand Up @@ -41,8 +44,9 @@ def convert_yml_to_excel(
base_path: str
) -> None:
sheet_list = {}
header = {}

start_time = datetime.now().strftime('%y%m%d_%H%M')
scan_item = ScannerItem(PKG_NAME, start_time)
scan_item.set_cover_pathinfo(base_path, "")
for yaml_file in oss_yaml_files:
try:
if os.path.isfile(yaml_file):
Expand All @@ -52,27 +56,30 @@ def convert_yml_to_excel(

if file_option_on:
base_path = os.path.dirname(yaml_file)
oss_items, _, _ = parsing_yml(yaml_file, base_path)
# if oss_items is abnormal(empty or invalid)
if not oss_items:
file_items, _, _ = parsing_yml(yaml_file, base_path)
# if file_items is abnormal(empty or invalid)
if not file_items:
continue

for item in oss_items:
items_to_print.extend(item.get_print_array())
if not base_path.endswith(f"{os.sep}"):
base_path += f"{os.sep}"
yaml_file = yaml_file.replace(base_path, '')
yaml_file = yaml_file.replace(os.sep, '_')
yaml_file_sheet = get_sheet_name(yaml_file, sheet_list)
tmp_yaml_file = yaml_file.replace(base_path, '')
tmp_yaml_file = tmp_yaml_file.replace(os.sep, '_')
yaml_file_sheet = get_sheet_name(tmp_yaml_file, sheet_list)

if yaml_file_sheet:
sheet_list[yaml_file_sheet] = items_to_print
header[yaml_file_sheet] = HEADER_CONTENT
scan_item.set_cover_comment(f"Converted file:{yaml_file}")
row_items = [HEADER_CONTENT]
for file_item in file_items:
row_items.extend(file_item.get_print_array())
sheet_list[yaml_file_sheet] = row_items

except Exception as ex:
logger.error(f"Read yaml file: {ex}")

try:
success, msg, result_file = write_output_file(output_file, '.xlsx', sheet_list, header)
scan_item.external_sheets = sheet_list
success, msg, result_file = write_output_file(output_file, '.xlsx', scan_item)
if success:
if result_file:
logger.warning(f"Output: {result_file}")
Expand Down
39 changes: 23 additions & 16 deletions src/fosslight_prechecker/_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ def create_result_file(output_file_name, format='', _start_time=""):
return result_file, output_path, output_extension


def get_path_in_yaml(oss_item):
path_in_yaml = [os.path.join(oss_item.relative_path, file) for file in oss_item.source_name_or_path]
def get_path_in_yaml(file_item):
path_in_yaml = [os.path.join(file_item.relative_path, file_item.source_name_or_path)]
path_in_yaml = [path.replace('\\', '/') for path in path_in_yaml]
return path_in_yaml

Expand Down Expand Up @@ -244,20 +244,27 @@ def exclude_file_in_yaml(path_to_find, yaml_files, license_missing_files, copyri
cop_present_path = []
abnormal_yaml_files = {}

for file in yaml_files:
oss_items, _, err_reason = parsing_yml(file, path_to_find, False)
# if oss_items is abnormal(empty or invalid)
if not oss_items:
abnormal_yaml_files[file] = err_reason

for oss_item in oss_items:
if oss_item.exclude:
excluded_path.extend(get_path_in_yaml(oss_item))
else:
if oss_item.license:
lic_present_path.extend(get_path_in_yaml(oss_item))
if oss_item.copyright:
cop_present_path.extend(get_path_in_yaml(oss_item))
for yaml_file in yaml_files:
file_items, _, err_reason = parsing_yml(yaml_file, path_to_find, False)
# if file_items is abnormal(empty or invalid)
if not file_items:
abnormal_yaml_files[yaml_file] = err_reason

for file_item in file_items:
license_added = False
copyright_added = False
excluded_file = False
for oss_item in file_item.oss_items:
if (not excluded_file) and oss_item.exclude:
excluded_file = True
excluded_path.extend(get_path_in_yaml(file_item))
else:
if (not license_added) and oss_item.license:
license_added = True
lic_present_path.extend(get_path_in_yaml(file_item))
if (not copyright_added) and oss_item.copyright:
copyright_added = True
cop_present_path.extend(get_path_in_yaml(file_item))

total_missing_files = list(license_missing_files.union(copyright_missing_files))
files_with_exclude_removed = extract_files_in_path(excluded_path, total_missing_files, True)
Expand Down

0 comments on commit ebec30e

Please sign in to comment.