Dash Core  0.12.2.1
P2P Digital Currency
fix-copyright-headers.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 '''
3 Run this script to update all the copyright headers of files
4 that were changed this year.
5 
6 For example:
7 
8 // Copyright (c) 2009-2012 The Bitcoin Core developers
9 
10 it will change it to
11 
12 // Copyright (c) 2009-2015 The Bitcoin Core developers
13 '''
14 import os
15 import time
16 import re
17 
18 year = time.gmtime()[0]
19 CMD_GIT_DATE = 'git log --format=@%%at -1 %s | date +"%%Y" -u -f -'
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"
23 
24 FOLDERS = ["./qa", "./src"]
25 EXTENSIONS = [".cpp",".h", ".py"]
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 ""
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 str(year) == 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