|
1 | 1 | #!/usr/bin/env python |
2 | 2 | ''' |
3 | | -Run this script inside of src/ and it will look for all the files |
4 | | -that were changed this year that still have the last year in the |
5 | | -copyright headers, and it will fix the headers on that file using |
6 | | -a perl regex one liner. |
| 3 | +Run this script to update all the copyright headers of files |
| 4 | +that were changed this year. |
7 | 5 |
|
8 | | -For example: if it finds something like this and we're in 2014 |
| 6 | +For example: |
9 | 7 |
|
10 | | -// Copyright (c) 2009-2013 The Bitcoin Core developers |
| 8 | +// Copyright (c) 2009-2012 The Bitcoin Core developers |
11 | 9 |
|
12 | 10 | it will change it to |
13 | 11 |
|
14 | | -// Copyright (c) 2009-2014 The Bitcoin Core developers |
15 | | -
|
16 | | -It will do this for all the files in the folder and its children. |
17 | | -
|
18 | | -Author: @gubatron |
| 12 | +// Copyright (c) 2009-2015 The Bitcoin Core developers |
19 | 13 | ''' |
20 | 14 | import os |
21 | 15 | import time |
| 16 | +import re |
22 | 17 |
|
23 | 18 | year = time.gmtime()[0] |
24 | | -last_year = year - 1 |
25 | | -command = "perl -pi -e 's/%s The Bitcoin/%s The Bitcoin/' %s" |
26 | | -listFilesCommand = "find . | grep %s" |
27 | | - |
28 | | -extensions = [".cpp",".h"] |
29 | | - |
30 | | -def getLastGitModifiedDate(filePath): |
31 | | - gitGetLastCommitDateCommand = "git log " + filePath +" | grep Date | head -n 1" |
32 | | - p = os.popen(gitGetLastCommitDateCommand) |
33 | | - result = "" |
34 | | - for l in p: |
35 | | - result = l |
36 | | - break |
37 | | - result = result.replace("\n","") |
38 | | - return result |
| 19 | +CMD_GIT_DATE = "git log %s | grep Date | head -n 1" |
| 20 | +CMD_REGEX= "perl -pi -e 's/(20\d\d)(?:-20\d\d)? The Bitcoin/$1-%s The Bitcoin/' %s" |
| 21 | +REGEX_CURRENT= re.compile("%s The Bitcoin" % year) |
| 22 | +CMD_LIST_FILES= "find %s | grep %s" |
39 | 23 |
|
40 | | -n=1 |
41 | | -for extension in extensions: |
42 | | - foundFiles = os.popen(listFilesCommand % extension) |
43 | | - for filePath in foundFiles: |
44 | | - filePath = filePath[1:-1] |
45 | | - if filePath.endswith(extension): |
46 | | - filePath = os.getcwd() + filePath |
47 | | - modifiedTime = getLastGitModifiedDate(filePath) |
48 | | - if len(modifiedTime) > 0 and str(year) in modifiedTime: |
49 | | - print n,"Last Git Modified: ", modifiedTime, " - ", filePath |
50 | | - os.popen(command % (last_year,year,filePath)) |
51 | | - n = n + 1 |
| 24 | +FOLDERS = ["./qa", "./src"] |
| 25 | +EXTENSIONS = [".cpp",".h", ".py"] |
52 | 26 |
|
| 27 | +def get_git_date(file_path): |
| 28 | + r = os.popen(CMD_GIT_DATE % file_path) |
| 29 | + for l in r: |
| 30 | + # Result is one line, so just return |
| 31 | + return l.replace("\n","") |
| 32 | + return "" |
53 | 33 |
|
| 34 | +n=1 |
| 35 | +for folder in FOLDERS: |
| 36 | + for extension in EXTENSIONS: |
| 37 | + for file_path in os.popen(CMD_LIST_FILES % (folder, extension)): |
| 38 | + file_path = os.getcwd() + file_path[1:-1] |
| 39 | + if file_path.endswith(extension): |
| 40 | + git_date = get_git_date(file_path) |
| 41 | + if len(git_date) > 0 and str(year) in git_date: |
| 42 | + # Only update if current year is not found |
| 43 | + if REGEX_CURRENT.search(open(file_path, "r").read()) is None: |
| 44 | + print n,"Last git edit", git_date, "-", file_path |
| 45 | + os.popen(CMD_REGEX % (year,file_path)) |
| 46 | + n = n + 1 |
0 commit comments