Skip to content

Commit

Permalink
Handle Apache 2.0 licence synoymns
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyharrison committed Aug 8, 2022
1 parent cff2577 commit 339d954
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sbom4python/license.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@


class LicenseScanner:

APACHE_SYNOYMNS = ["Apache Software License", "Apache License, Version 2.0", "Apache 2.0", "Apache 2"]

def __init__(self):
# Load licenses
license_dir, filename = os.path.split(__file__)
license_path = os.path.join(license_dir, "license_data", "spdx_licenses.json")
licfile = open(license_path)
self.licenses = json.load(licfile)

def check_synoymn(self, license, synoymns, value):
return value if license in synoymns else None

def find_license(self, license):
# Search list of licenses to find match

Expand All @@ -24,4 +30,5 @@ def find_license(self, license):
return lic["licenseId"]
elif lic["name"].lower() == license.lower():
return lic["licenseId"]
return default_license
license_id = self.check_synoymn(license, self.APACHE_SYNOYMNS, "Apache-2.0")
return license_id if license_id is not None else default_license

0 comments on commit 339d954

Please sign in to comment.