aboutsummaryrefslogtreecommitdiff
path: root/contrib/devtools/fix-copyright-headers.py
blob: 5e849525485bca4586d9b9248bfb59a0cf3e59b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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 Core developers

it will change it to

// Copyright (c) 2009-2014 The Bitcoin Core 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