mirror of
https://github.com/google/nomulus.git
synced 2025-07-21 18:26:12 +02:00
Add a license-checking Python script (#123)
* Add a license-checking Python script * Responses to CR
This commit is contained in:
parent
00147c1bc4
commit
3a485a03a6
5 changed files with 72 additions and 4 deletions
47
config/check_license.py
Normal file
47
config/check_license.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
# Copyright 2019 The Nomulus Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
|
||||
license = r".*Copyright \d{4} The Nomulus Authors\. All Rights Reserved\."
|
||||
extensions = ("java", "js", "soy", "sql", "py", "sh")
|
||||
non_included_patterns = {".git", "/build/", "/generated/", "node_modules/", "JUnitBackports.java", }
|
||||
|
||||
def should_include_path(path):
|
||||
for pattern in non_included_patterns:
|
||||
if pattern in path: return False
|
||||
return path.endswith(extensions)
|
||||
|
||||
def get_files():
|
||||
result = []
|
||||
for root, dirnames, filenames in os.walk("."):
|
||||
paths = [os.path.join(root, filename) for filename in filenames]
|
||||
result.extend(filter(should_include_path, paths))
|
||||
return result
|
||||
|
||||
if __name__ == "__main__":
|
||||
all_files = get_files()
|
||||
failed_files = []
|
||||
|
||||
for file in all_files:
|
||||
with open(file, 'r') as f:
|
||||
file_content = f.read()
|
||||
if not re.match(license, file_content, re.DOTALL):
|
||||
failed_files.append(file)
|
||||
|
||||
if failed_files:
|
||||
print("The following files did not match the license header: " + str(failed_files))
|
||||
sys.exit(1)
|
Loading…
Add table
Add a link
Reference in a new issue