Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/checkpyc.py @ 6719:faebc1940432 legacy-trunk
Understand -Xlinker option.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 02 Dec 1997 20:38:11 +0000 |
| parents | 73758db2f464 |
| children | 0de662cecacf |
| rev | line source |
|---|---|
|
4573
73758db2f464
/usr/local/bin/python -> /usr/bin/env python
Guido van Rossum <guido@python.org>
parents:
1506
diff
changeset
|
1 #! /usr/bin/env python |
| 500 | 2 # Check that all ".pyc" files exist and are up-to-date |
| 758 | 3 # Uses module 'os' |
| 500 | 4 |
| 5 import sys | |
| 758 | 6 import os |
| 500 | 7 from stat import ST_MTIME |
| 8 | |
| 9 def main(): | |
| 10 silent = 0 | |
| 11 verbose = 0 | |
| 12 if sys.argv[1:]: | |
| 559 | 13 if sys.argv[1] == '-v': |
| 500 | 14 verbose = 1 |
| 559 | 15 elif sys.argv[1] == '-s': |
| 500 | 16 silent = 1 |
| 17 MAGIC = '\0\0\0\0' | |
| 18 try: | |
| 19 if sys.version[:5] >= '0.9.4': | |
| 20 MAGIC = '\224\224\224\0' | |
| 21 except: | |
| 22 pass | |
| 23 if not silent: | |
| 24 print 'Using MAGIC word', `MAGIC` | |
| 25 for dirname in sys.path: | |
| 26 try: | |
| 758 | 27 names = os.listdir(dirname) |
| 28 except os.error: | |
| 500 | 29 print 'Cannot list directory', `dirname` |
| 30 continue | |
| 31 if not silent: | |
| 32 print 'Checking', `dirname`, '...' | |
| 33 names.sort() | |
| 34 for name in names: | |
| 559 | 35 if name[-3:] == '.py': |
| 758 | 36 name = os.path.join(dirname, name) |
| 500 | 37 try: |
| 758 | 38 st = os.stat(name) |
| 39 except os.error: | |
| 500 | 40 print 'Cannot stat', `name` |
| 41 continue | |
| 42 if verbose: | |
| 43 print 'Check', `name`, '...' | |
| 44 name_c = name + 'c' | |
| 45 try: | |
| 46 f = open(name_c, 'r') | |
| 47 except IOError: | |
| 48 print 'Cannot open', `name_c` | |
| 49 continue | |
| 50 magic_str = f.read(4) | |
| 51 mtime_str = f.read(4) | |
| 52 f.close() | |
| 53 if magic_str <> MAGIC: | |
| 54 print 'Bad MAGIC word in ".pyc" file', | |
| 55 print `name_c` | |
| 56 continue | |
| 57 mtime = get_long(mtime_str) | |
| 559 | 58 if mtime == 0 or mtime == -1: |
| 500 | 59 print 'Bad ".pyc" file', `name_c` |
| 60 elif mtime <> st[ST_MTIME]: | |
| 61 print 'Out-of-date ".pyc" file', | |
| 62 print `name_c` | |
| 63 | |
| 64 def get_long(s): | |
| 65 if len(s) <> 4: | |
| 66 return -1 | |
| 67 return ord(s[0]) + (ord(s[1])<<8) + (ord(s[2])<<16) + (ord(s[3])<<24) | |
| 68 | |
| 69 main() |
