1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
7 # Copyright 2016 The Android Open Source Project
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
21 #-------------------------------------------------------------------------
24 from common import isTextFile
25 from fnmatch import fnmatch
33 # \note Defined this way to avoid triggering license check error on this file
34 ("P" + "ermission is hereby granted, free of charge", LICENSE_MIT),
35 ("L" + "icensed under the Apache License, Version 2.0", LICENSE_APACHE2),
38 SOURCE_FILES = ["*.py", "*.java", "*.c", "*.h", "*.cpp", "*.hpp"]
46 def getFileLicense (file):
47 contents = readFile(file)
48 detected = LICENSE_UNKNOWN
50 for searchStr, license in LICENSE_KEYS:
51 if contents.find(searchStr) != -1:
52 if detected != LICENSE_UNKNOWN:
53 detected = LICENSE_MULTIPLE
59 def checkFileLicense (file):
60 license = getFileLicense(file)
62 if license == LICENSE_MIT:
63 print "%s: contains MIT license" % file
64 elif license == LICENSE_MULTIPLE:
65 print "%s: contains multiple licenses" % file
66 elif license == LICENSE_UNKNOWN:
67 print "%s: missing/unknown license" % file
69 return license == LICENSE_APACHE2
71 def isSourceFile (file):
72 for ptrn in SOURCE_FILES:
73 if fnmatch(file, ptrn):
77 def checkLicense (files):
80 if isTextFile(file) and isSourceFile(file):
81 if not checkFileLicense(file):