def get_licenses(location=None): """ Yield dictionaries of license data detected in the file at location for each detected license. """ from licensedcode.models import get_license from licensedcode.detect import get_license_matches for match in get_license_matches(location): for license_key in match.rule.licenses: license = get_license(license_key) yield { 'key': license.key, 'short_name': license.short_name, 'category': license.category, 'owner': license.owner, 'homepage_url': license.homepage_url, 'text_url': license.text_urls[0] if license.text_urls else '', 'dejacode_url': DEJACODE_LICENSE_URL.format(license.key), 'spdx_license_key': license.spdx_license_key, 'spdx_url': license.spdx_url, 'start_line': match.query_position.start_line, 'end_line': match.query_position.end_line, }
def get_licenses(location=None): """ Yield dictionaries of license data detected in the file at location for each detected license. """ from licensedcode.models import get_license from licensedcode.detect import get_license_matches for match in get_license_matches(location): for license_key in match.rule.licenses: license = get_license(license_key) yield { "key": license.key, "short_name": license.short_name, "category": license.category, "owner": license.owner, "homepage_url": license.homepage_url, "text_url": license.text_urls[0] if license.text_urls else "", "dejacode_url": DEJACODE_LICENSE_URL.format(license.key), "spdx_license_key": license.spdx_license_key, "spdx_url": license.spdx_url, "start_line": match.query_position.start_line, "end_line": match.query_position.end_line, }
def get_licenses(location, minimum_score=100): """ Yield an iterable of dictionaries of license data detected in the file at location for each detected license. minimum_score is the minimum score threshold from 0 to 100. The default is 100 means only exact licenses will be detected. With any value below 100, approximate license results are included. Note that the minimum length for an approximate match is four words. """ from licensedcode.models import get_license from licensedcode.detect import get_license_matches for match in get_license_matches(location, minimum_score=minimum_score): for license_key in match.rule.licenses: lic = get_license(license_key) result = OrderedDict() result['key'] = lic.key result['score'] = match.score result['short_name'] = lic.short_name result['category'] = lic.category result['owner'] = lic.owner result['homepage_url'] = lic.homepage_url result['text_url'] = lic.text_urls[0] if lic.text_urls else '' result['dejacode_url'] = DEJACODE_LICENSE_URL.format(lic.key) result['spdx_license_key'] = lic.spdx_license_key result['spdx_url'] = lic.spdx_url result['start_line'] = match.query_position.start_line result['end_line'] = match.query_position.end_line yield result
def detect_license(location=None, minimum_score=100): for match in detect.get_license_matches(location, minimum_score=100): for detected_license in match.rule.licenses: yield (detected_license, match.query_position.start_line, match.query_position.end_line, match.query_position.start_char, match.query_position.end_char, match.rule.identifier, match.score,)
def data_driven_test_function(self): matches = list(detect.get_license_matches(test_file, minimum_score=minimum_score)) # the detected license is the first member of the returned tuple license_result = flat_keys(matches) try: assert expected_licenses == license_result except: # on failure, we compare against more result data to get # additional failure details, including the test_file and full match details assert expected_licenses == ["test file: " + test_file] + [repr(license_result)] + matches
def data_driven_test_function(self): matches = list( detect.get_license_matches(test_file, minimum_score=minimum_score)) # the detected license is the first member of the returned tuple license_result = flat_keys(matches) try: assert expected_licenses == license_result except: # on failure, we compare against more result data to get # additional failure details, including the test_file and full match details assert expected_licenses == ['test file: ' + test_file ] + [repr(license_result)] + matches
def detect_license(location=None, minimum_score=100): for match in detect.get_license_matches(location, minimum_score=100): for detected_license in match.rule.licenses: yield ( detected_license, match.query_position.start_line, match.query_position.end_line, match.query_position.start_char, match.query_position.end_char, match.rule.identifier, match.score, )
def check_position(self, test_path, expected): """ Check license detection in file or folder against expected result. """ test_location = self.get_test_loc(test_path) results = [] for match in detect.get_license_matches(test_location, minimum_score=100): for detected in match.rule.licenses: result = (detected, match.query_position.start_line, match.query_position.end_line, match.query_position.start_char, match.query_position.end_char, # match.rule.identifier, # match.score ) results.append(result) assert expected == results
def check_position(self, test_path, expected): """ Check license detection in file or folder against expected result. """ test_location = self.get_test_loc(test_path) results = [] for match in detect.get_license_matches(test_location, minimum_score=100): for detected in match.rule.licenses: result = ( detected, match.query_position.start_line, match.query_position.end_line, match.query_position.start_char, match.query_position.end_char, # match.rule.identifier, # match.score ) results.append(result) assert expected == results