-
Notifications
You must be signed in to change notification settings - Fork 4
/
banner-helper.py
executable file
·62 lines (47 loc) · 1.47 KB
/
banner-helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
BANNER = """// ===================================================================================================
// Copyright (C) %d Kaltura Inc.
//
// Licensed under the AGPLv3 license, unless a different license for a
// particular library is specified in the applicable library path.
//
// You may obtain a copy of the License at
// https://www.gnu.org/licenses/agpl-3.0.html
// ===================================================================================================
"""
import os
from sys import exit
from datetime import datetime
FIRST_YEAR = 2017
THIS_YEAR = datetime.now().year
def has_banner(d):
d = d.lstrip()
for year in xrange(FIRST_YEAR, THIS_YEAR + 1):
if d.startswith(BANNER % year):
return True
return False
def process(dir):
global modified_files
banner = BANNER % THIS_YEAR
for root, dirs, files in os.walk(dir):
for name in files:
fileExt = os.path.splitext(name)[1]
if fileExt != '.swift':
continue
fullPath = os.path.join(root, name)
d = file(fullPath, 'rb').read()
if has_banner(d):
continue
# Remove xcode-generated banner
lines = d.split('\n')
for i in xrange(len(lines)):
if not lines[i].startswith('//'):
break
d = banner + '\n' + '\n'.join(lines[i:])
file(fullPath, 'wb').write(d)
modified_files += 1
modified_files = 0
for dir in ('Sources',):
process(dir)
# exit with 0 (OK) if there was at least one change.
exit(0 if modified_files > 0 else 1)