Cleaned up python/licenseck.py

- Moved logic into tidy.py
- Removed explicit BSD license exceptions, they are already ignored by
  being inside the codegen directory.
This commit is contained in:
Duncan Keall 2014-09-09 12:16:50 +12:00
parent 6c48066565
commit 8e25e958ab
2 changed files with 21 additions and 40 deletions

View file

@ -7,25 +7,29 @@
# option. This file may not be copied, modified, or distributed # option. This file may not be copied, modified, or distributed
# except according to those terms. # except according to those terms.
license0="""\
# These licenses are valid for use in Servo
licenses = [
"""\
/* This Source Code Form is subject to the terms of the Mozilla Public /* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
""" """,
license1="""\ """\
# This Source Code Form is subject to the terms of the Mozilla Public # This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
""" """,
license2="""\ """\
// This Source Code Form is subject to the terms of the Mozilla Public // This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this // License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
""" """,
license3 = """\ """\
// Copyright 2013 The Servo Project Developers. See the COPYRIGHT // Copyright 2013 The Servo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
@ -34,9 +38,9 @@ license3 = """\
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
""" """,
license4 = """\ """\
# Copyright 2013 The Servo Project Developers. See the COPYRIGHT # Copyright 2013 The Servo Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution. # file at the top-level directory of this distribution.
# #
@ -45,31 +49,6 @@ license4 = """\
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed # option. This file may not be copied, modified, or distributed
# except according to those terms. # except according to those terms.
""" """,
licenses = [license0, license1, license2, license3, license4]
exceptions = [
"servo/dom/bindings/codegen/ply/ply/yacc.py", # BSD
"servo/dom/bindings/codegen/ply/ply/__init__.py", # BSD
"servo/dom/bindings/codegen/ply/ply/lex.py", # BSD
] ]
def check_license(name, contents):
valid_license = False
for a_valid_license in licenses:
if contents.startswith(a_valid_license):
valid_license = True
break
if valid_license:
return True
for exception in exceptions:
if name.endswith(exception):
return True
firstlineish = contents[:100]
if firstlineish.find("xfail-license") != -1:
return True
return False

View file

@ -11,7 +11,7 @@
import os import os
import fnmatch import fnmatch
import licenseck from licenseck import licenses
directories_to_check = ["src", "components"] directories_to_check = ["src", "components"]
filetypes_to_check = [".rs", ".rc", ".cpp", ".c", ".h", ".py"] filetypes_to_check = [".rs", ".rc", ".cpp", ".c", ".h", ".py"]
@ -45,12 +45,14 @@ def should_check(file_name):
return True return True
def check_license(file_name, contents): def check_license(contents):
if not licenseck.check_license(file_name, contents): valid_license = any(contents.startswith(license) for license in licenses)
acknowledged_bad_license = "xfail-license" in contents[:100]
if not (valid_license or acknowledged_bad_license):
yield (1, "incorrect license") yield (1, "incorrect license")
def check_whitespace(file_name, contents): def check_whitespace(contents):
lines = contents.splitlines(True) lines = contents.splitlines(True)
for idx, line in enumerate(lines): for idx, line in enumerate(lines):
if line[-1] == "\n": if line[-1] == "\n":
@ -73,7 +75,7 @@ def collect_errors_for_files(files_to_check, checking_functions):
with open(file_name, "r") as fp: with open(file_name, "r") as fp:
contents = fp.read() contents = fp.read()
for check in checking_functions: for check in checking_functions:
for error in check(file_name, contents): for error in check(contents):
# filename, line, message # filename, line, message
yield (file_name, error[0], error[1]) yield (file_name, error[0], error[1])