Skip to content

Commit

Permalink
Add depends_on, purl in yaml (#155)
Browse files Browse the repository at this point in the history
Signed-off-by: Jiyeong Seok <jiyeong.seok@lge.com>
  • Loading branch information
dd-jy authored Apr 26, 2024
1 parent eef2ce5 commit 77d30ca
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 17 deletions.
56 changes: 45 additions & 11 deletions src/fosslight_util/oss_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import logging
import os
from fosslight_util.constant import LOGGER_NAME
from fosslight_util.constant import LOGGER_NAME, FL_DEPENDENCY

_logger = logging.getLogger(LOGGER_NAME)

Expand All @@ -25,6 +25,8 @@ def __init__(self, value):
self._yocto_recipe = []
self._yocto_package = []
self.is_binary = False
self._depends_on = []
self.purl = ""

def __del__(self):
pass
Expand Down Expand Up @@ -123,11 +125,29 @@ def yocto_package(self, value):
self._yocto_package = [item.strip() for item in self._yocto_package]
self._yocto_package = list(set(self._yocto_package))

def set_sheet_item(self, item):
@property
def depends_on(self):
return self._depends_on

@depends_on.setter
def depends_on(self, value):
if not value:
self._depends_on = []
else:
if not isinstance(value, list):
value = value.split(",")
self._depends_on.extend(value)
self._depends_on = [item.strip() for item in self._depends_on]
self._depends_on = list(set(self._depends_on))

def set_sheet_item(self, item, scanner_name=''):
if len(item) < 9:
_logger.warning(f"sheet list is too short ({len(item)}): {item}")
return
self.source_name_or_path = item[0]
if scanner_name == FL_DEPENDENCY:
self.purl = item[0]
else:
self.source_name_or_path = item[0]
self.name = item[1]
self.version = item[2]
self.license = item[3]
Expand All @@ -137,19 +157,29 @@ def set_sheet_item(self, item):
self.exclude = item[7]
self.comment = item[8]

def get_print_array(self):
if len(item) >= 10 and scanner_name == FL_DEPENDENCY:
self.depends_on = item[9]

def get_print_array(self, scanner_name=''):
items = []
if len(self.source_name_or_path) == 0:
self.source_name_or_path.append("")
if scanner_name != FL_DEPENDENCY:
if len(self.source_name_or_path) == 0:
self.source_name_or_path.append("")
if len(self.license) == 0:
self.license.append("")

exclude = "Exclude" if self.exclude else ""

for source_name_or_path in self.source_name_or_path:
lic = ",".join(self.license)
items.append([os.path.join(self.relative_path, source_name_or_path), self.name, self.version, lic,
self.download_location, self.homepage, self.copyright, exclude, self.comment])
lic = ",".join(self.license)
if scanner_name == FL_DEPENDENCY:
items = [self.purl, self.name, self.version, lic,
self.download_location, self.homepage, self.copyright, exclude, self.comment]
if len(self.depends_on) > 0:
items.append(",".join(self.depends_on))
else:
for source_name_or_path in self.source_name_or_path:
oss_item = [os.path.join(self.relative_path, source_name_or_path), self.name, self.version, lic,
self.download_location, self.homepage, self.copyright, exclude, self.comment]
items.append(oss_item)
return items

def get_print_json(self):
Expand All @@ -171,6 +201,10 @@ def get_print_json(self):
json_item["exclude"] = self.exclude
if self.comment != "":
json_item["comment"] = self.comment
if len(self.depends_on) > 0:
json_item["depends on"] = self.depends_on
if self.purl != "":
json_item["purl"] = self.purl

return json_item

Expand Down
17 changes: 11 additions & 6 deletions src/fosslight_util/write_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ def write_yaml(output_file, sheet_list_origin, separate_yaml=False):
for sheet_name, sheet_contents in sheet_list.items():
if sheet_name not in constant.supported_sheet_and_scanner.keys():
continue
scanner_name = constant.supported_sheet_and_scanner[sheet_name]
sheet_contents_with_scanner = []
for i in sheet_contents:
i.insert(0, scanner_name)
sheet_contents_with_scanner.append(i)
if not separate_yaml:
merge_sheet.extend(sheet_contents)
merge_sheet.extend(sheet_contents_with_scanner)
else:
output_file = f'{separate_output_file}_{sheet_name}.yaml'
convert_sheet_to_yaml(sheet_contents, output_file)
convert_sheet_to_yaml(sheet_contents_with_scanner, output_file)
output_files.append(output_file)

if not separate_yaml:
Expand All @@ -61,13 +66,13 @@ def write_yaml(output_file, sheet_list_origin, separate_yaml=False):
return success, error_msg, output


def convert_sheet_to_yaml(sheet_contents, output_file):
sheet_contents = [list(t) for t in set(tuple(e) for e in sorted(sheet_contents))]
def convert_sheet_to_yaml(sheet_contents_with_scanner, output_file):
sheet_contents_with_scanner = [list(t) for t in set(tuple(e) for e in sorted(sheet_contents_with_scanner))]

yaml_dict = {}
for sheet_item in sheet_contents:
for sheet_item in sheet_contents_with_scanner:
item = OssItem('')
item.set_sheet_item(sheet_item)
item.set_sheet_item(sheet_item[1:], sheet_item[0])
create_yaml_with_ossitem(item, yaml_dict)

with open(output_file, 'w') as f:
Expand Down

0 comments on commit 77d30ca

Please sign in to comment.