def get_licensing(_test_licenses=None): """ Return and cache a license_expression.Licensing objet built from the all the licenses. """ global _LICENSING if not _LICENSING or _test_licenses: if _test_licenses: licenses = _test_licenses else: licenses = get_licenses_db() from license_expression import LicenseSymbolLike from license_expression import Licensing licensing = Licensing( (LicenseSymbolLike(lic) for lic in licenses.values())) if _test_licenses: # Do not cache when testing return licensing _LICENSING = licensing return _LICENSING
def get_unknown_spdx_symbol(_test_licenses=None): """ Return the unknown SPDX license symbol. Note: the `_test_licenses` arg is a mapping of key: license used for testing instead of the standard license db. """ global _UNKNOWN_SPDX_SYMBOL if not _UNKNOWN_SPDX_SYMBOL or _test_licenses: from license_expression import LicenseSymbolLike if _test_licenses: licenses = _test_licenses else: licenses = get_licenses_db() unknown = LicenseSymbolLike(licenses[u'unknown-spdx']) if _test_licenses: # Do not cache when testing return unknown _UNKNOWN_SPDX_SYMBOL = unknown return _UNKNOWN_SPDX_SYMBOL
def build_unknown_spdx_symbol(licenses_db=None): """ Return the unknown SPDX license symbol given a `licenses_db` mapping of {key: License} or the standard license db. """ from license_expression import LicenseSymbolLike licenses = licenses_db or build_licenses_db() return LicenseSymbolLike(licenses[u'unknown-spdx'])
def build_unknown_spdx_symbol(licenses_db=None): """ Return the unknown SPDX license symbol given a `licenses_db` mapping of {key: License} or the standard license db. """ from license_expression import LicenseSymbolLike from licensedcode.models import load_licenses licenses_db = licenses_db or load_licenses() return LicenseSymbolLike(licenses_db['unknown-spdx'])
def build_licensing(licenses_db=None): """ Return a `license_expression.Licensing` objet built from `licenses_db` mapping of {key: License} or the standard license db. """ from license_expression import LicenseSymbolLike from license_expression import Licensing licenses = licenses_db or build_licenses_db() return Licensing((LicenseSymbolLike(lic) for lic in licenses.values()))
def get_spdx_symbols(_test_licenses=None): """ Return a mapping of (SPDX LicenseSymbol -> lowercased SPDX license key-> key} Note: the `_test_licenses` arg is a mapping of key: license used for testing instead of the standard license db. """ global _LICENSE_SYMBOLS_BY_SPDX_KEY if not _LICENSE_SYMBOLS_BY_SPDX_KEY or _test_licenses: from license_expression import LicenseSymbol from license_expression import LicenseSymbolLike symbols_by_spdx_key = {} if _test_licenses: licenses = _test_licenses else: licenses = get_licenses_db() for lic in licenses.values(): if not (lic.spdx_license_key or lic.other_spdx_license_keys): continue symbol = LicenseSymbolLike(lic) if lic.spdx_license_key: slk = lic.spdx_license_key.lower() existing = symbols_by_spdx_key.get(slk) if existing: raise ValueError( 'Duplicated SPDX license key: %(slk)r defined in ' '%(lic)r and %(existing)r' % locals()) symbols_by_spdx_key[slk] = symbol for other_spdx in lic.other_spdx_license_keys: if not (other_spdx and other_spdx.strip()): continue slk = other_spdx.lower() existing = symbols_by_spdx_key.get(slk) if existing: raise ValueError( 'Duplicated "other" SPDX license key: %(slk)r defined ' 'in %(lic)r and %(existing)r' % locals()) symbols_by_spdx_key[slk] = symbol if _test_licenses: # Do not cache when testing return symbols_by_spdx_key _LICENSE_SYMBOLS_BY_SPDX_KEY = symbols_by_spdx_key return _LICENSE_SYMBOLS_BY_SPDX_KEY
def build_spdx_symbols(licenses_db=None): """ Return a mapping of {lowercased SPDX license key: LicenseSymbolLike} where LicenseSymbolLike wraps a License object loaded from a `licenses_db` mapping of {key: License} or the standard license db. """ from license_expression import LicenseSymbolLike from licensedcode.models import load_licenses licenses_db = licenses_db or load_licenses() symbols_by_spdx_key = {} for lic in licenses_db.values(): if not (lic.spdx_license_key or lic.other_spdx_license_keys): continue symbol = LicenseSymbolLike(lic) if lic.spdx_license_key: slk = lic.spdx_license_key.lower() existing = symbols_by_spdx_key.get(slk) if existing: raise ValueError( 'Duplicated SPDX license key: %(slk)r defined in ' '%(lic)r and %(existing)r' % locals()) symbols_by_spdx_key[slk] = symbol for other_spdx in lic.other_spdx_license_keys: if not (other_spdx and other_spdx.strip()): continue slk = other_spdx.lower() existing = symbols_by_spdx_key.get(slk) if existing: raise ValueError( 'Duplicated "other" SPDX license key: %(slk)r defined ' 'in %(lic)r and %(existing)r' % locals()) symbols_by_spdx_key[slk] = symbol return symbols_by_spdx_key
def build_spdx_symbols(licenses_db=None): """ Return a mapping of {lowercased SPDX license key: LicenseSymbolLike} where LicenseSymbolLike wraps a License object loaded from a `licenses_db` mapping of {key: License} or the standard license db. """ from license_expression import LicenseSymbolLike from licensedcode.models import load_licenses licenses_db = licenses_db or load_licenses() licenses_by_spdx_key = get_licenses_by_spdx_key( licenses=licenses_db.values(), include_deprecated=False, lowercase_keys=True, include_other_spdx_license_keys=True, ) return { spdx: LicenseSymbolLike(lic) for spdx, lic in licenses_by_spdx_key.items() }