diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-02-16 11:44:18 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-02-16 11:44:48 +0100 |
commit | b8d9058a4d1ce28eefa65aa3339bcc52b3c014e9 (patch) | |
tree | 6a8e0611ff2ca8782c4d9bfcad82fde8d473b1f5 /contrib/devtools/fix-copyright-headers.py | |
parent | 25d816110ba28c5014b23c9a363c472fc28a3891 (diff) | |
parent | 57702541a2009d4b936ebfddeeec3db7f8f74e5c (diff) | |
download | bitcoin-b8d9058a4d1ce28eefa65aa3339bcc52b3c014e9.tar.xz |
Merge pull request #3646
5770254 Copyright header updates s/2013/2014 on files whose last git commit was done in 2014. contrib/devtools/fix-copyright-headers.py script to be able to perform this maintenance task with ease during the rest of the year, every year. Modifications to contrib/devtools/README.md to document what fix-copyright-headers.py does. (gubatron)
Diffstat (limited to 'contrib/devtools/fix-copyright-headers.py')
-rwxr-xr-x | contrib/devtools/fix-copyright-headers.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/contrib/devtools/fix-copyright-headers.py b/contrib/devtools/fix-copyright-headers.py new file mode 100755 index 0000000000..52fdc99144 --- /dev/null +++ b/contrib/devtools/fix-copyright-headers.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +''' +Run this script inside of src/ and it will look for all the files +that were changed this year that still have the last year in the +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 + +// Copyright (c) 2009-2013 The Bitcoin developers + +it will change it to + +// Copyright (c) 2009-2014 The Bitcoin developers + +It will do this for all the files in the folder and its children. + +Author: @gubatron +''' +import os +import time + +year = time.gmtime()[0] +last_year = year - 1 +command = "perl -pi -e 's/%s The Bitcoin/%s The Bitcoin/' %s" +listFilesCommand = "find . | grep %s" + +extensions = [".cpp",".h"] + +def getLastGitModifiedDate(filePath): + gitGetLastCommitDateCommand = "git log " + filePath +" | grep Date | head -n 1" + p = os.popen(gitGetLastCommitDateCommand) + result = "" + for l in p: + result = l + break + result = result.replace("\n","") + return result + +n=1 +for extension in extensions: + foundFiles = os.popen(listFilesCommand % extension) + for filePath in foundFiles: + filePath = filePath[1:-1] + if filePath.endswith(extension): + filePath = os.getcwd() + filePath + modifiedTime = getLastGitModifiedDate(filePath) + if len(modifiedTime) > 0 and str(year) in modifiedTime: + print n,"Last Git Modified: ", modifiedTime, " - ", filePath + os.popen(command % (last_year,year,filePath)) + n = n + 1 + + |