forked from crs4/pydoop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbump_copyright_year
More file actions
executable file
·53 lines (39 loc) · 1.27 KB
/
Copy pathbump_copyright_year
File metadata and controls
executable file
·53 lines (39 loc) · 1.27 KB
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
#!/usr/bin/env python
"""\
Set copyright end year across the distribution.
"""
import sys
import os
import re
import argparse
import datetime
THIS_YEAR = datetime.date.today().year
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
PATTERN = re.compile(r"(?<=opyright 2009-)\d+")
def find_files(root_dir):
for d, subdirs, fnames in os.walk(root_dir, topdown=True):
for fn in fnames:
yield os.path.join(d, fn)
subdirs[:] = [_ for _ in subdirs if _ != ".git"]
def bump_end_year(root_dir, year):
year = "%d" % year
for fn in find_files(root_dir):
if fn == os.path.abspath(__file__):
continue
print "processing %r" % (fn,)
with open(fn) as f:
content = f.read()
with open(fn, "w") as f:
f.write(re.sub(PATTERN, year, content))
def make_parser():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("-y", type=int, metavar="YYYY", default=THIS_YEAR,
help="copyright end year (default = current)")
return parser
def main(argv):
parser = make_parser()
args = parser.parse_args(argv[1:])
repo_root = os.path.dirname(THIS_DIR)
bump_end_year(repo_root, args.y)
if __name__ == "__main__":
main(sys.argv)