anki/scripts/copyright_headers.py

61 lines
1.6 KiB
Python
Raw Normal View History

2021-04-13 10:45:05 +02:00
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
2021-04-14 10:22:02 +02:00
import os
import sys
2021-04-13 10:45:05 +02:00
from pathlib import Path
nonstandard_header = {
"pylib/anki/_vendor/stringcase.py",
2021-04-13 10:45:05 +02:00
"pylib/anki/importing/pauker.py",
"pylib/anki/importing/supermemo_xml.py",
"pylib/anki/statsbg.py",
"pylib/tools/protoc-gen-mypy.py",
"python/pyqt/install.py",
2021-04-13 10:45:05 +02:00
"qt/aqt/mpv.py",
"qt/aqt/winpaths.py",
2021-10-28 10:46:45 +02:00
"qt/package/build.rs",
"qt/package/src/main.rs",
2021-04-13 10:45:05 +02:00
}
2021-04-13 10:57:08 +02:00
ignored_folders = [
"bazel-",
"qt/forms",
"node_modules",
2021-04-13 10:57:08 +02:00
]
2021-04-13 10:45:05 +02:00
if not os.path.exists("WORKSPACE"):
print("run from workspace root")
sys.exit(1)
found = False
for dirpath, dirnames, fnames in os.walk("."):
dir = Path(dirpath)
2021-04-13 10:57:08 +02:00
ignore = False
for folder in ignored_folders:
if folder in dirpath:
ignore = True
break
if ignore:
2021-04-13 10:45:05 +02:00
continue
2021-04-13 10:57:08 +02:00
2021-04-13 10:45:05 +02:00
for fname in fnames:
for ext in ".py", ".ts", ".rs", ".svelte":
2021-04-13 10:57:08 +02:00
if fname.endswith(ext):
path = dir / fname
with open(path) as f:
top = f.read(256)
if not top.strip():
continue
if str(path) in nonstandard_header:
continue
if fname.endswith(".d.ts"):
continue
if "Ankitects Pty Ltd and contributors" not in top:
print("missing standard copyright header:", path)
found = True
2021-04-13 10:45:05 +02:00
if found:
2021-04-14 10:22:02 +02:00
sys.exit(1)