xref: /aosp_15_r20/external/deqp/scripts/update-copyright-year.py (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker# -*- coding: utf-8 -*-
2*35238bceSAndroid Build Coastguard Worker
3*35238bceSAndroid Build Coastguard Worker#-------------------------------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker# drawElements Quality Program utilities
5*35238bceSAndroid Build Coastguard Worker# --------------------------------------
6*35238bceSAndroid Build Coastguard Worker#
7*35238bceSAndroid Build Coastguard Worker# Copyright 2015 The Android Open Source Project
8*35238bceSAndroid Build Coastguard Worker#
9*35238bceSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
10*35238bceSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
11*35238bceSAndroid Build Coastguard Worker# You may obtain a copy of the License at
12*35238bceSAndroid Build Coastguard Worker#
13*35238bceSAndroid Build Coastguard Worker#      http://www.apache.org/licenses/LICENSE-2.0
14*35238bceSAndroid Build Coastguard Worker#
15*35238bceSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
16*35238bceSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
17*35238bceSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18*35238bceSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
19*35238bceSAndroid Build Coastguard Worker# limitations under the License.
20*35238bceSAndroid Build Coastguard Worker#
21*35238bceSAndroid Build Coastguard Worker#-------------------------------------------------------------------------
22*35238bceSAndroid Build Coastguard Worker
23*35238bceSAndroid Build Coastguard Workerimport os
24*35238bceSAndroid Build Coastguard Workerimport re
25*35238bceSAndroid Build Coastguard Workerimport sys
26*35238bceSAndroid Build Coastguard Workerimport time
27*35238bceSAndroid Build Coastguard Workerimport fnmatch
28*35238bceSAndroid Build Coastguard Worker
29*35238bceSAndroid Build Coastguard WorkerSRC_FILE_PATTERNS = [ "*.c", "*.h", "*.cpp", "*.hpp", "*.inl", "*.java", "*.aidl", "*.py" ]
30*35238bceSAndroid Build Coastguard WorkerCOPYRIGHT_PATTERN = r'Copyright \(C\) ([0-9]{4})(-[0-9]{4})? drawElements Ltd.'
31*35238bceSAndroid Build Coastguard WorkerCOPYRIGHT_REPLACEMENT = r'Copyright (C) \1-' + time.strftime("%Y") + r' drawElements Ltd.'
32*35238bceSAndroid Build Coastguard Worker
33*35238bceSAndroid Build Coastguard Workerdef isSrcFile (filename):
34*35238bceSAndroid Build Coastguard Worker    for pattern in SRC_FILE_PATTERNS:
35*35238bceSAndroid Build Coastguard Worker        if fnmatch.fnmatch(filename, pattern):
36*35238bceSAndroid Build Coastguard Worker            return True
37*35238bceSAndroid Build Coastguard Worker    return False
38*35238bceSAndroid Build Coastguard Worker
39*35238bceSAndroid Build Coastguard Workerdef findSrcFiles (dir):
40*35238bceSAndroid Build Coastguard Worker    srcFiles = []
41*35238bceSAndroid Build Coastguard Worker    for root, dirs, files in os.walk(dir):
42*35238bceSAndroid Build Coastguard Worker        for file in files:
43*35238bceSAndroid Build Coastguard Worker            if isSrcFile(file):
44*35238bceSAndroid Build Coastguard Worker                srcFiles.append(os.path.join(root, file))
45*35238bceSAndroid Build Coastguard Worker    return srcFiles
46*35238bceSAndroid Build Coastguard Worker
47*35238bceSAndroid Build Coastguard Workerdef processFile (filename):
48*35238bceSAndroid Build Coastguard Worker    print(filename)
49*35238bceSAndroid Build Coastguard Worker    file = open(filename, "rb")
50*35238bceSAndroid Build Coastguard Worker    data = file.read()
51*35238bceSAndroid Build Coastguard Worker    file.close()
52*35238bceSAndroid Build Coastguard Worker    data = re.sub(COPYRIGHT_PATTERN, COPYRIGHT_REPLACEMENT, data)
53*35238bceSAndroid Build Coastguard Worker    file = open(filename, "wb")
54*35238bceSAndroid Build Coastguard Worker    file.write(data)
55*35238bceSAndroid Build Coastguard Worker    file.close()
56*35238bceSAndroid Build Coastguard Worker
57*35238bceSAndroid Build Coastguard Workerdef processDir (dir):
58*35238bceSAndroid Build Coastguard Worker    srcFiles = findSrcFiles(dir)
59*35238bceSAndroid Build Coastguard Worker    for file in srcFiles:
60*35238bceSAndroid Build Coastguard Worker        processFile(file)
61*35238bceSAndroid Build Coastguard Worker
62*35238bceSAndroid Build Coastguard Workerif __name__ == "__main__":
63*35238bceSAndroid Build Coastguard Worker    if len(sys.argv) < 2:
64*35238bceSAndroid Build Coastguard Worker        print(sys.argv[0] + ": [directory]")
65*35238bceSAndroid Build Coastguard Worker    else:
66*35238bceSAndroid Build Coastguard Worker        processDir(sys.argv[1])
67