Added 'list_only' option (and modified 'run()' to respect it).
[python/dscho.git] / Tools / scripts / fixnotice.py
blobcf6f140b8c1b535ff41f3b1312f5d3ed0b64acc6
1 #! /usr/bin/env python
3 OLD_NOTICE = """
4 Permission to use, copy, modify, and distribute this software and its
5 documentation for any purpose and without fee is hereby granted,
6 provided that the above copyright notice appear in all copies and that
7 both that copyright notice and this permission notice appear in
8 supporting documentation, and that the names of Stichting Mathematisch
9 Centrum or CWI not be used in advertising or publicity pertaining to
10 distribution of the software without specific, written prior permission.
12 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
13 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
14 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
15 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
18 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 """
21 NEW_NOTICE = """
22 Permission to use, copy, modify, and distribute this software and its
23 documentation for any purpose and without fee is hereby granted,
24 provided that the above copyright notice appear in all copies and that
25 both that copyright notice and this permission notice appear in
26 supporting documentation, and that the names of Stichting Mathematisch
27 Centrum or CWI or Corporation for National Research Initiatives or
28 CNRI not be used in advertising or publicity pertaining to
29 distribution of the software without specific, written prior
30 permission.
32 While CWI is the initial source for this software, a modified version
33 is made available by the Corporation for National Research Initiatives
34 (CNRI) at the Internet address ftp://ftp.python.org.
36 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
37 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
38 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
39 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
40 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
41 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
42 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
43 PERFORMANCE OF THIS SOFTWARE.
44 """
46 # " <-- Help Emacs
48 import os, sys, string
50 def main():
51 args = sys.argv[1:]
52 if not args:
53 print "No arguments."
54 for arg in args:
55 process(arg)
57 def process(arg):
58 f = open(arg)
59 data = f.read()
60 f.close()
61 i = string.find(data, OLD_NOTICE)
62 if i < 0:
63 ## print "No old notice in", arg
64 return
65 data = data[:i] + NEW_NOTICE + data[i+len(OLD_NOTICE):]
66 new = arg + ".new"
67 backup = arg + ".bak"
68 print "Replacing notice in", arg, "...",
69 sys.stdout.flush()
70 f = open(new, "w")
71 f.write(data)
72 f.close()
73 os.rename(arg, backup)
74 os.rename(new, arg)
75 print "done"
77 if __name__ == '__main__':
78 main()