|
20 | 20 | _exclude_directory = [os.path.sep + dir_name + |
21 | 21 | os.path.sep for dir_name in _exclude_directory] |
22 | 22 | _exclude_directory.append("/.") |
| 23 | +MAX_LICENSE_LENGTH = 200 |
| 24 | +MAX_LICENSE_TOTAL_LENGTH = 600 |
| 25 | +SUBSTRING_LICENSE_COMMENT = "Maximum character limit (License)" |
23 | 26 |
|
24 | 27 |
|
25 | 28 | class ScanItem: |
@@ -74,13 +77,28 @@ def get_file(self): |
74 | 77 |
|
75 | 78 | def get_row_to_print(self): |
76 | 79 | 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 | + |
77 | 95 | 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, "", "", |
79 | 97 | "\n".join(self.copyright), "Exclude" if self.exclude else "", self.comment, |
80 | 98 | self.license_reference]) |
81 | 99 | else: |
82 | 100 | 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, "", |
84 | 102 | "\n".join(self.copyright), "Exclude" if self.exclude else "", self.comment, |
85 | 103 | self.license_reference]) |
86 | 104 | return print_rows |
|
0 commit comments