@@ -1026,8 +1026,8 @@ def license_text(self):
10261026 Return the license text if the license_text_file field exists and the
10271027 field value (file) exists.
10281028 """
1029- location = self .file_fields_locations .get ('license_text_file' , '' )
1030- if location :
1029+ location = self .file_fields_locations .get ('license_text_file' ,)
1030+ if location and os . path . exists ( location ) :
10311031 try :
10321032 with open (location , 'rU' ) as f :
10331033 return f .read ()
@@ -1194,7 +1194,8 @@ def write_to_csv(self, output_path):
11941194 row_data = about_object .get_row_data (relative_path )
11951195 csv_writer .writerow (row_data )
11961196
1197- def generate_attribution (self , template_path = 'templates/default.html' ,
1197+ def generate_attribution (self ,
1198+ template_path = 'templates/default.html' ,
11981199 limit_to = None ):
11991200 """
12001201 Generate an attribution file from the current list of ABOUT objects.
@@ -1204,26 +1205,27 @@ def generate_attribution(self, template_path='templates/default.html',
12041205
12051206 try :
12061207 import jinja2 as j2
1207- except ImportError , e :
1208+ except ImportError :
12081209 print ('The Jinja2 templating library is required to generate '
12091210 'attribution texts. You can install it by running:'
1210- 'configure' )
1211+ '" configure" ' )
12111212 return
12121213
12131214 # FIXME: the template dir should be outside the code tree
12141215 template_dir = os .path .dirname (template_path )
12151216 template_file_name = os .path .basename (template_path )
1216-
1217- jinja_env = j2 .Environment (loader = j2 . FileSystemLoader ( template_dir ) )
1217+ loader = j2 . FileSystemLoader ( template_dir )
1218+ jinja_env = j2 .Environment (loader = loader )
12181219
12191220 try :
12201221 template = jinja_env .get_template (template_file_name )
1221- except j2 .TemplateNotFound , e :
1222+ except j2 .TemplateNotFound :
12221223 print ('Template: %(template_file_name)s not found' % locals ())
12231224 return
12241225
12251226 limit_to = limit_to or []
12261227 limit_to = set (limit_to )
1228+ print ('limit_to:' , limit_to )
12271229
12281230 about_object_fields = []
12291231 about_content_dict = {}
@@ -1232,48 +1234,55 @@ def generate_attribution(self, template_path='templates/default.html',
12321234 # FIXME: what is the meaning of this partition?
12331235 # PO created the var some_path to provide some clarity
12341236 # but what does the second element means?
1235- some_path = about_object .location .partition (self .location )[2 ]
1236- about_relative_path = '/' + some_path
1237- print ('some_path:' , some_path )
1237+ file_name = about_object .location .partition (self .location )[2 ]
1238+ # FIXME: a path starting with / is NOT relative
1239+ about_relative_path = '/' + file_name
1240+ print ('file_name:' , file_name )
12381241
12391242 if limit_to and about_relative_path in limit_to :
12401243 continue
12411244
1242- about_content_dict = about_object .validated_fields
1243- print ('about_content_dict:' , about_content_dict )
1244- # Add information in the dictionary where it does not
1245- # present in the ABOUT file
1245+ about_content = about_object .validated_fields
1246+ print ('about_content 1:' , about_content )
1247+ # Add information in the dictionary if not in the ABOUT file
12461248 lic_text = unicode (about_object .license_text (),
12471249 errors = 'replace' )
1248- about_content_dict ['license_text' ] = lic_text
1250+
1251+ print ('lic_text:' , lic_text )
1252+ about_content ['license_text' ] = lic_text
12491253 notice_text = about_object .notice_text ()
1250- about_content_dict ['notice_text' ] = notice_text
1254+ about_content ['notice_text' ] = notice_text
1255+ print ('about_content 2:' , about_content )
12511256
12521257 # FIXME: The following is a tmp code to handle multiple
12531258 # 'license_text_file' in the input
1254- print ('about_content_dict:' , about_content_dict )
1255- for k in about_content_dict :
1256- if ('\n ' in about_content_dict [k ]
1259+ for k in about_content :
1260+ if ('\n ' in about_content [k ]
12571261 and k == 'license_text_file' ):
12581262 lic_text = unicode (about_object .tmp_get_license_text (),
12591263 errors = 'replace' )
1260- about_content_dict ['license_text' ] = lic_text
1264+ about_content ['license_text' ] = lic_text
1265+ print ('about_content 3:' , about_content )
12611266
12621267 # Raise error if no license_text is found
1263- if 'license_text' not in about_content_dict :
1268+ if not about_content . get ( 'license_text' ) :
12641269 msg = ('No license_text found. '
1265- 'skipping License generation.' )
1270+ 'Skipping License generation.' )
1271+ print ()
1272+ print (msg )
1273+ print ()
12661274 err = Error (GENATTRIB , 'name' ,
12671275 about_object .get_about_name (), msg )
12681276 self .genattrib_errors .append (err )
12691277
1270- about_object_fields .append (about_content_dict )
1278+ about_object_fields .append (about_content )
1279+ print ('about_object_fields:' , about_object_fields )
12711280
12721281 # find paths requested in the limit_to paths arg that do not point to
12731282 # a corresponding ABOUT file
12741283 for path in limit_to :
12751284 path = posix_path (path )
1276-
1285+
12771286 afp = join (self .location , path )
12781287 msg = ('The requested ABOUT file: %(afp)r does not exist. '
12791288 'No attribution generated for this file.' % locals ())
@@ -1287,6 +1296,9 @@ def generate_attribution(self, template_path='templates/default.html',
12871296 license_text_list.append(common_license_dict[key])"""
12881297
12891298 rendered = template .render (about_objects = about_object_fields )
1299+ print ('genattrib_errors:' , self .genattrib_errors )
1300+ print ('rendered:' , rendered )
1301+ print ()
12901302 return rendered
12911303
12921304 def check_paths (self , paths ):
0 commit comments