28 '''change the copy right year 39 def extend_copyright(line, year):
40 '''year is the year which you want to extend to''' 43 p2014 = re.compile(
r'.*{}.*'.format(year))
48 p20xx_bb = re.compile(
r'(.*)(20\d\d)(-)(\d\d)(.*)')
49 m = p20xx_bb.match(line)
51 return p20xx_bb.sub(
r'\g<1>\g<2>\g<3>{}\g<5>'.format(year), line)
54 p20xx = re.compile(
r'(.*)(20\d\d)(.*)')
57 return p20xx.sub(
r'\g<1>\g<2>-{}\g<3>'.format(year), line)
59 def replace_line(file,search_exp,replace_exp):
60 for line
in fileinput.input(file, inplace=1):
61 if search_exp
in line:
62 line = line.replace(search_exp, replace_exp)
63 sys.stdout.write(line)
67 if extend_copyright(
'Copyright 2011-12 ARM Limited', year) !=
'Copyright 2011-14 ARM Limited':
71 if extend_copyright(
'Copyright 2013-14 ARM Limited', year) !=
'Copyright 2013-14 ARM Limited':
75 if extend_copyright(
'Copyright 2012 ARM Limited', year) !=
'Copyright 2012-14 ARM Limited':
79 if extend_copyright(
'Copyright 2014 ARM Limited', year) !=
'Copyright 2014 ARM Limited':
86 def extend_copyright_all(extend_to_year):
88 for root, dirs, files
in os.walk(os.getcwd()):
91 if f != os.path.basename(sys.argv[0]):
92 all_files.append(os.path.join(root, f))
94 pcopy_right = re.compile(
r'.*Copyright [0-9-]* ARM Limited.*')
97 for line
in fd.readlines():
98 m = pcopy_right.match(line)
100 old_line = m.group(0)
101 new_line = extend_copyright(old_line, extend_to_year)
103 replace_line(f, old_line, new_line)
106 parser = argparse.ArgumentParser(description=
'Extend copyright year to the year you specified.')
107 parser.add_argument(
'year', nargs=
'?', help=
'year you want to extend, only 2 digitals, e.g.\'14\'')
108 parser.add_argument(
'-t',
'--test', action=
'store_true', help=
'run the test')
109 args = parser.parse_args()
115 pdigital2 = re.compile(
r'^\d\d$')
116 if args.year
and pdigital2.search(args.year):
117 extend_copyright_all(args.year)
121 if __name__ ==
'__main__':