@@ -971,6 +971,16 @@ def get_license_text_file_name(self):
971971 pass
972972 return ""
973973
974+ def get_license_text (self ):
975+ """
976+ Return the license_text if the license_text field exists
977+ """
978+ try :
979+ return self .parsed ['license_text' ]
980+ except Exception as e :
981+ pass
982+ return ""
983+
974984 def get_about_name (self ):
975985 """
976986 Return the about object's name
@@ -1128,10 +1138,8 @@ def generate_attribution(self, template_path=None, limit_to=None):
11281138 validated_fields = []
11291139 notice_text = []
11301140 license_key = []
1131- license_text = []
1141+ license_text_list = []
11321142 license_dict = {}
1133- license_text_file_name = []
1134- license_text_file_content = []
11351143 not_exist_components = list (limit_to )
11361144
11371145 for about_object in self :
@@ -1149,76 +1157,35 @@ def generate_attribution(self, template_path=None, limit_to=None):
11491157 notice_text .append (about_object .notice_text ())
11501158 dje_license_name = about_object .get_dje_license_name ()
11511159 license_text_file = about_object .get_license_text_file_name ()
1160+ license_text = about_object .get_license_text ()
11521161 if license_text_file :
1153- # Check if the 'license_text_file' was generated from the
1154- # extract_license option. If the 'license_text_file' is
1155- # not extracted from DJE and is in the original codebase,
1156- # then, the dict key's name should me 'name' + 'license_text_file'
1157- # We can check if the 'license_text_file' was generated from
1158- # extract_license option by checking if it ends with '.LICENSE'
1159-
1160- # UPDATE: There may be cases that components have the same
1161- # about name and 'license_text_file' name but different
1162- # content in the 'license_text_file'.
1163- # As a result, we need to raise error if this is the case
1162+ # Check if the license key, license_text_file, already
1163+ # exist in the license dictionary
11641164 if license_text_file in license_dict :
1165- # Check if the content are the same
1166- if license_dict [license_text_file ] == unicode (about_object .license_text (), errors = 'replace' ):
1165+ # Raise error if key name are the same but the content
1166+ # are different
1167+ license_text_check = license_dict [license_text_file ]
1168+ if not unicode (license_text_check ) == unicode (about_object .license_text ()):
11671169 msg = 'License Name: %s - Same license name with different content.' \
11681170 ' License generation is skipped.' \
11691171 % license_text_file
11701172 self .genattrib_errors .append (Error (GENATTRIB ,\
11711173 'license_text' ,\
11721174 license_text_file , msg ))
1173- break
1174-
1175- if license_text_file .endswith ('.LICENSE' ):
1176- license_dict [license_text_file ] = unicode (about_object .license_text (), errors = 'replace' )
11771175 else :
1178- license_name = about_object .get_about_name () + '_' + license_text_file
1179- license_dict [license_name ] = unicode (about_object .license_text (), errors = 'replace' )
1180-
1181- """
1182- if about_object.license_text():
1183- license_text_file_name.append(license_text_file)
1184- license_text_file_content.append(unicode(about_object.license_text(), errors='replace'))
1185- else:
1186- msg = 'Name: %s - license_text does not exist.'\
1187- ' License generation is skipped.'\
1188- % about_object.get_about_name()
1189- self.genattrib_errors.append(Error(GENATTRIB,\
1190- 'license_text',\
1191- license_text_file, msg))
1192- """
1193- # Following code are useless as the 'license_text_file' is needed
1194- # to grab the license for attribution generation.
1195- # If there is no 'license_text_file' key or value, the tool
1196- # should throw an error
1197- """
1198- if dje_license_name:
1199- if not dje_license_name in license_dict \
1200- and not dje_license_name == None:
1201- if about_object.license_text():
1202- license_dict[about_object.get_dje_license_name()] = unicode(about_object.license_text(), errors='replace')
1203- else:
1204- msg = 'Name: %s - license_text does not exist.'\
1205- ' License generation is skipped.'\
1206- % about_object.get_about_name()
1207- self.genattrib_errors.append(Error(GENATTRIB,\
1208- 'dje_license',\
1209- dje_license_name, msg))
1210- elif about_object.get_license_text_file_name():
1211- if not about_object.get_license_text_file_name() in license_dict:
1212- if about_object.license_text():
1213- license_dict[about_object.get_license_text_file_name()] = unicode(about_object.license_text(), errors='replace')
1214- else:
1215- msg = 'Name: %s - license_text does not exist.'\
1216- ' License generation is skipped.'\
1217- % about_object.get_about_name()
1218- self.genattrib_errors.append(Error(GENATTRIB,\
1219- 'license_text',\
1220- about_object.get_license_text_file_name(), msg))
1221- """
1176+ if license_text_file .endswith ('.LICENSE' ):
1177+ license_dict [license_text_file ] = unicode (about_object .license_text (), errors = 'replace' )
1178+ else :
1179+ # If the 'license_text_file' doesn't end with '.LICENSE',
1180+ # such as COPYING, COPYRIGHT, we will use the name
1181+ # of the About file combine with the 'license_text_file'
1182+ # as the key of the license dictionary.
1183+ license_name = about_object .get_about_name () + '_' + license_text_file
1184+ license_dict [license_name ] = unicode (about_object .license_text (), errors = 'replace' )
1185+ elif license_text :
1186+ # We don't need to do anything here as the license_text
1187+ # will be capture directly in the about object.
1188+ pass
12221189 else :
12231190 msg = 'No license_text is found. License generation is skipped.'
12241191 self .genattrib_errors .append (Error (GENATTRIB , 'name' ,\
@@ -1236,11 +1203,11 @@ def generate_attribution(self, template_path=None, limit_to=None):
12361203 # We want the license generation in alphabetical order
12371204 for key in sorted (license_dict .keys ()):
12381205 license_key .append (key )
1239- license_text .append (license_dict [key ])
1206+ license_text_list .append (license_dict [key ])
12401207
12411208 return template .render (about_objects = validated_fields ,
12421209 license_keys = license_key ,
1243- license_texts = license_text ,
1210+ license_texts = license_text_list ,
12441211 #license_keys=license_text_file_name,
12451212 #license_texts = license_text_file_content,
12461213 notice_texts = notice_text ,
0 commit comments