@@ -288,24 +288,15 @@ def write_licenses(self, license_context_list):
288288 except Exception as e :
289289 self .errors .append (Error ('Unknown' , gen_license_path , "Something is wrong." ))
290290
291- def get_license_text_from_api (self , url , username , api_key , license_key ):
292- """
293- Returns the license_text of a given license_key using an API request.
294- Returns an empty string if the text is not available.
295- """
296- data = self .request_license_data (url , username , api_key , license_key )
297- license_text = data .get ('full_text' , '' )
298- return license_text
299-
300- # This is a temp function. This should be merged with the get_license_text_from_api
301- def get_license_name_from_api (self , url , username , api_key , license_key ):
291+ def get_license_details_from_api (self , url , username , api_key , license_key ):
302292 """
303293 Returns the license_text of a given license_key using an API request.
304294 Returns an empty string if the text is not available.
305295 """
306296 data = self .request_license_data (url , username , api_key , license_key )
307297 license_name = data .get ('name' , '' )
308- return license_name
298+ license_text = data .get ('full_text' , '' )
299+ return [license_name , license_text ]
309300
310301 def get_dje_license_list (self , gen_location , input_list , gen_license ):
311302 license_output_list = []
@@ -339,14 +330,31 @@ def get_dje_license_list(self, gen_location, input_list, gen_license):
339330 "Missing 'dje_license' for " + line ['about_file' ]))
340331 return license_output_list
341332
342- def add_dje_license_name (self , input_list , api_url , api_username , api_key ):
333+ def pre_process_and_dje_license_list (self , input_list , api_url , api_username , api_key , dje_license_list , output_path ):
334+ key_text_dict = {}
343335 for line in input_list :
344336 try :
345337 if line ['dje_license' ]:
346- line ['dje_license_name' ] = self .get_license_name_from_api (api_url , api_username , api_key , line ['dje_license' ])
338+ detail = self .get_license_details_from_api (api_url , api_username , api_key , line ['dje_license' ])
339+ line ['dje_license_name' ] = detail [0 ]
340+ key_text_dict [line ['dje_license' ]] = detail [1 ]
347341 except Exception as e :
348342 self .warnings .append (Warn ('dje_license' , '' ,
349343 "Missing 'dje_license' for " + line ['about_file' ]))
344+ if dje_license_list :
345+ license_list_context = []
346+ for gen_path , license_key in dje_license_list :
347+ if gen_path .startswith ('/' ):
348+ gen_path = gen_path .partition ('/' )[2 ]
349+ gen_license_path = join (output_path , gen_path , license_key ) + '.LICENSE'
350+ if not _exists (gen_license_path ) and not self .extract_dje_license_error :
351+ context = key_text_dict [license_key ]
352+ if context :
353+ gen_path_context = []
354+ gen_path_context .append (gen_license_path )
355+ gen_path_context .append (context .encode ('utf8' ))
356+ license_list_context .append (gen_path_context )
357+ return license_list_context
350358
351359 def pre_generation (self , gen_location , input_list , action_num , all_in_one ):
352360 output_list = []
@@ -664,34 +672,25 @@ def main(parser, options, args):
664672 print ("The input does not have the 'dje_license' key which is required." )
665673 sys .exit (errno .EINVAL )
666674
675+ dje_license_list = gen .get_dje_license_list (output_path , input_list , gen_license )
676+
667677 if gen_license :
668- gen .add_dje_license_name (input_list , api_url , api_username , api_key )
678+ license_list_context = gen .pre_process_and_dje_license_list (input_list ,
679+ api_url ,
680+ api_username ,
681+ api_key ,
682+ dje_license_list ,
683+ output_path )
684+ gen .write_licenses (license_list_context )
669685
670- dje_license_list = gen .get_dje_license_list (output_path , input_list , gen_license )
671686 components_list = gen .pre_generation (output_path , input_list , action_num , all_in_one )
672687 formatted_output = gen .format_output (components_list )
673688 gen .write_output (formatted_output )
674689
675- if dje_license_list :
676- license_list_context = []
677- for gen_path , license_key in dje_license_list :
678- if gen_path .startswith ('/' ):
679- gen_path = gen_path .partition ('/' )[2 ]
680- gen_license_path = join (output_path , gen_path , license_key ) + '.LICENSE'
681- if not _exists (gen_license_path ) and not gen .extract_dje_license_error :
682- context = gen .get_license_text_from_api (api_url , api_username , api_key , license_key )
683- if context :
684- gen_path_context = []
685- gen_path_context .append (gen_license_path )
686- gen_path_context .append (context .encode ('utf8' ))
687- license_list_context .append (gen_path_context )
688- gen .write_licenses (license_list_context )
689-
690690 gen .warnings_errors_summary ()
691691 print ('Warnings: %s' % len (gen .warnings ))
692692 print ('Errors: %s' % len (gen .errors ))
693693
694-
695694def get_parser ():
696695 class MyFormatter (optparse .IndentedHelpFormatter ):
697696 def _format_text (self , text ):
0 commit comments