|
20 | 20 | import csv |
21 | 21 | from datetime import datetime |
22 | 22 | from email.parser import HeaderParser |
| 23 | +from os.path import dirname, join |
23 | 24 | import errno |
24 | 25 | import httplib |
25 | 26 | import logging |
@@ -749,7 +750,6 @@ def validate_about_resource_exist(self): |
749 | 750 | self.errors.append(Error(FILE, about_resource, |
750 | 751 | self.about_resource, |
751 | 752 | 'File does not exist.')) |
752 | | - |
753 | 753 | self._save_location(about_resource, self.about_resource) |
754 | 754 |
|
755 | 755 | def validate_file_field_exists(self, field_name, file_path): |
@@ -974,6 +974,20 @@ def duplicate_file_names_when_lowercased(file_location): |
974 | 974 | names.append(name) |
975 | 975 | return names |
976 | 976 |
|
| 977 | + def tmp_get_license_text(self): |
| 978 | + # TODO: This is a temp fix for handling multiple 'license_text_file' |
| 979 | + # The code should get the license text from the def license_text(self), |
| 980 | + # not this function. |
| 981 | + license_text = "" |
| 982 | + licenses = self.parsed.get('license_text_file', '') |
| 983 | + license_list = licenses.split('\n ') |
| 984 | + for lic in license_list: |
| 985 | + location = join(dirname(self.location), lic) |
| 986 | + with open(location, 'rU') as f: |
| 987 | + license_text += f.read() |
| 988 | + license_text += '\n\n\n\n\n\n' |
| 989 | + return license_text |
| 990 | + |
977 | 991 | def license_text(self): |
978 | 992 | """ |
979 | 993 | Return the license text if the license_text_file field exists and the |
@@ -1175,12 +1189,19 @@ def generate_attribution(self, template_path=None, limit_to=None): |
1175 | 1189 | about_content_dict = about_object.validated_fields |
1176 | 1190 | # Add information in the dictionary where it does not |
1177 | 1191 | # present in the ABOUT file |
1178 | | - about_content_dict['license_text_content'] = unicode(about_object.license_text(), |
| 1192 | + about_content_dict['license_text'] = unicode(about_object.license_text(), |
| 1193 | + errors='replace') |
| 1194 | + about_content_dict['notice_text'] = about_object.notice_text() |
| 1195 | + |
| 1196 | + # FIXME: The following is a tmp code to handle multiple |
| 1197 | + # 'license_text_file' in the input |
| 1198 | + for k in about_content_dict: |
| 1199 | + if '\n' in about_content_dict[k] and k == 'license_text_file': |
| 1200 | + about_content_dict['license_text'] = unicode(about_object.tmp_get_license_text(), |
1179 | 1201 | errors='replace') |
1180 | | - about_content_dict['notice_text_content'] = about_object.notice_text() |
1181 | 1202 |
|
1182 | 1203 | # Raise error if no license_text is found |
1183 | | - if not about_content_dict['license_text_content']: |
| 1204 | + if not about_content_dict['license_text']: |
1184 | 1205 | msg = ('No license_text is found. ' |
1185 | 1206 | 'License generation is skipped.') |
1186 | 1207 | err = Error(GENATTRIB, 'name', |
|
0 commit comments