|
|
@ -1,5 +1,5 @@ |
|
|
|
#!/usr/bin/env python |
|
|
|
#!/usr/bin/env python3 |
|
|
|
''' |
|
|
|
""" |
|
|
|
Run this script to update all the copyright headers of files |
|
|
|
Run this script to update all the copyright headers of files |
|
|
|
that were changed this year. |
|
|
|
that were changed this year. |
|
|
|
|
|
|
|
|
|
|
@ -10,37 +10,58 @@ For example: |
|
|
|
it will change it to |
|
|
|
it will change it to |
|
|
|
|
|
|
|
|
|
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers |
|
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers |
|
|
|
''' |
|
|
|
""" |
|
|
|
import os |
|
|
|
import subprocess |
|
|
|
import time |
|
|
|
import time |
|
|
|
import re |
|
|
|
import re |
|
|
|
|
|
|
|
|
|
|
|
year = time.gmtime()[0] |
|
|
|
CMD_GIT_LIST_FILES = ['git', 'ls-files'] |
|
|
|
CMD_GIT_DATE = 'git log --format=%%ad --date=short -1 %s | cut -d"-" -f 1' |
|
|
|
CMD_GIT_DATE = ['git', 'log', '--format=%ad', '--date=short', '-1'] |
|
|
|
CMD_REGEX= "perl -pi -e 's/(20\d\d)(?:-20\d\d)? The Bitcoin/$1-%s The Bitcoin/' %s" |
|
|
|
CMD_PERL_REGEX = ['perl', '-pi', '-e'] |
|
|
|
REGEX_CURRENT= re.compile("%s The Bitcoin" % year) |
|
|
|
REGEX_TEMPLATE = 's/(20\\d\\d)(?:-20\\d\\d)? The Bitcoin/$1-%s The Bitcoin/' |
|
|
|
CMD_LIST_FILES= "find %s | grep %s" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FOLDERS = ["./qa", "./src"] |
|
|
|
FOLDERS = ["qa/", "src/"] |
|
|
|
EXTENSIONS = [".cpp",".h", ".py"] |
|
|
|
EXTENSIONS = [".cpp",".h", ".py"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_git_date(file_path): |
|
|
|
def get_git_date(file_path): |
|
|
|
r = os.popen(CMD_GIT_DATE % file_path) |
|
|
|
d = subprocess.run(CMD_GIT_DATE + [file_path], |
|
|
|
for l in r: |
|
|
|
stdout=subprocess.PIPE, |
|
|
|
# Result is one line, so just return |
|
|
|
check=True, |
|
|
|
return l.replace("\n","") |
|
|
|
universal_newlines=True).stdout |
|
|
|
return "" |
|
|
|
# yyyy-mm-dd |
|
|
|
|
|
|
|
return d.split('-')[0] |
|
|
|
n=1 |
|
|
|
|
|
|
|
for folder in FOLDERS: |
|
|
|
|
|
|
|
for extension in EXTENSIONS: |
|
|
|
def skip_file(file_path): |
|
|
|
for file_path in os.popen(CMD_LIST_FILES % (folder, extension)): |
|
|
|
for ext in EXTENSIONS: |
|
|
|
file_path = os.getcwd() + file_path[1:-1] |
|
|
|
if file_path.endswith(ext): |
|
|
|
if file_path.endswith(extension): |
|
|
|
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) |
|
|
|
git_date = get_git_date(file_path) |
|
|
|
if str(year) == git_date: |
|
|
|
if not year == git_date: |
|
|
|
# Only update if current year is not found |
|
|
|
# print(file_path, year, "(skip)") |
|
|
|
if REGEX_CURRENT.search(open(file_path, "r").read()) is None: |
|
|
|
continue |
|
|
|
print n,"Last git edit", git_date, "-", file_path |
|
|
|
if regex_current.search(open(file_path, "r").read()) is not None: |
|
|
|
os.popen(CMD_REGEX % (year,file_path)) |
|
|
|
# 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) |
|
|
|
n = n + 1 |
|
|
|
n = n + 1 |
|
|
|