@@ -84,28 +84,35 @@ def read_and_check_licenses(self, license_text, license_keywords):
84
84
found = True
85
85
return found
86
86
87
- def read_and_check_dir_for_licenses (self , path ):
88
- """ Check licenses for all files under the directory
87
+ def check_licenses (self , filepath ):
88
+ """ Read a license text file and find the license_kinds.
89
89
"""
90
- for (root , _ , files ) in os .walk (path ):
91
- for f in files :
92
- with open (os .path .join (root , f ), 'r' ) as file_to_check :
93
- file_string = file_to_check .read ()
94
- self .read_and_check_licenses (file_string , LICENSE_KEYWORDS )
95
- if self .read_and_check_licenses (file_string , RESTRICTED_LICENSE_KEYWORDS ):
96
- self .restricted .add (f )
97
-
98
- def run (self , license_text = '' ):
90
+ with open (filepath , 'r' ) as file_to_check :
91
+ file_string = file_to_check .read ()
92
+ self .read_and_check_licenses (file_string , LICENSE_KEYWORDS )
93
+ if self .read_and_check_licenses (file_string , RESTRICTED_LICENSE_KEYWORDS ):
94
+ self .restricted .add (os .path .basename (filepath ))
95
+
96
+ def run (self , license_text_path = '' ):
99
97
""" search licenses in vndk snapshots
98
+
99
+ Args:
100
+ license_text_path: path to the license text file to check.
101
+ If empty, check all license files.
100
102
"""
101
- if license_text == '' :
103
+ if license_text_path == '' :
102
104
for path in self ._paths_to_check :
103
105
logging .info ('Reading {}' .format (path ))
104
- self .read_and_check_dir_for_licenses (path )
106
+ for (root , _ , files ) in os .walk (path ):
107
+ for f in files :
108
+ self .check_licenses (os .path .join (root , f ))
109
+ self .license_kinds .update (LICENSE_INCLUDE )
105
110
else :
106
- logging .info ('Reading {}' .format (license_text ))
107
- self .read_and_check_dir_for_licenses (license_text )
108
- self .license_kinds .update (LICENSE_INCLUDE )
111
+ logging .info ('Reading {}' .format (license_text_path ))
112
+ self .check_licenses (os .path .join (self ._install_dir , utils .COMMON_DIR_PATH , license_text_path ))
113
+ if not self .license_kinds :
114
+ # Add 'legacy_permissive' if no licenses are found for this file.
115
+ self .license_kinds .add ('legacy_permissive' )
109
116
110
117
def get_args ():
111
118
parser = argparse .ArgumentParser ()
0 commit comments