Skip to content

Commit e8c69e1

Browse files
authored
Merge pull request #158 from fosslight/max_lic
Move method to limit license characters
2 parents 8b068fb + 6e563a7 commit e8c69e1

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

src/fosslight_source/_scan_item.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,37 +68,33 @@ def licenses(self):
6868

6969
@licenses.setter
7070
def licenses(self, value):
71-
self._licenses.extend(value)
72-
if len(self._licenses) > 0:
73-
self._licenses = list(set(self._licenses))
71+
if value:
72+
max_length_exceed = False
73+
for new_lic in value:
74+
if new_lic not in self._licenses:
75+
if len(new_lic) > MAX_LICENSE_LENGTH:
76+
new_lic = new_lic[:MAX_LICENSE_LENGTH]
77+
max_length_exceed = True
78+
self._licenses.append(new_lic)
79+
if len(",".join(self._licenses)) > MAX_LICENSE_TOTAL_LENGTH:
80+
self._licenses.remove(new_lic)
81+
max_length_exceed = True
82+
break
83+
if max_length_exceed and (SUBSTRING_LICENSE_COMMENT not in self.comment):
84+
self.comment = f"{self.comment}/ {SUBSTRING_LICENSE_COMMENT}" if self.comment else SUBSTRING_LICENSE_COMMENT
7485

7586
def get_file(self):
7687
return self.file
7788

7889
def get_row_to_print(self):
7990
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-
9591
if not self.download_location:
96-
print_rows.append([self.file, self.oss_name, self.oss_version, str_license, "", "",
92+
print_rows.append([self.file, self.oss_name, self.oss_version, ",".join(self.licenses), "", "",
9793
"\n".join(self.copyright), "Exclude" if self.exclude else "", self.comment,
9894
self.license_reference])
9995
else:
10096
for url in self.download_location:
101-
print_rows.append([self.file, self.oss_name, self.oss_version, str_license, url, "",
97+
print_rows.append([self.file, self.oss_name, self.oss_version, ",".join(self.licenses), url, "",
10298
"\n".join(self.copyright), "Exclude" if self.exclude else "", self.comment,
10399
self.license_reference])
104100
return print_rows

0 commit comments

Comments
 (0)