@@ -196,34 +196,50 @@ def get_non_supported_fields(input_list):
196196 first_line = input_list [0 ]
197197 return [field for field in first_line .keys () if not field in SUPPORTED_FIELDS ]
198198
199- def verify_license_files (self , input_list , project_dir , license_in_project ):
199+ def verify_files_existance (self , input_list , project_dir , file_in_project ):
200200 """
201201 Verify the existence of the 'license text file'
202202 """
203- license_files_list = []
203+ files_list = []
204+ # Get all the dictionary keys
205+ column_keys = input_list [0 ].keys ()
206+
207+ # Get all the keys that ending with _file except for the 'about_file
208+ file_keys = []
209+ for key in column_keys :
210+ if '_file' in key and key != 'about_file' :
211+ file_keys .append (key )
212+
204213 for line in input_list :
205- try :
206- if line ['license_text_file' ]:
207- license_file = line ['license_text_file' ]
214+ for file_key in file_keys :
215+ if line [file_key ]:
216+ file_path_list = []
217+ file_value = []
208218 file_location = line ['about_file' ]
209219 if file_location .startswith ('/' ):
210220 file_location = file_location .partition ('/' )[2 ]
211- #if file_location.endswith('/'):
212- # file_location = file_location.rpartition('/')[0]
213221 about_parent_dir = dirname (file_location )
214- if license_in_project :
215- license_file_path = join (project_dir , about_parent_dir , license_file )
216- else :
217- license_file_path = join (project_dir , license_file )
218- if _exists (license_file_path ):
219- license_files_list .append ((license_file_path , about_parent_dir ))
222+ if file_in_project :
223+ if '\n ' in line [file_key ]:
224+ file_value = line [file_key ].split ('\n ' )
225+ else :
226+ file_value .append (line [file_key ])
227+ for value in file_value :
228+ file_path_list .append (join (project_dir , about_parent_dir , value ))
220229 else :
221- self .warnings .append (Warn ('license_text_file' , license_file_path , "License does not exist." ))
222- except Exception as e :
223- print (repr (e ))
224- print ("The input does not have the 'license_text_file' key which is required." )
225- raise Exception (repr (e ))
226- return license_files_list
230+ if '\n ' in line [file_key ]:
231+ file_value = line [file_key ].split ('\n ' )
232+ else :
233+ file_value .append (line [file_key ])
234+ for value in file_value :
235+ file_path_list .append (join (project_dir , value ))
236+
237+ for path in file_path_list :
238+ if _exists (path ):
239+ files_list .append ((path , about_parent_dir ))
240+ else :
241+ self .warnings .append (Warn (file_key , path , "File does not exist." ))
242+ return files_list
227243
228244 def request_license_data (self , url , username , api_key , license_key ):
229245 """
@@ -278,15 +294,15 @@ def request_license_data(self, url, username, api_key, license_key):
278294 return data
279295
280296 @staticmethod
281- def copy_license_files (gen_location , license_list ):
297+ def copy_files (gen_location , files_list ):
282298 """
283- Copy the 'license_text_file' into the gen_location
299+ Copy the files into the gen_location
284300 """
285- for license_path , component_path in license_list :
286- output_license_path = join (gen_location , component_path )
287- if not _exists (output_license_path ):
288- makedirs (output_license_path )
289- shutil .copy2 (license_path , output_license_path )
301+ for file_path , component_path in files_list :
302+ output_file_path = join (gen_location , component_path )
303+ if not _exists (output_file_path ):
304+ makedirs (output_file_path )
305+ shutil .copy2 (file_path , output_file_path )
290306
291307 def write_licenses (self , license_context_list ):
292308 for gen_license_path , license_context in license_context_list :
@@ -513,8 +529,8 @@ def _exists(file_path):
513529any project structure
514530"""
515531
516- COPY_LICENSE_HELP = """\
517- Copy the 'license_text_file ' from the project to the generated location
532+ COPY_FILES_HELP = """\
533+ Copy the '*_file ' from the project to the generated location
518534Project path - Project path
519535"""
520536
@@ -547,7 +563,7 @@ def main(parser, options, args):
547563 verbosity = options .verbosity
548564 action = options .action
549565 all_in_one = options .all_in_one
550- copy_license_path = options .copy_license
566+ copy_files_path = options .copy_files
551567 license_text_path = options .license_text_location
552568 mapping_config = options .mapping
553569 extract_license = options .extract_license
@@ -575,8 +591,8 @@ def main(parser, options, args):
575591 else :
576592 action_num = action
577593
578- if copy_license_path :
579- if not _exists (copy_license_path ):
594+ if copy_files_path :
595+ if not _exists (copy_files_path ):
580596 print ("The project path does not exist." )
581597 sys .exit (errno .EINVAL )
582598
@@ -656,20 +672,20 @@ def main(parser, options, args):
656672 if ignored_fields_list :
657673 input_list = gen .get_only_supported_fields (input_list , ignored_fields_list )
658674
659- if copy_license_path :
660- if not isdir (copy_license_path ):
661- print ("The '--copy_license ' <project_path> must be a directory." )
662- print ("'--copy_license ' is skipped." )
675+ if copy_files_path :
676+ if not isdir (copy_files_path ):
677+ print ("The '--copy_files ' <project_path> must be a directory." )
678+ print ("'--copy_files ' is skipped." )
663679 else :
664- #if not copy_license_path .endswith('/'):
665- # copy_license_path += '/'
666- project_parent_dir = dirname (copy_license_path )
680+ #if not copy_files_path .endswith('/'):
681+ # copy_files_path += '/'
682+ project_parent_dir = dirname (copy_files_path )
667683 licenses_in_project = True
668- license_list = gen .verify_license_files (input_list , project_parent_dir , licenses_in_project )
684+ license_list = gen .verify_files_existance (input_list , project_parent_dir , licenses_in_project )
669685 if not license_list :
670- print ("None of the 'license_text_file' is found. '--copy_license ' is ignored." )
686+ print ("None of the file is found. '--copy_files ' is ignored." )
671687 else :
672- gen .copy_license_files (output_path , license_list )
688+ gen .copy_files (output_path , license_list )
673689
674690 if license_text_path :
675691 if not isdir (license_text_path ):
@@ -680,11 +696,11 @@ def main(parser, options, args):
680696 # license_text_path += '/'
681697 license_dir = dirname (license_text_path )
682698 licenses_in_project = False
683- license_list = gen .verify_license_files (input_list , license_dir , licenses_in_project )
699+ license_list = gen .verify_files_existance (input_list , license_dir , licenses_in_project )
684700 if not license_list :
685- print ("None of the 'license_text_file' is found. '--copy_license ' is ignored." )
701+ print ("None of the file is found. '--copy_files ' is ignored." )
686702 else :
687- gen .copy_license_files (output_path , license_list )
703+ gen .copy_files (output_path , license_list )
688704
689705 if extract_license :
690706 if not api_url or not api_username or not api_key :
@@ -768,7 +784,7 @@ def format_option(self, option):
768784 parser .add_option ('--verbosity' , type = int , help = VERBOSITY_HELP )
769785 parser .add_option ('--action' , type = int , help = ACTION_HELP )
770786 parser .add_option ('--all_in_one' , action = 'store_true' , help = ALL_IN_ONE_HELP )
771- parser .add_option ('--copy_license ' , type = 'string' , help = COPY_LICENSE_HELP )
787+ parser .add_option ('--copy_files ' , type = 'string' , help = COPY_FILES_HELP )
772788 parser .add_option ('--license_text_location' , type = 'string' , help = LICENSE_TEXT_LOCATION_HELP )
773789 parser .add_option ('--mapping' , action = 'store_true' , help = MAPPING_HELP )
774790 parser .add_option (
0 commit comments