mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
[devtools] Rewrite fix-copyright-headers.py
This commit is contained in:
parent
3cd836c1d8
commit
fa6ad855e9
@ -11,16 +11,16 @@ fix-copyright-headers.py
|
|||||||
========================
|
========================
|
||||||
|
|
||||||
Every year newly updated files need to have its copyright headers updated to reflect the current year.
|
Every year newly updated files need to have its copyright headers updated to reflect the current year.
|
||||||
If you run this script from src/ it will automatically update the year on the copyright header for all
|
If you run this script from the root folder it will automatically update the year on the copyright header for all
|
||||||
.cpp and .h files if these have a git commit from the current year.
|
source files if these have a git commit from the current year.
|
||||||
|
|
||||||
For example a file changed in 2014 (with 2014 being the current year):
|
For example a file changed in 2015 (with 2015 being the current year):
|
||||||
|
|
||||||
```// Copyright (c) 2009-2013 The Bitcoin Core developers```
|
```// Copyright (c) 2009-2013 The Bitcoin Core developers```
|
||||||
|
|
||||||
would be changed to:
|
would be changed to:
|
||||||
|
|
||||||
```// Copyright (c) 2009-2014 The Bitcoin Core developers```
|
```// Copyright (c) 2009-2015 The Bitcoin Core developers```
|
||||||
|
|
||||||
git-subtree-check.sh
|
git-subtree-check.sh
|
||||||
====================
|
====================
|
||||||
|
@ -1,53 +1,46 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
'''
|
'''
|
||||||
Run this script inside of src/ and it will look for all the files
|
Run this script to update all the copyright headers of files
|
||||||
that were changed this year that still have the last year in the
|
that were changed this year.
|
||||||
copyright headers, and it will fix the headers on that file using
|
|
||||||
a perl regex one liner.
|
|
||||||
|
|
||||||
For example: if it finds something like this and we're in 2014
|
For example:
|
||||||
|
|
||||||
// Copyright (c) 2009-2013 The Bitcoin Core developers
|
// Copyright (c) 2009-2012 The Bitcoin Core developers
|
||||||
|
|
||||||
it will change it to
|
it will change it to
|
||||||
|
|
||||||
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
||||||
|
|
||||||
It will do this for all the files in the folder and its children.
|
|
||||||
|
|
||||||
Author: @gubatron
|
|
||||||
'''
|
'''
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import re
|
||||||
|
|
||||||
year = time.gmtime()[0]
|
year = time.gmtime()[0]
|
||||||
last_year = year - 1
|
CMD_GIT_DATE = "git log %s | grep Date | head -n 1"
|
||||||
command = "perl -pi -e 's/%s The Bitcoin/%s The Bitcoin/' %s"
|
CMD_REGEX= "perl -pi -e 's/(20\d\d)(?:-20\d\d)? The Bitcoin/$1-%s The Bitcoin/' %s"
|
||||||
listFilesCommand = "find . | grep %s"
|
REGEX_CURRENT= re.compile("%s The Bitcoin" % year)
|
||||||
|
CMD_LIST_FILES= "find %s | grep %s"
|
||||||
|
|
||||||
extensions = [".cpp",".h"]
|
FOLDERS = ["./qa", "./src"]
|
||||||
|
EXTENSIONS = [".cpp",".h", ".py"]
|
||||||
|
|
||||||
def getLastGitModifiedDate(filePath):
|
def get_git_date(file_path):
|
||||||
gitGetLastCommitDateCommand = "git log " + filePath +" | grep Date | head -n 1"
|
r = os.popen(CMD_GIT_DATE % file_path)
|
||||||
p = os.popen(gitGetLastCommitDateCommand)
|
for l in r:
|
||||||
result = ""
|
# Result is one line, so just return
|
||||||
for l in p:
|
return l.replace("\n","")
|
||||||
result = l
|
return ""
|
||||||
break
|
|
||||||
result = result.replace("\n","")
|
|
||||||
return result
|
|
||||||
|
|
||||||
n=1
|
n=1
|
||||||
for extension in extensions:
|
for folder in FOLDERS:
|
||||||
foundFiles = os.popen(listFilesCommand % extension)
|
for extension in EXTENSIONS:
|
||||||
for filePath in foundFiles:
|
for file_path in os.popen(CMD_LIST_FILES % (folder, extension)):
|
||||||
filePath = filePath[1:-1]
|
file_path = os.getcwd() + file_path[1:-1]
|
||||||
if filePath.endswith(extension):
|
if file_path.endswith(extension):
|
||||||
filePath = os.getcwd() + filePath
|
git_date = get_git_date(file_path)
|
||||||
modifiedTime = getLastGitModifiedDate(filePath)
|
if len(git_date) > 0 and str(year) in git_date:
|
||||||
if len(modifiedTime) > 0 and str(year) in modifiedTime:
|
# Only update if current year is not found
|
||||||
print n,"Last Git Modified: ", modifiedTime, " - ", filePath
|
if REGEX_CURRENT.search(open(file_path, "r").read()) is None:
|
||||||
os.popen(command % (last_year,year,filePath))
|
print n,"Last git edit", git_date, "-", file_path
|
||||||
n = n + 1
|
os.popen(CMD_REGEX % (year,file_path))
|
||||||
|
n = n + 1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user