@@ -295,6 +295,16 @@ def get_license_text_from_api(self, url, username, api_key, license_key):
295295 license_text = data .get ('full_text' , '' )
296296 return license_text
297297
298+ # This is a temp function. This should be merged with the get_license_text_from_api
299+ def get_license_name_from_api (self , url , username , api_key , license_key ):
300+ """
301+ Returns the license_text of a given license_key using an API request.
302+ Returns an empty string if the text is not available.
303+ """
304+ data = self .request_license_data (url , username , api_key , license_key )
305+ license_name = data .get ('name' , '' )
306+ return license_name
307+
298308 def get_dje_license_list (self , gen_location , input_list , gen_license ):
299309 license_output_list = []
300310 for line in input_list :
@@ -327,9 +337,14 @@ def get_dje_license_list(self, gen_location, input_list, gen_license):
327337 "Missing 'dje_license_key' for " + line ['about_file' ]))
328338 return license_output_list
329339
330- def pre_generation (self , gen_location , input_list , action_num , all_in_one ):
340+ def pre_generation (self , gen_location , input_list , action_num , all_in_one , api_url , api_username , api_key ):
331341 output_list = []
332342 for line in input_list :
343+ try :
344+ if api_url and line ['dje_license_key' ]:
345+ line ['dje_license' ] = self .get_license_name_from_api (api_url , api_username , api_key , line ['dje_license_key' ])
346+ except Exception as e :
347+ pass
333348 component_list = []
334349 file_location = line ['about_file' ]
335350 if file_location .startswith ('/' ):
@@ -644,7 +659,7 @@ def main(parser, options, args):
644659 sys .exit (errno .EINVAL )
645660
646661 dje_license_list = gen .get_dje_license_list (output_path , input_list , gen_license )
647- components_list = gen .pre_generation (output_path , input_list , action_num , all_in_one )
662+ components_list = gen .pre_generation (output_path , input_list , action_num , all_in_one , api_url , api_username , api_key )
648663 formatted_output = gen .format_output (components_list )
649664 gen .write_output (formatted_output )
650665
0 commit comments