Skip to content

Commit 7dacab1

Browse files
authored
Merge pull request #157 from fosslight/max_lic
Limit the maximum number of characters in the license
2 parents 295893d + fd9c642 commit 7dacab1

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/fosslight_source/_scan_item.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
_exclude_directory = [os.path.sep + dir_name +
2121
os.path.sep for dir_name in _exclude_directory]
2222
_exclude_directory.append("/.")
23+
MAX_LICENSE_LENGTH = 200
24+
MAX_LICENSE_TOTAL_LENGTH = 600
25+
SUBSTRING_LICENSE_COMMENT = "Maximum character limit (License)"
2326

2427

2528
class ScanItem:
@@ -74,13 +77,28 @@ def get_file(self):
7477

7578
def get_row_to_print(self):
7679
print_rows = []
80+
licenses = []
81+
max_length_exceed = False
82+
for lic in self.licenses:
83+
if len(lic) > MAX_LICENSE_LENGTH:
84+
lic = lic[:MAX_LICENSE_LENGTH]
85+
max_length_exceed = True
86+
licenses.append(lic)
87+
str_license = ",".join(licenses)
88+
if len(str_license) > MAX_LICENSE_TOTAL_LENGTH:
89+
max_length_exceed = True
90+
str_license = str_license[:MAX_LICENSE_TOTAL_LENGTH]
91+
92+
if max_length_exceed:
93+
self.comment = f"{self.comment}/ {SUBSTRING_LICENSE_COMMENT}" if self.comment else SUBSTRING_LICENSE_COMMENT
94+
7795
if not self.download_location:
78-
print_rows.append([self.file, self.oss_name, self.oss_version, ','.join(self.licenses), "", "",
96+
print_rows.append([self.file, self.oss_name, self.oss_version, str_license, "", "",
7997
"\n".join(self.copyright), "Exclude" if self.exclude else "", self.comment,
8098
self.license_reference])
8199
else:
82100
for url in self.download_location:
83-
print_rows.append([self.file, self.oss_name, self.oss_version, ','.join(self.licenses), url, "",
101+
print_rows.append([self.file, self.oss_name, self.oss_version, str_license, url, "",
84102
"\n".join(self.copyright), "Exclude" if self.exclude else "", self.comment,
85103
self.license_reference])
86104
return print_rows

0 commit comments

Comments
 (0)