@@ -951,16 +951,6 @@ def notice_text(self):
951951
952952 return "" # Returns empty string if the notice file does not exist
953953
954- def get_dje_license_name (self ):
955- """
956- Return the dje_license value if the dje_license field exists
957- """
958- try :
959- return self .parsed ['dje_license_name' ]
960- except Exception as e :
961- pass
962- return ""
963-
964954 def get_license_text_file_name (self ):
965955 """
966956 Return the license_text_file name if the license_text_file field exists
@@ -991,6 +981,16 @@ def get_about_name(self):
991981 pass
992982 return ""
993983
984+ def get_about_resource_path (self ):
985+ """
986+ Return the about object's name
987+ """
988+ try :
989+ return self .parsed ['about_resource_path' ]
990+ except Exception as e :
991+ pass
992+ return ""
993+
994994class AboutCollector (object ):
995995 """
996996 A collection of AboutFile instances.
@@ -1140,6 +1140,7 @@ def generate_attribution(self, template_path=None, limit_to=None):
11401140 license_key = []
11411141 license_text_list = []
11421142 license_dict = {}
1143+ common_license_dict = {}
11431144 not_exist_components = list (limit_to )
11441145
11451146 for about_object in self :
@@ -1155,16 +1156,24 @@ def generate_attribution(self, template_path=None, limit_to=None):
11551156 if not limit_to or about_relative_path in limit_to :
11561157 validated_fields .append (about_object .validated_fields )
11571158 notice_text .append (about_object .notice_text ())
1158- dje_license_name = about_object .get_dje_license_name ()
11591159 license_text_file = about_object .get_license_text_file_name ()
1160- license_text = about_object .get_license_text ()
1160+ about_resource_path = about_object .get_about_resource_path ()
1161+ if not about_resource_path :
1162+ msg = 'About File: %s - The required field, about_resource_path, not found' \
1163+ ' License generation is skipped.' \
1164+ % about_object .location
1165+ self .genattrib_errors .append (Error (GENATTRIB ,\
1166+ 'about_resource' ,\
1167+ about_object .location , msg ))
11611168 if license_text_file :
1162- # Check if the license key, license_text_file, already
1163- # exist in the license dictionary
1164- if license_text_file in license_dict :
1169+ # Use the about_file_path as the key
1170+ # Check if the key already existed in the dictionary
1171+ # This shouldn't be reached as the 'about_resource_path'
1172+ # should be unique.
1173+ if about_resource_path in license_dict :
11651174 # Raise error if key name are the same but the content
11661175 # are different
1167- license_text_check = license_dict [license_text_file ]
1176+ license_text_check = license_dict [about_resource_path ]
11681177 if not unicode (license_text_check ) == unicode (about_object .license_text ()):
11691178 msg = 'License Name: %s - Same license name with different content.' \
11701179 ' License generation is skipped.' \
@@ -1173,18 +1182,12 @@ def generate_attribution(self, template_path=None, limit_to=None):
11731182 'license_text' ,\
11741183 license_text_file , msg ))
11751184 else :
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 :
1185+ license_dict [about_resource_path ] = unicode (about_object .license_text (), errors = 'replace' )
1186+ if license_text_file in COMMON_LICENSES :
1187+ common_license_dict [license_text_file ] = unicode (about_object .license_text (), errors = 'replace' )
1188+ elif about_object .get_license_text ():
11861189 # We don't need to do anything here as the license_text
1187- # will be capture directly in the about object.
1190+ # will be captured directly in the about object.
11881191 pass
11891192 else :
11901193 msg = 'No license_text is found. License generation is skipped.'
@@ -1200,16 +1203,14 @@ def generate_attribution(self, template_path=None, limit_to=None):
12001203 self .genattrib_errors .append (Error (GENATTRIB , 'about_file' ,\
12011204 component , msg ))
12021205
1203- # We want the license generation in alphabetical order
1204- for key in sorted (license_dict .keys ()):
1206+ # We want to display common_licenses in alphabetical order
1207+ for key in sorted (common_license_dict .keys ()):
12051208 license_key .append (key )
1206- license_text_list .append (license_dict [key ])
1209+ license_text_list .append (common_license_dict [key ])
12071210
12081211 return template .render (about_objects = validated_fields ,
12091212 license_keys = license_key ,
12101213 license_texts = license_text_list ,
1211- #license_keys=license_text_file_name,
1212- #license_texts = license_text_file_content,
12131214 notice_texts = notice_text ,
12141215 license_dicts = license_dict ,
12151216 common_licenses = COMMON_LICENSES )
0 commit comments