@@ -1050,7 +1050,7 @@ def from_dict(cls, about_data, base_dir=''):
10501050 about .load_dict (about_data , base_dir = base_dir )
10511051 return about
10521052
1053- def dumps (self ):
1053+ def dumps (self , licenses_dict = None ):
10541054 """
10551055 Return self as a formatted ABOUT string.
10561056 """
@@ -1064,7 +1064,6 @@ def dumps(self):
10641064 for field in self .all_fields ():
10651065 if not field .value and not field .name in bool_fields :
10661066 continue
1067-
10681067 if field .name == 'license_key' and field .value :
10691068 license_key = field .value
10701069 elif field .name == 'license_name' and field .value :
@@ -1095,10 +1094,6 @@ def dumps(self):
10951094 license_file = field .value .keys ()
10961095 elif field .name == 'license_url' and field .value :
10971096 license_url = field .value
1098-
1099- # No multiple 'about_resource' reference supported.
1100- # Take the first element (should only be one) in the list for the
1101- # value of 'about_resource'
11021097 elif field .name in file_fields and field .value :
11031098 data [field .name ] = field .original_value
11041099 elif field .name in bool_fields and not field .value == None :
@@ -1108,7 +1103,36 @@ def dumps(self):
11081103 data [field .name ] = field .value
11091104
11101105 # Group the same license information in a list
1111- license_group = list (zip_longest (license_key , license_name , license_file , license_url ))
1106+ # This `licenses_dict` is a dictionary with license key as the key and the
1107+ # value is the list of [license_name, license_context, license_url]
1108+ lic_key_dup = license_key [:]
1109+ for lic_key in license_key :
1110+ lic_dict = OrderedDict ()
1111+
1112+ if licenses_dict and lic_key in licenses_dict :
1113+ lic_dict ['key' ] = lic_key
1114+ lic_name = licenses_dict [lic_key ][0 ]
1115+ lic_url = licenses_dict [lic_key ][2 ]
1116+ lic_file = lic_key + '.LICENSE'
1117+
1118+ lic_dict ['name' ] = lic_name
1119+ lic_dict ['file' ] = lic_file
1120+ lic_dict ['url' ] = lic_url
1121+
1122+ # Remove the license information if it has been handled
1123+ #license_key.remove(lic_key)
1124+ #print(license_key)
1125+ lic_key_dup .remove (lic_key )
1126+ if lic_name in license_name :
1127+ license_name .remove (lic_name )
1128+ if lic_url in license_url :
1129+ license_url .remove (lic_url )
1130+ if lic_file in license_file :
1131+ license_file .remove (lic_file )
1132+ data .setdefault ('licenses' , []).append (lic_dict )
1133+
1134+ # Handle license information that have not been handled.
1135+ license_group = list (zip_longest (lic_key_dup , license_name , license_file , license_url ))
11121136 for lic_group in license_group :
11131137 lic_dict = OrderedDict ()
11141138 if lic_group [0 ]:
@@ -1123,7 +1147,7 @@ def dumps(self):
11231147
11241148 return saneyaml .dump (data )
11251149
1126- def dump (self , location ):
1150+ def dump (self , location , lic_dict = None ):
11271151 """
11281152 Write formatted ABOUT representation of self to location.
11291153 """
@@ -1146,7 +1170,7 @@ def dump(self, location):
11461170
11471171 with io .open (about_file_path , mode = 'w' , encoding = 'utf-8' ) as dumped :
11481172 dumped .write (genereated_tk_version )
1149- dumped .write (self .dumps ())
1173+ dumped .write (self .dumps (lic_dict ))
11501174
11511175 def dump_android_notice (self , path , context ):
11521176 """
@@ -1208,14 +1232,15 @@ def dump_lic(self, location, license_dict):
12081232 if not posixpath .exists (parent ):
12091233 os .makedirs (add_unc (parent ))
12101234
1211- if self .license_expression .present and not self . license_file . present :
1235+ if self .license_expression .present :
12121236 special_char_in_expression , lic_list = parse_license_expression (self .license_expression .value )
1213- self .license_key .value = lic_list
12141237 self .license_key .present = True
12151238 if not special_char_in_expression :
12161239 for lic_key in lic_list :
12171240 try :
12181241 if license_dict [lic_key ]:
1242+ if not lic_key in self .license_key .value :
1243+ self .license_key .value .append (lic_key )
12191244 license_path = posixpath .join (parent , lic_key )
12201245 license_path += u'.LICENSE'
12211246 license_path = add_unc (license_path )
0 commit comments