in scancode/scanCode.py [0:0]
def has_block_license(path):
"""Open file and verify it contains a valid license header."""
if not os.path.isfile(path):
if VERBOSE:
print_error(MSG_SKIPPING_FILE % path)
return []
with open(path) as fp:
for license in valid_licenses:
# Assure license string is normalized to remove indentations
# caused by declaration (above) as a string literal.
normalized_license = textwrap.dedent(license)
# Search for license at start of file,
# allowing for some "slack" length
file_head = fp.read(len(normalized_license) +
license_search_slack_len)
if file_head is None:
return [(1, ERR_LICENSE)]
elif normalized_license in file_head:
return []
# reset and try finding the next license
fp.seek(0)
return [(1, ERR_LICENSE)]