-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaddgpl.py
92 lines (74 loc) · 2.81 KB
/
addgpl.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
import os
SRC_FILE_EXTNS = ['.java', '.xml']
JAVA_GPL = """/*
Copyright (C) 2009 Gopalkrishna Sharma.
Email: [email protected] / [email protected]
This file is part of WakeUp!.
Wake Up! is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Wake Up! 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 Wake Up!. If not, see <http://www.gnu.org/licenses/>.
*/
"""
XML_GPL = """<!--
Copyright (C) 2009 Gopalkrishna Sharma.
Email: [email protected] / [email protected]
This file is part of WakeUp!.
Wake Up! is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Wake Up! 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 Wake Up!. If not, see <http://www.gnu.org/licenses/>.
-->
"""
XML_ENCODING_STR = """<?xml version="1.0" encoding="utf-8"?>"""
def addGPLToFile(filename):
gplmsg = ""
fin = open(filename, 'r')
content = fin.read()
fin.close()
if (filename.endswith('.xml')):
if -1 == content.find(XML_ENCODING_STR):
content = XML_GPL + content
else:
content = content.replace(XML_ENCODING_STR, XML_ENCODING_STR + "\n" + XML_GPL)
elif filename.endswith('.java'):
content = JAVA_GPL + content
else:
raise ValueError, "Source file GPL message can be added only to .java and .xml files"
fout = open(filename, 'w')
fout.write(content)
fout.close()
def isSrcFile(filename):
for extn in SRC_FILE_EXTNS:
if filename.endswith(extn):
return True
return False
def getAllSrcFiles(rootdir):
files = []
entries = os.listdir(rootdir)
for entry in entries:
entry = os.path.join(rootdir, entry)
if os.path.isdir(entry):
for f in getAllSrcFiles(entry):
files.append(f)
if os.path.isfile(entry) and isSrcFile(entry):
files.append(entry)
return files
def main():
for srcfile in getAllSrcFiles('.'):
print "Adding GPL statement to file:", srcfile
addGPLToFile(srcfile)
if __name__ == '__main__':
main()