3 """(Ostensibly) fix copyright notices in files.
5 Actually, this sript will simply replace a block of text in a file from one
6 string to another. It will only do this once though, i.e. not globally
7 throughout the file. It writes a backup file and then does an os.rename()
10 Usage: fixnotices.py [options] [filenames]
13 Print this message and exit
16 Use the notice in the file as the old (to be replaced) string, instead
17 of the hard coded value in the script.
20 Use the notice in the file as the new (replacement) string, instead of
21 the hard coded value in the script.
24 Don't actually make the changes, but print out the list of files that
25 would change. When used with -v, a status will be printed for every
29 Print a message for every file looked at, indicating whether the file
33 OLD_NOTICE
= """/***********************************************************
34 Copyright (c) 2000, BeOpen.com.
35 Copyright (c) 1995-2000, Corporation for National Research Initiatives.
36 Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
39 See the file "Misc/COPYRIGHT" for information on usage and
40 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
41 ******************************************************************/
52 def usage(code
, msg
=''):
53 print __doc__
% globals()
60 global DRYRUN
, OLD_NOTICE
, NEW_NOTICE
, VERBOSE
62 opts
, args
= getopt
.getopt(sys
.argv
[1:], 'hv',
63 ['help', 'oldnotice=', 'newnotice=',
64 'dry-run', 'verbose'])
65 except getopt
.error
, msg
:
69 if opt
in ('-h', '--help'):
71 elif opt
in ('-v', '--verbose'):
73 elif opt
== '--dry-run':
75 elif opt
== '--oldnotice':
77 OLD_NOTICE
= fp
.read()
79 elif opt
== '--newnotice':
81 NEW_NOTICE
= fp
.read()
92 i
= data
.find(OLD_NOTICE
)
95 print 'no change:', file
97 elif DRYRUN
or VERBOSE
:
98 print ' change:', file
100 # Don't actually change the file
102 data
= data
[:i
] + NEW_NOTICE
+ data
[i
+len(OLD_NOTICE
):]
104 backup
= file + ".bak"
108 os
.rename(file, backup
)
112 if __name__
== '__main__':