@@ -402,16 +402,16 @@ def repr_problem(obj):
402402
403403# Use DJE License Name
404404COMMON_LICENSES = (
405- 'Apache License 2.0' ,
406- 'BSD-Modified ' ,
407- 'BSD-Original ' ,
408- 'BSD-Original-UC ' ,
409- 'GNU General Public License 2.0' ,
410- 'GNU General Public License 3.0' ,
411- 'GNU Lesser General Public License 2.1' ,
412- 'Net SNMP License ' ,
413- 'OpenSSL/SSLeay License ' ,
414- 'ZLIB License ' ,
405+ 'apache- 2.0.LICENSE ' ,
406+ 'bsd-new.LICENSE ' ,
407+ 'bsd-original.LICENSE ' ,
408+ 'bsd-original-uc.LICENSE ' ,
409+ 'gpl- 2.0.LICENSE ' ,
410+ 'gpl- 3.0.LICENSE ' ,
411+ 'lgpl- 2.1.LICENSE ' ,
412+ 'net-snmp.LICENSE ' ,
413+ 'openssl-ssleay.LICENSE ' ,
414+ 'zlib.LICENSE ' ,
415415)
416416
417417# Maps lowercase id to standard ids with official case
@@ -1130,6 +1130,8 @@ def generate_attribution(self, template_path=None, limit_to=None):
11301130 license_key = []
11311131 license_text = []
11321132 license_dict = {}
1133+ license_text_file_name = []
1134+ license_text_file_content = []
11331135 not_exist_components = list (limit_to )
11341136
11351137 for about_object in self :
@@ -1146,31 +1148,79 @@ def generate_attribution(self, template_path=None, limit_to=None):
11461148 validated_fields .append (about_object .validated_fields )
11471149 notice_text .append (about_object .notice_text ())
11481150 dje_license_name = about_object .get_dje_license_name ()
1149- if dje_license_name :
1150- if not dje_license_name in license_dict \
1151- and not dje_license_name == None :
1152- if about_object .license_text ():
1153- license_dict [about_object .get_dje_license_name ()] = unicode (about_object .license_text (), errors = 'replace' )
1154- else :
1155- msg = 'Name: %s - license_text does not exist.' \
1151+ license_text_file = about_object .get_license_text_file_name ()
1152+ 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
1164+ 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' ):
1167+ msg = 'License Name: %s - Same license name with different content.' \
11561168 ' License generation is skipped.' \
1157- % about_object . get_about_name ()
1169+ % license_text_file
11581170 self .genattrib_errors .append (Error (GENATTRIB ,\
1159- 'dje_license' ,\
1160- dje_license_name , msg ))
1161- elif about_object .get_license_text_file_name ():
1162- if not about_object .get_license_text_file_name () in license_dict :
1163- if about_object .license_text ():
1164- license_dict [about_object .get_license_text_file_name ()] = unicode (about_object .license_text (), errors = 'replace' )
1165- else :
1166- msg = 'Name: %s - license_text does not exist.' \
1171+ 'license_text' ,\
1172+ 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' )
1177+ 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.'\
11671187 ' License generation is skipped.'\
11681188 % about_object.get_about_name()
1169- self .genattrib_errors .append (Error (GENATTRIB ,\
1170- 'license_text' ,\
1171- about_object .get_license_text_file_name (), msg ))
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+ """
11721222 else :
1173- msg = 'No dje_license or license_text is found. License generation is skipped.'
1223+ msg = 'No license_text is found. License generation is skipped.'
11741224 self .genattrib_errors .append (Error (GENATTRIB , 'name' ,\
11751225 about_object .get_about_name (),\
11761226 msg ))
@@ -1191,6 +1241,8 @@ def generate_attribution(self, template_path=None, limit_to=None):
11911241 return template .render (about_objects = validated_fields ,
11921242 license_keys = license_key ,
11931243 license_texts = license_text ,
1244+ #license_keys=license_text_file_name,
1245+ #license_texts = license_text_file_content,
11941246 notice_texts = notice_text ,
11951247 license_dicts = license_dict ,
11961248 common_licenses = COMMON_LICENSES )
0 commit comments