Mercurial > cpython-lru_cache-weakref
annotate Misc/Fixcprt.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 73758db2f464 |
| children |
| rev | line source |
|---|---|
|
4573
73758db2f464
/usr/local/bin/python -> /usr/bin/env python
Guido van Rossum <guido@python.org>
parents:
2068
diff
changeset
|
1 #! /usr/bin/env python |
| 1529 | 2 |
| 3 import regex | |
| 4 import regsub | |
| 5 import glob | |
| 6 import sys | |
| 7 import os | |
| 8 import stat | |
| 9 import getopt | |
| 10 | |
|
2068
5227324d64e4
Added 1995 to copyright message; added a few people to acks again...
Guido van Rossum <guido@python.org>
parents:
1529
diff
changeset
|
11 oldcprt = """\ |
|
5227324d64e4
Added 1995 to copyright message; added a few people to acks again...
Guido van Rossum <guido@python.org>
parents:
1529
diff
changeset
|
12 Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum, |
|
5227324d64e4
Added 1995 to copyright message; added a few people to acks again...
Guido van Rossum <guido@python.org>
parents:
1529
diff
changeset
|
13 Amsterdam, The Netherlands.""" |
|
5227324d64e4
Added 1995 to copyright message; added a few people to acks again...
Guido van Rossum <guido@python.org>
parents:
1529
diff
changeset
|
14 newcprt = """\ |
|
5227324d64e4
Added 1995 to copyright message; added a few people to acks again...
Guido van Rossum <guido@python.org>
parents:
1529
diff
changeset
|
15 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
5227324d64e4
Added 1995 to copyright message; added a few people to acks again...
Guido van Rossum <guido@python.org>
parents:
1529
diff
changeset
|
16 The Netherlands.""" |
| 1529 | 17 |
| 18 oldprog = regex.compile(oldcprt) | |
| 19 newprog = regex.compile(newcprt) | |
| 20 | |
|
2068
5227324d64e4
Added 1995 to copyright message; added a few people to acks again...
Guido van Rossum <guido@python.org>
parents:
1529
diff
changeset
|
21 HEADSIZE = 1024 |
|
5227324d64e4
Added 1995 to copyright message; added a few people to acks again...
Guido van Rossum <guido@python.org>
parents:
1529
diff
changeset
|
22 |
| 1529 | 23 def main(): |
| 24 opts, args = getopt.getopt(sys.argv[1:], 'y:') | |
| 25 agelimit = 0L | |
| 26 for opt, arg in opts: | |
| 27 if opt == '-y': | |
| 28 agelimit = os.stat(arg)[stat.ST_MTIME] | |
| 29 if not args: | |
| 30 args = glob.glob('*.[ch]') | |
| 31 for file in args: | |
| 32 try: | |
| 33 age = os.stat(file)[stat.ST_MTIME] | |
| 34 except os.error, msg: | |
| 35 print file, ': stat failed :', msg | |
| 36 continue | |
| 37 if age <= agelimit: | |
| 38 print file, ': too old, skipped' | |
| 39 continue | |
| 40 try: | |
| 41 f = open(file, 'r') | |
| 42 except IOError, msg: | |
| 43 print file, ': open failed :', msg | |
| 44 continue | |
|
2068
5227324d64e4
Added 1995 to copyright message; added a few people to acks again...
Guido van Rossum <guido@python.org>
parents:
1529
diff
changeset
|
45 head = f.read(HEADSIZE) |
| 1529 | 46 if oldprog.search(head) < 0: |
| 47 if newprog.search(head) < 0: | |
| 48 print file, ': NO COPYRIGHT FOUND' | |
| 49 else: | |
| 50 print file, ': (new copyright already there)' | |
| 51 f.close() | |
| 52 continue | |
| 53 newhead = regsub.sub(oldcprt, newcprt, head) | |
| 54 data = newhead + f.read() | |
| 55 f.close() | |
| 56 try: | |
| 57 f = open(file + '.new', 'w') | |
| 58 except IOError, msg: | |
| 59 print file, ': creat failed :', msg | |
| 60 continue | |
| 61 f.write(data) | |
| 62 f.close() | |
| 63 try: | |
| 64 os.rename(file, file + '~') | |
| 65 except IOError, msg: | |
| 66 print file, ': rename to backup failed :', msg | |
| 67 continue | |
| 68 try: | |
| 69 os.rename(file + '.new', file) | |
| 70 except IOError, msg: | |
| 71 print file, ': rename from .new failed :', msg | |
| 72 continue | |
| 73 print file, ': copyright changed.' | |
| 74 | |
| 75 main() |
