blob: 7b447fbfb7dfd0d41ac21ec30effde946709c705 [file] [log] [blame]
Guido van Rossuma7925f11994-01-26 10:20:16 +00001#! /usr/local/bin/python
2
3import regex
4import regsub
5import glob
6import sys
7import os
8import stat
9import getopt
10
11oldcprt = 'Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,\nAmsterdam, The Netherlands.'
12newcprt = 'Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,\nAmsterdam, The Netherlands.'
13
14oldprog = regex.compile(oldcprt)
15newprog = regex.compile(newcprt)
16
17def main():
18 opts, args = getopt.getopt(sys.argv[1:], 'y:')
19 agelimit = 0L
20 for opt, arg in opts:
21 if opt == '-y':
22 agelimit = os.stat(arg)[stat.ST_MTIME]
23 if not args:
24 args = glob.glob('*.[ch]')
25 for file in args:
26 try:
27 age = os.stat(file)[stat.ST_MTIME]
28 except os.error, msg:
29 print file, ': stat failed :', msg
30 continue
31 if age <= agelimit:
32 print file, ': too old, skipped'
33 continue
34 try:
35 f = open(file, 'r')
36 except IOError, msg:
37 print file, ': open failed :', msg
38 continue
39 head = f.read(1024)
40 if oldprog.search(head) < 0:
41 if newprog.search(head) < 0:
42 print file, ': NO COPYRIGHT FOUND'
43 else:
44 print file, ': (new copyright already there)'
45 f.close()
46 continue
47 newhead = regsub.sub(oldcprt, newcprt, head)
48 data = newhead + f.read()
49 f.close()
50 try:
51 f = open(file + '.new', 'w')
52 except IOError, msg:
53 print file, ': creat failed :', msg
54 continue
55 f.write(data)
56 f.close()
57 try:
58 os.rename(file, file + '~')
59 except IOError, msg:
60 print file, ': rename to backup failed :', msg
61 continue
62 try:
63 os.rename(file + '.new', file)
64 except IOError, msg:
65 print file, ': rename from .new failed :', msg
66 continue
67 print file, ': copyright changed.'
68
69main()