Skip to content

Commit

Permalink
define process_codebase function for matching references
Browse files Browse the repository at this point in the history
Signed-off-by: akugarg <akanksha.garg2k@gmail.com>
  • Loading branch information
akugarg committed Aug 12, 2021
1 parent 6f751e9 commit 2ba8f14
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/licensedcode/plugin_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ def match_reference_license(resource, codebase):
"""
Find instances for any licenses in referenced filenames
"""

if not resource.is_file:
return

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

location = resource.location
from licensedcode import cache

from scancode.api import get_licenses
idx = cache.get_index()
matches = idx.match(
location=location, min_score=0)

reference_licenses=[]
reference_license_exp=[]
unique_files = []

for match in matches:
ref_files=match.rule.referenced_filenames
for license in licenses:
ref_files=license['matched_rule']['referenced_filenames']
if len(ref_files) != 0:
for i in range(len(ref_files)):
if not ref_files[i].startswith('usr/share/common-licenses'):
new_loc=find_reference_file(location,ref_files[i])
if new_loc:
new_lic=get_licenses(new_loc, min_score=0)
licenses.extend(new_lic['licenses'])
license_expressions.extend(new_lic['license_expressions'])

if ref_files[i].startswith('usr/share/common-licenses') or ref_files[i] in unique_files:
continue
unique_files.append(ref_files[i])
print(unique_files)
new_loc=find_reference_file(location,ref_files[i])
if new_loc:
new_lic=get_licenses(new_loc, min_score=0)
reference_licenses.extend(new_lic['licenses'])
reference_license_exp.extend(new_lic['license_expressions'])

licenses.extend(reference_licenses)
license_expressions.extend(reference_license_exp)
codebase.save_resource(resource)
return resource

Expand Down

0 comments on commit 2ba8f14

Please sign in to comment.