Skip to content

Commit 2ba8f14

Browse files
committed
define process_codebase function for matching references
Signed-off-by: akugarg <akanksha.garg2k@gmail.com>
1 parent 6f751e9 commit 2ba8f14

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

src/licensedcode/plugin_license.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ def match_reference_license(resource, codebase):
133133
"""
134134
Find instances for any licenses in referenced filenames
135135
"""
136-
137136
if not resource.is_file:
138137
return
139138

@@ -143,23 +142,29 @@ def match_reference_license(resource, codebase):
143142
return
144143

145144
location = resource.location
146-
from licensedcode import cache
145+
147146
from scancode.api import get_licenses
148-
idx = cache.get_index()
149-
matches = idx.match(
150-
location=location, min_score=0)
147+
148+
reference_licenses=[]
149+
reference_license_exp=[]
150+
unique_files = []
151151

152-
for match in matches:
153-
ref_files=match.rule.referenced_filenames
152+
for license in licenses:
153+
ref_files=license['matched_rule']['referenced_filenames']
154154
if len(ref_files) != 0:
155155
for i in range(len(ref_files)):
156-
if not ref_files[i].startswith('usr/share/common-licenses'):
157-
new_loc=find_reference_file(location,ref_files[i])
158-
if new_loc:
159-
new_lic=get_licenses(new_loc, min_score=0)
160-
licenses.extend(new_lic['licenses'])
161-
license_expressions.extend(new_lic['license_expressions'])
162-
156+
if ref_files[i].startswith('usr/share/common-licenses') or ref_files[i] in unique_files:
157+
continue
158+
unique_files.append(ref_files[i])
159+
print(unique_files)
160+
new_loc=find_reference_file(location,ref_files[i])
161+
if new_loc:
162+
new_lic=get_licenses(new_loc, min_score=0)
163+
reference_licenses.extend(new_lic['licenses'])
164+
reference_license_exp.extend(new_lic['license_expressions'])
165+
166+
licenses.extend(reference_licenses)
167+
license_expressions.extend(reference_license_exp)
163168
codebase.save_resource(resource)
164169
return resource
165170

0 commit comments

Comments
 (0)