Debian Codegraph @

scripts/update-license

raw symbols SCIP
1 #!/usr/bin/python
2
3 # This file is part of Dust Racing (DustRAC).
4 # Copyright (C) 2011 Jussi Lind <[email protected]>
5 #
6 # DustRAC is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 # DustRAC is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with DustRAC. If not, see <http://www.gnu.org/licenses/>.
17 #
18 # Usage:
19 #
20 # This script replaces the license plate of the given file(s) with
21 # the given new license plate. license lines MUST begin with "//".
22 #
23 # e.g. python license.py gpl_header.txt `find . -name "*.hh"`
24
25 import sys
26
27 def main(argv):
28
29 if len(argv) < 3:
30 print("Usage: python license.py [licenseHeaderFile] [sourceFiles]")
31 return 1
32
33 # Read the new license
34 fName = argv[1]
35 print("Opening " + fName + " for read..")
36 f = open(fName, 'r')
37 licenseLines = f.readlines()
38 f.close()
39
40 for j in xrange(2, len(argv)):
41 fName = argv[j]
42
43 # Read the original file
44 print("Opening " + fName + " for read..")
45 f = open(fName, 'r')
46 origLines = f.readlines()
47 f.close()
48
49 # Skip the current license plate
50 headerSkip = True
51 newLines = []
52 for i in origLines:
53 if (i.find('//') == 0 or i.find('\n') == 0) and headerSkip:
54 pass
55 else:
56 headerSkip = False
57 newLines.append(i)
58
59 # Add the new license
60 newLines = licenseLines + newLines
61
62 # Modify the source file
63 print("Opening " + fName + " for write..")
64 f = open(fName, 'w')
65 f.writelines(newLines)
66 f.close()
67
68 print("Done.")
69 return 0
70
71 if __name__ == '__main__':
72 main(sys.argv)
73