MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / load_licenses

Function load_licenses

src/licensedcode/models.py:801–857  ·  view source on GitHub ↗

Return a mapping of {key: License} loaded from license data and text files found in ``licenses_data_dir``. Raise Exceptions if there are dangling or orphaned files. Optionally include deprecated license if ``with_deprecated`` is True. Optionally check for dangling orphaned files

(
    licenses_data_dir=licenses_data_dir,
    with_deprecated=False,
    check_consistency=True,
    is_builtin=True,
)

Source from the content-addressed store, hash-verified

799
800
801def load_licenses(
802 licenses_data_dir=licenses_data_dir,
803 with_deprecated=False,
804 check_consistency=True,
805 is_builtin=True,
806):
807 """
808 Return a mapping of {key: License} loaded from license data and text files
809 found in ``licenses_data_dir``. Raise Exceptions if there are dangling or
810 orphaned files.
811 Optionally include deprecated license if ``with_deprecated`` is True.
812 Optionally check for dangling orphaned files if ``check_dangling`` is True.
813 """
814
815 all_files = list(resource_iter(
816 location=licenses_data_dir,
817 ignored=ignore_editor_tmp_files,
818 with_dirs=False,
819 follow_symlinks=True,
820 ))
821
822 licenses = {}
823
824 for license_file in all_files:
825 if license_file.endswith('.LICENSE'):
826 if TRACE:
827 logger_debug('load_licenses: license_file:', license_file)
828
829 key = file_base_name(license_file)
830
831 try:
832 lic = License.from_dir(
833 key=key,
834 licenses_data_dir=licenses_data_dir,
835 check_consistency=check_consistency,
836 is_builtin=is_builtin,
837 )
838 except Exception as e:
839 msg = (
840 f'Failed to load license: {key} from: '
841 f'file://{licenses_data_dir}/{key}.LICENSE with error: {e}'
842 )
843 raise InvalidLicense(msg) from e
844
845 if not with_deprecated and lic.is_deprecated:
846 continue
847
848 licenses[key] = lic
849
850 if not licenses:
851 msg = (
852 'No licenses were loaded. Check to see if the license data files '
853 f'are available at "{licenses_data_dir}".'
854 )
855 raise InvalidLicense(msg)
856
857 return licenses
858

Callers 15

__init__Method · 0.90
get_licensesMethod · 0.90
cliFunction · 0.90
build_licensingFunction · 0.90
build_spdx_symbolsFunction · 0.90
get_licenses_by_spdx_keyFunction · 0.90
generateFunction · 0.90

Calls 5

resource_iterFunction · 0.90
file_base_nameFunction · 0.90
InvalidLicenseClass · 0.85
logger_debugFunction · 0.70
from_dirMethod · 0.45