2016-08-28 17:01:52 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""
|
2015-12-13 14:51:43 +01:00
|
|
|
Run this script to update all the copyright headers of files
|
|
|
|
that were changed this year.
|
2014-02-08 22:50:24 +01:00
|
|
|
|
2015-12-13 14:51:43 +01:00
|
|
|
For example:
|
2014-02-08 22:50:24 +01:00
|
|
|
|
2015-12-13 14:51:43 +01:00
|
|
|
// Copyright (c) 2009-2012 The Bitcoin Core developers
|
2014-02-08 22:50:24 +01:00
|
|
|
|
|
|
|
it will change it to
|
|
|
|
|
2015-12-13 14:51:43 +01:00
|
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
2016-08-28 17:01:52 +02:00
|
|
|
"""
|
|
|
|
import subprocess
|
2014-02-08 22:50:24 +01:00
|
|
|
import time
|
2015-12-13 14:51:43 +01:00
|
|
|
import re
|
2014-02-08 22:50:24 +01:00
|
|
|
|
2016-08-28 17:01:52 +02:00
|
|
|
CMD_GIT_LIST_FILES = ['git', 'ls-files']
|
|
|
|
CMD_GIT_DATE = ['git', 'log', '--format=%ad', '--date=short', '-1']
|
|
|
|
CMD_PERL_REGEX = ['perl', '-pi', '-e']
|
|
|
|
REGEX_TEMPLATE = 's/(20\\d\\d)(?:-20\\d\\d)? The Bitcoin/$1-%s The Bitcoin/'
|
2014-02-08 22:50:24 +01:00
|
|
|
|
2016-08-28 17:01:52 +02:00
|
|
|
FOLDERS = ["qa/", "src/"]
|
2015-12-13 14:51:43 +01:00
|
|
|
EXTENSIONS = [".cpp",".h", ".py"]
|
2014-02-08 22:50:24 +01:00
|
|
|
|
2016-08-28 17:01:52 +02:00
|
|
|
|
2015-12-13 14:51:43 +01:00
|
|
|
def get_git_date(file_path):
|
2016-08-28 17:01:52 +02:00
|
|
|
d = subprocess.run(CMD_GIT_DATE + [file_path],
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
check=True,
|
|
|
|
universal_newlines=True).stdout
|
|
|
|
# yyyy-mm-dd
|
|
|
|
return d.split('-')[0]
|
|
|
|
|
|
|
|
|
|
|
|
def skip_file(file_path):
|
|
|
|
for ext in EXTENSIONS:
|
|
|
|
if file_path.endswith(ext):
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
year = str(time.gmtime()[0])
|
|
|
|
regex_current = re.compile("%s The Bitcoin" % year)
|
|
|
|
n = 1
|
|
|
|
for folder in FOLDERS:
|
|
|
|
for file_path in subprocess.run(
|
|
|
|
CMD_GIT_LIST_FILES + [folder],
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
check=True,
|
|
|
|
universal_newlines=True
|
|
|
|
).stdout.split("\n"):
|
|
|
|
if skip_file(file_path):
|
|
|
|
# print(file_path, "(skip)")
|
|
|
|
continue
|
|
|
|
git_date = get_git_date(file_path)
|
|
|
|
if not year == git_date:
|
|
|
|
# print(file_path, year, "(skip)")
|
|
|
|
continue
|
|
|
|
if regex_current.search(open(file_path, "r").read()) is not None:
|
|
|
|
# already up to date
|
|
|
|
# print(file_path, year, "(skip)")
|
|
|
|
continue
|
|
|
|
print(n, file_path, "(update to %s)" % year)
|
|
|
|
subprocess.run(CMD_PERL_REGEX + [REGEX_TEMPLATE % year, file_path], check=True)
|
2015-12-13 14:51:43 +01:00
|
|
|
n = n + 1
|