7
7
# See https://aboutcode.org for more information about nexB OSS projects.
8
8
#
9
9
10
+ import logging
11
+ import os
10
12
import posixpath
11
13
from functools import partial
12
14
20
22
21
23
from scancode .api import SCANCODE_LICENSEDB_URL
22
24
23
- TRACE = False
25
+ TRACE = os . environ . get ( 'SCANCODE_DEBUG_LICENSE_PLUGIN' , False )
24
26
25
27
26
- def logger_debug (* args ): pass
28
+ def logger_debug (* args ):
29
+ pass
27
30
28
31
32
+ logger = logging .getLogger (__name__ )
33
+
29
34
if TRACE :
30
- use_print = True
31
- if use_print :
32
- prn = print
33
- else :
34
- import logging
35
- import sys
36
- logger = logging .getLogger (__name__ )
37
- # logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
38
- logging .basicConfig (stream = sys .stdout )
39
- logger .setLevel (logging .DEBUG )
40
- prn = logger .debug
35
+ import sys
36
+ logging .basicConfig (stream = sys .stdout )
37
+ logger .setLevel (logging .DEBUG )
41
38
42
39
def logger_debug (* args ):
43
- return prn (' ' .join (isinstance (a , str ) and a or repr (a ) for a in args ))
44
-
40
+ return logger .debug (' ' .join (isinstance (a , str ) and a or repr (a ) for a in args ))
45
41
46
42
@scan_impl
47
43
class LicenseScanner (ScanPlugin ):
@@ -156,28 +152,37 @@ def process_codebase(self, codebase, unknown_licenses, **kwargs):
156
152
cle .extra_data ['additional_license_plugins' ] = cche .additional_license_plugins
157
153
has_additional_licenses = True
158
154
159
- if unknown_licenses :
160
- if codebase .has_single_resource :
161
- return
155
+ if TRACE and has_additional_licenses :
156
+ logger_debug (
157
+ f'add_referenced_filenames_license_matches: additional_licenses' ,
158
+ f'has_additional_licenses: { has_additional_licenses } \n ' ,
159
+ f'additional_license_directory: { cche .additional_license_directory } \n ' ,
160
+ f'additional_license_plugins : { cche .additional_license_plugins } '
161
+ )
162
162
163
- for resource in codebase .walk (topdown = False ):
164
- # follow license references to other files
165
- if TRACE :
166
- license_expressions_before = list (resource .license_expressions )
163
+ if codebase .has_single_resource and not codebase .root .is_file :
164
+ return
167
165
166
+ modified = False
167
+ for resource in codebase .walk (topdown = False ):
168
+ # follow license references to other files
169
+ if TRACE :
170
+ license_expressions_before = list (resource .license_expressions )
171
+
172
+ if unknown_licenses :
168
173
modified = add_referenced_filenames_license_matches (resource , codebase )
169
174
170
- if has_additional_licenses and resource .is_file and resource .license_detections :
171
- add_builtin_license_flag (resource , licenses )
175
+ if has_additional_licenses and resource .is_file and resource .licenses :
176
+ add_builtin_license_flag (resource , licenses )
172
177
173
- if TRACE and modified :
174
- license_expressions_after = list (resource .license_expressions )
175
- logger_debug (
176
- f'add_referenced_filenames_license_matches: Modfied:' ,
177
- f'{ resource .path } with license_expressions:\n '
178
- f'before: { license_expressions_before } \n '
179
- f'after : { license_expressions_after } '
180
- )
178
+ if TRACE and modified :
179
+ license_expressions_after = list (resource .license_expressions )
180
+ logger_debug (
181
+ f'add_referenced_filenames_license_matches: Modfied:' ,
182
+ f'{ resource .path } with license_expressions:\n '
183
+ f'before: { license_expressions_before } \n '
184
+ f'after : { license_expressions_after } '
185
+ )
181
186
182
187
183
188
def add_builtin_license_flag (resource , licenses ):
@@ -186,22 +191,17 @@ def add_builtin_license_flag(resource, licenses):
186
191
additional licenses present in the cache, either through an additional
187
192
license directory or additional license plugins.
188
193
"""
189
- for detection in resource .license_detections :
190
- matches = detection ['matches' ]
191
- for match in matches :
192
- add_builtin_value (license_match = match , licenses = licenses )
193
-
194
- for match in resource .license_clues :
194
+ for match in resource .licenses :
195
195
add_builtin_value (license_match = match , licenses = licenses )
196
196
197
197
198
198
def add_builtin_value (license_match , licenses ):
199
199
license_key = license_match ['key' ]
200
200
lic = licenses .get (license_key )
201
201
if lic .is_builtin :
202
- license_match ['is_builtin' ] = True
202
+ license_match ['matched_rule' ][ ' is_builtin' ] = True
203
203
else :
204
- license_match ['is_builtin' ] = False
204
+ license_match ['matched_rule' ][ ' is_builtin' ] = False
205
205
206
206
207
207
def add_referenced_filenames_license_matches (resource , codebase ):
0 commit comments