2020-05-02 02:36:23 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""Check the docs/THIRDPARTY file against the DEP-5 copyright format.
|
|
|
|
|
|
|
|
https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
|
|
|
|
|
|
|
Disclaimer: This script is not a lawyer. It cannot validate that the
|
|
|
|
claimed licenses are correct. It can only check for basic syntactic
|
|
|
|
issues.
|
|
|
|
"""
|
|
|
|
import difflib
|
|
|
|
import io
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2020-05-02 02:36:23 +02:00
|
|
|
from debian import copyright
|
|
|
|
|
|
|
|
COPYRIGHT_FILENAME = "docs/THIRDPARTY"
|
|
|
|
os.chdir(os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
status = 0
|
|
|
|
|
|
|
|
*files, empty = subprocess.check_output(
|
2021-02-12 08:19:30 +01:00
|
|
|
["git", "ls-files", "-z"],
|
|
|
|
encoding="utf-8",
|
2020-05-02 02:36:23 +02:00
|
|
|
).split("\0")
|
|
|
|
assert empty == ""
|
|
|
|
files += [
|
|
|
|
"static/generated/emoji/images/emoji/unicode/ignore-this-path",
|
|
|
|
]
|
|
|
|
|
|
|
|
with open(COPYRIGHT_FILENAME) as f:
|
|
|
|
lines = list(f)
|
|
|
|
c = copyright.Copyright(lines)
|
|
|
|
|
|
|
|
if not c.header.known_format():
|
|
|
|
print(f"{COPYRIGHT_FILENAME}: Unknown header format {c.header.format}")
|
|
|
|
status = 1
|
|
|
|
|
|
|
|
defined_licenses = {
|
2020-10-19 07:05:17 +02:00
|
|
|
p.license.to_str().split("\n", 1)[0]
|
|
|
|
for p in c.all_license_paragraphs()
|
|
|
|
if "\n" in p.license.to_str()
|
2020-05-02 02:36:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for p in c.all_files_paragraphs():
|
|
|
|
for g in p.files:
|
|
|
|
if not any(map(copyright.globs_to_re([g]).fullmatch, files)):
|
|
|
|
print(f"{COPYRIGHT_FILENAME}: No such file {g}")
|
|
|
|
status = 1
|
|
|
|
|
2020-10-19 07:05:17 +02:00
|
|
|
if "\n" not in p.license.to_str() and p.license.to_str() not in defined_licenses:
|
|
|
|
print(f"{COPYRIGHT_FILENAME}: Missing license text for {p.license.to_str()}")
|
2020-05-02 02:36:23 +02:00
|
|
|
status = 1
|
|
|
|
|
|
|
|
dumped = c.dump()
|
|
|
|
if dumped != "".join(lines):
|
|
|
|
print(f"{COPYRIGHT_FILENAME}: Changes expected:")
|
|
|
|
sys.stdout.writelines(
|
|
|
|
difflib.unified_diff(
|
|
|
|
lines,
|
|
|
|
io.StringIO(dumped).readlines(),
|
|
|
|
COPYRIGHT_FILENAME,
|
|
|
|
COPYRIGHT_FILENAME,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
status = 1
|
|
|
|
|
|
|
|
sys.exit(status)
|