@@ -1245,7 +1245,6 @@ def generate_attribution(self, template_path=None, limit_to=None):
12451245 'attribution texts. You can install it by running:'
12461246 '"configure"' )
12471247 return
1248-
12491248 # For some reasons, if I set the template_path = "templates/default.html"
12501249 # in the parameter, the tempalte_path will become 'None' and cause error
12511250 if not template_path :
@@ -1257,7 +1256,6 @@ def generate_attribution(self, template_path=None, limit_to=None):
12571256 template_file_name = basename (template_path )
12581257 loader = j2 .FileSystemLoader (template_dir )
12591258 jinja_env = j2 .Environment (loader = loader )
1260-
12611259 try :
12621260 template = jinja_env .get_template (template_file_name )
12631261 except j2 .TemplateNotFound :
@@ -1270,12 +1268,66 @@ def generate_attribution(self, template_path=None, limit_to=None):
12701268 about_content_dict = {}
12711269
12721270 not_process_components = list (limit_to )
1273-
12741271 component_exist = False
12751272
12761273 # ToDo: temp fix to have correct order in the attribution generation based on
12771274 # the input
1278- for component in not_process_components :
1275+ # In addition, if user doesn't provide the component list a.k.a the
1276+ # limit_to, this code will never work.
1277+ # ToDo: This code need to be refactor. Too many duplicated code.
1278+ if not_process_components :
1279+ for component in not_process_components :
1280+ for about_object in self :
1281+ # FIXME: what is the meaning of this partition?
1282+ # PO created the var some_path to provide some clarity
1283+ # but what does the second element means?
1284+ file_name = about_object .location .partition (self .location )[2 ]
1285+ # FIXME: a path starting with / is NOT relative
1286+ about_relative_path = '/' + file_name
1287+ """if limit_to:
1288+ try:
1289+ not_process_components.remove(about_relative_path)
1290+ except Exception as e:
1291+ continue"""
1292+
1293+ #if limit_to and about_relative_path in limit_to:
1294+ # continue
1295+ if component == about_relative_path :
1296+ component_exist = True
1297+ about_content = about_object .validated_fields
1298+ # Add information in the dictionary if not in the ABOUT file
1299+ lic_text = unicode (about_object .license_text (),
1300+ errors = 'replace' )
1301+
1302+ about_content ['license_text' ] = lic_text
1303+ notice_text = about_object .notice_text ()
1304+ about_content ['notice_text' ] = notice_text
1305+
1306+ # FIXME: The following is temporary code to handle multiple
1307+ # license_text_file paths in the field value, one per lne
1308+ for k in about_content :
1309+ if ('\n ' in about_content [k ]
1310+ and k == 'license_text_file' ):
1311+ # FIXME: we should report decoding errors
1312+ lic_text = unicode (about_object .tmp_get_license_text (),
1313+ errors = 'replace' )
1314+ about_content ['license_text' ] = lic_text
1315+
1316+ # report error if no license_text is found
1317+ if not about_content .get ('license_text' ):
1318+ msg = ('No license_text found. '
1319+ 'Skipping License generation.' )
1320+ err = Error (GENATTRIB , 'name' ,
1321+ about_object .get_about_name (), msg )
1322+ self .genattrib_errors .append (err )
1323+ about_object_fields .append (about_content )
1324+ break
1325+ if not component_exist :
1326+ msg = ('The requested ABOUT file: %r does not exist. '
1327+ 'No attribution generated for this file.' % component )
1328+ err = Error (GENATTRIB , 'about_file' , component , msg )
1329+ self .genattrib_errors .append (err )
1330+ else :
12791331 for about_object in self :
12801332 # FIXME: what is the meaning of this partition?
12811333 # PO created the var some_path to provide some clarity
@@ -1288,44 +1340,35 @@ def generate_attribution(self, template_path=None, limit_to=None):
12881340 not_process_components.remove(about_relative_path)
12891341 except Exception as e:
12901342 continue"""
1291-
1292- #if limit_to and about_relative_path in limit_to:
1293- # continue
1294- if component == about_relative_path :
1295- component_exist = True
1296- about_content = about_object .validated_fields
1297- # Add information in the dictionary if not in the ABOUT file
1298- lic_text = unicode (about_object .license_text (),
1299- errors = 'replace' )
1300-
1301- about_content ['license_text' ] = lic_text
1302- notice_text = about_object .notice_text ()
1303- about_content ['notice_text' ] = notice_text
1304-
1305- # FIXME: The following is temporary code to handle multiple
1306- # license_text_file paths in the field value, one per lne
1307- for k in about_content :
1308- if ('\n ' in about_content [k ]
1309- and k == 'license_text_file' ):
1310- # FIXME: we should report decoding errors
1311- lic_text = unicode (about_object .tmp_get_license_text (),
1312- errors = 'replace' )
1313- about_content ['license_text' ] = lic_text
1314-
1315- # report error if no license_text is found
1316- if not about_content .get ('license_text' ):
1317- msg = ('No license_text found. '
1318- 'Skipping License generation.' )
1319- err = Error (GENATTRIB , 'name' ,
1320- about_object .get_about_name (), msg )
1321- self .genattrib_errors .append (err )
1322- about_object_fields .append (about_content )
1323- break
1324- if not component_exist :
1325- msg = ('The requested ABOUT file: %r does not exist. '
1326- 'No attribution generated for this file.' % component )
1327- err = Error (GENATTRIB , 'about_file' , component , msg )
1328- self .genattrib_errors .append (err )
1343+
1344+ about_content = about_object .validated_fields
1345+ # Add information in the dictionary if not in the ABOUT file
1346+ lic_text = unicode (about_object .license_text (),
1347+ errors = 'replace' )
1348+
1349+ about_content ['license_text' ] = lic_text
1350+ notice_text = about_object .notice_text ()
1351+ about_content ['notice_text' ] = notice_text
1352+
1353+ # FIXME: The following is temporary code to handle multiple
1354+ # license_text_file paths in the field value, one per lne
1355+ for k in about_content :
1356+ if ('\n ' in about_content [k ]
1357+ and k == 'license_text_file' ):
1358+ # FIXME: we should report decoding errors
1359+ lic_text = unicode (about_object .tmp_get_license_text (),
1360+ errors = 'replace' )
1361+ about_content ['license_text' ] = lic_text
1362+
1363+ # report error if no license_text is found
1364+ if not about_content .get ('license_text' ):
1365+ msg = ('No license_text found. '
1366+ 'Skipping License generation.' )
1367+ err = Error (GENATTRIB , 'name' ,
1368+ about_object .get_about_name (), msg )
1369+ self .genattrib_errors .append (err )
1370+ about_object_fields .append (about_content )
1371+ break
13291372
13301373 """# find paths requested in the limit_to paths arg that do not point to
13311374 # a corresponding ABOUT file
0 commit comments