-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathaddheaders.py
110 lines (83 loc) · 4.69 KB
/
addheaders.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#
# Copyright (c) 2015-2018 Idiap Research Institute, http://www.idiap.ch/
# Written by James Newling <james.newling@gmail.com>
# All rights reserved.
#
# eakmeans is a library for exact and approximate k-means written in C++ and
# Python. This file is part of eakmeans. See file COPYING for more details.
#
# This file is part of eakmeans.
#
# eakmeans is free software: you can redistribute it and/or modify
# it under the terms of the 3-Clause BSD Licence. See
# https://opensource.org/licenses/BSD-3-Clause for more details.
#
# eakmeans is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See file
# COPYING for more details.
#
from IPython.core.debugger import Tracer
old_rawheader = r"""Copyright (c) 2015 Idiap Research Institute, http://www.idiap.ch/
Written by James Newling <jnewling@idiap.ch>
eakmeans is a library for exact and approximate k-means written in C++ and Python. This file is part of eakmeans. eakmeans is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation. eakmeans is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with eakmeans. If not, see <http://www.gnu.org/licenses/>.
"""
old_hashheader = r"""#Copyright (c) 2015 Idiap Research Institute, http://www.idiap.ch/
#Written by James Newling <jnewling@idiap.ch>
#eakmeans is a library for exact and approximate k-means written in C++ and Python. This file is part of eakmeans. eakmeans is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation. eakmeans is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with eakmeans. If not, see <http://www.gnu.org/licenses/>.
"""
old_cppheader = r"""/*
%s
*/
"""%(old_rawheader, )
new_rawheader = r"""
Copyright (c) 2015-2018 Idiap Research Institute, http://www.idiap.ch/
Written by James Newling <james.newling@gmail.com>
All rights reserved.
eakmeans is a library for exact and approximate k-means written in C++ and
Python. This file is part of eakmeans. See file COPYING for more details.
This file is part of eakmeans.
eakmeans is free software: you can redistribute it and/or modify
it under the terms of the 3-Clause BSD Licence. See
https://opensource.org/licenses/BSD-3-Clause for more details.
eakmeans is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See file
COPYING for more details.
"""
new_hashheader = '\n'.join(['# ' + l for l in new_rawheader.split('\n')]) + '\n'
new_cppheader = "/*%s*/\n\n" % new_rawheader
import os
import sys
import commands
hfiles = commands.getstatusoutput("find . -name \"*.h\"")[1].split("\n")
cppfiles = commands.getstatusoutput("find . -name \"*.cpp\"")[1].split("\n")
hppfiles = commands.getstatusoutput("find . -name \"*.hpp\"")[1].split("\n")
cppheaderable = hfiles + cppfiles + hppfiles
makefiles = commands.getstatusoutput("find . -name \"Makefile\"")[1].split("\n")
pyfiles = commands.getstatusoutput("find . -name \"*.py\"")[1].split("\n")
pyxfiles = commands.getstatusoutput("find . -name \"*.pyx\"")[1].split("\n")
pyxbldfiles = commands.getstatusoutput("find . -name \"*.pyxbld\"")[1].split("\n")
hashheaderable = makefiles + pyfiles + pyxfiles + pyxbldfiles
for files, old_header, new_header in zip(
[cppheaderable, hashheaderable],
[old_cppheader, old_hashheader],
[new_cppheader, new_hashheader]
):
for fn in files:
if fn:
sys.stdout.write("headering " + fn +"...")
filly = open(fn, "r")
lines = filly.read()
filly.close()
if lines.startswith(old_header):
lines = lines[len(old_header):]
if lines.startswith(new_header):
# already with header, skip this file
sys.stdout.write(" already done, skip.\n")
continue
filly = open(fn, "w")
filly.write(new_header)
filly.write(lines)
filly.close()
sys.stdout.write(" done.\n")