@@ -1270,49 +1270,81 @@ def generate_attribution(self, template_path=None, limit_to=None):
12701270 not_process_components = list (limit_to )
12711271 component_exist = False
12721272
1273- for component in not_process_components :
1273+ # Following code contains duplication and perhaps needs to do some
1274+ # refactoring
1275+ if limit_to :
1276+ for component in not_process_components :
1277+ for about_object in self :
1278+ # The about_object.location is the absolute path of the ABOUT
1279+ # file. The purpose of the following partition is to match
1280+ # the about_file's location with the input list.
1281+ about_relative_path = about_object .location .partition (
1282+ normpath (self .location ))[2 ]
1283+
1284+ if component == about_relative_path :
1285+ component_exist = True
1286+ about_content = about_object .validated_fields
1287+ if '\n ' in about_object .get_dje_license_name ():
1288+ msg = ('Multiple licenses is not supported. '
1289+ 'Skipping License generation.' )
1290+ err = Error (GENATTRIB , 'dje_license' ,
1291+ about_object .get_dje_license_name (), msg )
1292+ self .genattrib_errors .append (err )
1293+
1294+ lic_text = unicode (about_object .license_text (),
1295+ errors = 'replace' )
1296+ notice_text = unicode (about_object .notice_text (),
1297+ errors = 'replace' )
1298+ about_content ['license_text' ] = lic_text
1299+ about_content ['notice_text' ] = notice_text
1300+
1301+ license_dict [about_object .get_dje_license_name ()] = about_content ['license_text' ]
1302+
1303+ # report error if no license_text is found
1304+ if not about_content .get ('license_text' )\
1305+ and not about_content .get ('notice_text' )\
1306+ and not '\n ' in about_object .get_dje_license_name ():
1307+ msg = ('No license_text found. '
1308+ 'Skipping License generation.' )
1309+ err = Error (GENATTRIB , 'name' ,
1310+ about_object .get_about_name (), msg )
1311+ self .genattrib_errors .append (err )
1312+ about_object_fields .append (about_content )
1313+ break
1314+ if not component_exist :
1315+ msg = ('The requested ABOUT file: %r does not exist. '
1316+ 'No attribution generated for this file.' % component )
1317+ err = Error (GENATTRIB , 'about_file' , component , msg )
1318+ self .genattrib_errors .append (err )
1319+ else :
12741320 for about_object in self :
1275- # The about_object.location is the absolute path of the ABOUT
1276- # file. The purpose of the following partition is to match
1277- # the about_file's location with the input list.
1278- about_relative_path = about_object .location .partition (
1279- normpath (self .location ))[2 ]
1280-
1281- if component == about_relative_path :
1282- component_exist = True
1283- about_content = about_object .validated_fields
1284- if '\n ' in about_object .get_dje_license_name ():
1285- msg = ('Multiple licenses is not supported. '
1286- 'Skipping License generation.' )
1287- err = Error (GENATTRIB , 'dje_license' ,
1288- about_object .get_dje_license_name (), msg )
1289- self .genattrib_errors .append (err )
1290-
1291- lic_text = unicode (about_object .license_text (),
1292- errors = 'replace' )
1293- notice_text = unicode (about_object .notice_text (),
1294- errors = 'replace' )
1295- about_content ['license_text' ] = lic_text
1296- about_content ['notice_text' ] = notice_text
1297-
1298- license_dict [about_object .get_dje_license_name ()] = about_content ['license_text' ]
1299-
1300- # report error if no license_text is found
1301- if not about_content .get ('license_text' )\
1302- and not about_content .get ('notice_text' )\
1303- and not '\n ' in about_object .get_dje_license_name ():
1304- msg = ('No license_text found. '
1305- 'Skipping License generation.' )
1306- err = Error (GENATTRIB , 'name' ,
1307- about_object .get_about_name (), msg )
1308- self .genattrib_errors .append (err )
1309- about_object_fields .append (about_content )
1310- break
1311- if not component_exist :
1312- msg = ('The requested ABOUT file: %r does not exist. '
1313- 'No attribution generated for this file.' % component )
1314- err = Error (GENATTRIB , 'about_file' , component , msg )
1315- self .genattrib_errors .append (err )
1321+ about_content = about_object .validated_fields
1322+ if '\n ' in about_object .get_dje_license_name ():
1323+ msg = ('Multiple licenses is not supported. '
1324+ 'Skipping License generation.' )
1325+ err = Error (GENATTRIB , 'dje_license' ,
1326+ about_object .get_dje_license_name (), msg )
1327+ self .genattrib_errors .append (err )
1328+
1329+ lic_text = unicode (about_object .license_text (),
1330+ errors = 'replace' )
1331+ notice_text = unicode (about_object .notice_text (),
1332+ errors = 'replace' )
1333+ about_content ['license_text' ] = lic_text
1334+ about_content ['notice_text' ] = notice_text
1335+
1336+ license_dict [about_object .get_dje_license_name ()] = about_content ['license_text' ]
1337+
1338+ # report error if no license_text is found
1339+ if not about_content .get ('license_text' )\
1340+ and not about_content .get ('notice_text' )\
1341+ and not '\n ' in about_object .get_dje_license_name ():
1342+ msg = ('No license_text found. '
1343+ 'Skipping License generation.' )
1344+ err = Error (GENATTRIB , 'name' ,
1345+ about_object .get_about_name (), msg )
1346+ self .genattrib_errors .append (err )
1347+ about_object_fields .append (about_content )
13161348
13171349 # We want to display common_licenses in alphabetical order
13181350 license_key = []
0 commit comments