mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
pre-commit: Add license-header check inspired by Spicy
This commit is contained in:
parent
4958c56c84
commit
d93249eeab
2 changed files with 47 additions and 0 deletions
36
ci/license-header.py
Executable file
36
ci/license-header.py
Executable file
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import re
|
||||
|
||||
exit_code = 0
|
||||
|
||||
pat1 = re.compile(r"See the file \"COPYING\" in the main distribution directory for copyright.")
|
||||
|
||||
# This is the copyright line used within Spicy plugin and popular in
|
||||
# Spicy analyzers.
|
||||
pat2 = re.compile(r"Copyright \(c\) 2... by the Zeek Project. See COPYING for details.")
|
||||
|
||||
|
||||
def match_line(line):
|
||||
for pat in [pat1, pat2]:
|
||||
m = pat.search(line)
|
||||
if m is not None:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
for f in sys.argv[1:]:
|
||||
has_license_header = False
|
||||
with open(f) as fp:
|
||||
for line in fp:
|
||||
line = line.strip()
|
||||
if has_license_header := match_line(line):
|
||||
break
|
||||
|
||||
if not has_license_header:
|
||||
print(f"{f}:does not seem to contain a license header", file=sys.stderr)
|
||||
exit_code = 1
|
||||
|
||||
sys.exit(exit_code)
|
Loading…
Add table
Add a link
Reference in a new issue