File: update-license

package info (click to toggle)
dustrac 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 28,396 kB
  • sloc: cpp: 43,805; ansic: 30,075; sh: 121; xml: 79; python: 33; makefile: 11
file content (73 lines) | stat: -rwxr-xr-x 2,108 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/python

# This file is part of Dust Racing (DustRAC).
# Copyright (C) 2011 Jussi Lind <jussi.lind@iki.fi>
# 
# DustRAC 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.
# DustRAC 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 DustRAC. If not, see <http://www.gnu.org/licenses/>.
# 
# Usage:
#
# This script replaces the license plate of the given file(s) with
# the given new license plate. license lines MUST begin with "//".
#
# e.g. python license.py gpl_header.txt `find . -name "*.hh"`

import sys

def main(argv):

    if len(argv) < 3:
        print("Usage: python license.py [licenseHeaderFile] [sourceFiles]")
        return 1

    # Read the new license
    fName = argv[1]
    print("Opening " + fName + " for read..")
    f = open(fName, 'r')
    licenseLines = f.readlines()
    f.close()

    for j in xrange(2, len(argv)):
        fName = argv[j]

        # Read the original file
        print("Opening " + fName + " for read..")
        f = open(fName, 'r')
        origLines = f.readlines()
        f.close()

        # Skip the current license plate
        headerSkip = True
        newLines   = []
        for i in origLines:
            if (i.find('//') == 0 or i.find('\n') == 0) and headerSkip:
                pass
            else:
                headerSkip = False
                newLines.append(i)

        # Add the new license
        newLines = licenseLines + newLines 

        # Modify the source file
        print("Opening " + fName + " for write..")
        f = open(fName, 'w')    
        f.writelines(newLines)
        f.close()

    print("Done.")
    return 0

if __name__ == '__main__':
    main(sys.argv)