scancode: skip non code files

For instance pdf, or binaries - catch them as an exception and skip for
additional SPDX check
pull/12437/head
Martin Kojtal 2020-02-21 09:14:30 +00:00
parent db989ba65a
commit 37a7ff0443
1 changed files with 13 additions and 10 deletions

View File

@ -81,17 +81,20 @@ def license_check(directory_name, file):
found_spdx = True
if not found_spdx:
# Issue reported reported here https://github.com/nexB/scancode-toolkit/issues/1913
# We verify here if SPDX is not really there as SDPX is part of the license text
# scancode has some problems detecting it properly
with open(os.path.join(os.path.abspath(license_offender['file']['path'])), 'r') as spdx_file_check:
filetext = spdx_file_check.read()
matches = re.findall("SPDX-License-Identifier:?", filetext)
if matches:
try:
# Issue reported here https://github.com/nexB/scancode-toolkit/issues/1913
# We verify here if SPDX is not really there as SDPX is part of the license text
# scancode has some problems detecting it properly
with open(os.path.join(os.path.abspath(license_offender['file']['path'])), 'r') as spdx_file_check:
filetext = spdx_file_check.read()
matches = re.findall("SPDX-License-Identifier:?", filetext)
if matches:
continue
license_offender['reason'] = MISSING_SPDX_TEXT
offenders.append(license_offender)
except UnicodeDecodeError:
# not valid file for license check
continue
license_offender['reason'] = MISSING_SPDX_TEXT
offenders.append(license_offender)
except KeyError:
userlog.warning("Invalid scancode json file")
return -1