]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/jaeger-client-cpp/scripts/update-license.py
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / jaeger-client-cpp / scripts / update-license.py
CommitLineData
f67539c2
TL
1from __future__ import (
2 absolute_import, print_function, division, unicode_literals
3)
4
5import logging
6import re
7import sys
8from datetime import datetime
9
10logging.basicConfig(level=logging.DEBUG)
11logger = logging.getLogger(__name__)
12
13CURRENT_YEAR = datetime.today().year
14
15LICENSE_BLOB = """Copyright (c) %d Uber Technologies, Inc.
16
17Licensed under the Apache License, Version 2.0 (the "License");
18you may not use this file except in compliance with the License.
19You may obtain a copy of the License at
20
21http://www.apache.org/licenses/LICENSE-2.0
22
23Unless required by applicable law or agreed to in writing, software
24distributed under the License is distributed on an "AS IS" BASIS,
25WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26See the License for the specific language governing permissions and
27limitations under the License.""" % CURRENT_YEAR
28
29
30def comment_block(license_blob):
31 lines = ['/*\n']
32 lines += [(' * ' + l).rstrip() + '\n'
33 for l in license_blob.split('\n')]
34 lines.append(' */\n')
35 return lines
36
37
38LICENSE_BLOB_LINES_CPP = comment_block(LICENSE_BLOB)
39
40COPYRIGHT_RE = re.compile(r'Copyright \(c\) (\d+)', re.I)
41
42
43def update_cpp_license(name, force=False):
44 with open(name) as f:
45 orig_lines = list(f)
46 lines = list(orig_lines)
47
48 found = False
49 changed = False
50 for i, line in enumerate(lines[:5]):
51 m = COPYRIGHT_RE.search(line)
52 if not m:
53 continue
54
55 found = True
56 year = int(m.group(1))
57 if year == CURRENT_YEAR:
58 break
59
60 new_line = COPYRIGHT_RE.sub('Copyright (c) %d' % CURRENT_YEAR, line)
61 assert line != new_line, ('Could not change year in: %s' % line)
62 lines[i] = new_line
63 changed = True
64 break
65
66 if not found:
67 if 'Code generated by' in lines[0]:
68 lines[1:1] = ['\n'] + LICENSE_BLOB_LINES_CPP
69 else:
70 lines[0:0] = LICENSE_BLOB_LINES_CPP + ['\n']
71 changed = True
72
73 if changed:
74 with open(name, 'w') as f:
75 for line in lines:
76 f.write(line)
77 print(name)
78
79
80def main():
81 if len(sys.argv) == 1:
82 print('USAGE: %s FILE ...' % sys.argv[0])
83 sys.exit(1)
84
85 for name in sys.argv[1:]:
86 if name.endswith('.cpp') or \
87 name.endswith('.h') or \
88 name.endswith('.h.in'):
89 try:
90 update_cpp_license(name)
91 except Exception as error:
92 logger.error('Failed to process file %s', name)
93 logger.exception(error)
94 raise error
95 else:
96 raise NotImplementedError('Unsupported file type: %s' % name)
97
98
99if __name__ == "__main__":
100 main()