39 parser = ArgumentParser(
40 "Simple script to update the copyright year in the files passed on the command line"
45 default=os.environ.get(
"CHECK_ONLY"),
46 help=
"Check for presence of copyright (do not update years)",
52 help=
"Check for presence of copyright (do not update years)",
58 default=datetime.datetime.now().year,
59 help=
"Year to use [default: current year]",
61 parser.add_argument(
"files", nargs=
"+", help=
"Files to update")
63 args = parser.parse_args()
65 exp = re.compile(
r"[Cc]opyright.*(\d{4}-)?\d{4} CERN")
67 missing_copyright = []
68 for file
in args.files:
69 with open(file,
"r")
as f:
70 content = f.readlines()
72 if not any(COPYRIGHT_SIGNATURE.search(line)
for line
in content):
73 missing_copyright.append(file)
75 elif not args.check_only:
78 update_year(line, args.year)
if exp.search(line)
else line
82 if new_content != content:
83 with open(file,
"w")
as f:
84 f.writelines(new_content)
88 "The following files are missing a copyright line:\n - "
89 +
"\n - ".join(missing_copyright)