2828import sys
2929import os .path
3030
31+ MISSING_LICENSE_TEXT = "Missing license"
32+ MISSING_PERMISIVE_LICENSE_TEXT = "Non-permissive license found"
33+ MISSING_SPDX_TEXT = "Missing SDPX identifier"
34+
35+ FILE_OFFENDER = {
36+ 'file' : None ,
37+ 'reason' : None
38+ }
39+
3140def license_check (directory_name , file ):
3241
3342 offenders = []
@@ -41,23 +50,32 @@ def license_check(directory_name, file):
4150 if file ['type' ] == 'directory' :
4251 continue
4352 if not file ['licenses' ]:
53+ dict_file = FILE_OFFENDER
54+ dict_file ['file' ] = file
55+ dict_file ['reason' ] = MISSING_LICENSE_TEXT
4456 offenders .append (file )
4557
4658 found_spdx = False
4759 for i in range (len (file ['licenses' ])):
4860 if file ['licenses' ][i ]['category' ] != 'Permissive' :
49- offenders .append (file )
61+ dict_file = FILE_OFFENDER
62+ dict_file ['file' ] = file
63+ dict_file ['reason' ] = MISSING_PERMISIVE_LICENSE_TEXT
64+ offenders .append (dict_file )
5065 # find SPDX, it shall be one of licenses found
5166 if file ['licenses' ][i ]['matched_rule' ]['identifier' ].find ("spdx" ) != - 1 :
5267 found_spdx = True
5368
5469 if not found_spdx :
55- offenders .append (file )
70+ dict_file = FILE_OFFENDER
71+ dict_file ['file' ] = file
72+ dict_file ['reason' ] = MISSING_SPDX_TEXT
73+ offenders .append (dict_file )
5674
5775 if offenders :
5876 print ("Found files with missing license details, please review and fix" )
5977 for offender in offenders :
60- print ("File: " , offender ['path' ][len (directory_name ):], ":" , "licenses found : " , offender ['licenses ' ])
78+ print ("File: " , offender ['file' ][ ' path' ][len (directory_name ):], ":" , "reason : " , offender ['reason ' ])
6179 sys .exit (- 1 )
6280 else :
6381 sys .exit (0 )
0 commit comments