Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/checkpyc.py @ 15164:8930ec3bc00a legacy-trunk
Added additional test cases for pulldom modifications.
| author | Lars Gustäbel <lars@gustaebel.de> |
|---|---|
| date | Wed, 11 Oct 2000 22:36:00 +0000 |
| parents | 0de662cecacf |
| children | 14a27acc755a |
| 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 |
|
9294
0de662cecacf
Use the imp module to get the magic word.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
8 import imp |
| 500 | 9 |
| 10 def main(): | |
| 11 silent = 0 | |
| 12 verbose = 0 | |
| 13 if sys.argv[1:]: | |
| 559 | 14 if sys.argv[1] == '-v': |
| 500 | 15 verbose = 1 |
| 559 | 16 elif sys.argv[1] == '-s': |
| 500 | 17 silent = 1 |
|
9294
0de662cecacf
Use the imp module to get the magic word.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
18 MAGIC = imp.get_magic() |
| 500 | 19 if not silent: |
| 20 print 'Using MAGIC word', `MAGIC` | |
| 21 for dirname in sys.path: | |
| 22 try: | |
| 758 | 23 names = os.listdir(dirname) |
| 24 except os.error: | |
| 500 | 25 print 'Cannot list directory', `dirname` |
| 26 continue | |
| 27 if not silent: | |
| 28 print 'Checking', `dirname`, '...' | |
| 29 names.sort() | |
| 30 for name in names: | |
| 559 | 31 if name[-3:] == '.py': |
| 758 | 32 name = os.path.join(dirname, name) |
| 500 | 33 try: |
| 758 | 34 st = os.stat(name) |
| 35 except os.error: | |
| 500 | 36 print 'Cannot stat', `name` |
| 37 continue | |
| 38 if verbose: | |
| 39 print 'Check', `name`, '...' | |
| 40 name_c = name + 'c' | |
| 41 try: | |
| 42 f = open(name_c, 'r') | |
| 43 except IOError: | |
| 44 print 'Cannot open', `name_c` | |
| 45 continue | |
| 46 magic_str = f.read(4) | |
| 47 mtime_str = f.read(4) | |
| 48 f.close() | |
| 49 if magic_str <> MAGIC: | |
| 50 print 'Bad MAGIC word in ".pyc" file', | |
| 51 print `name_c` | |
| 52 continue | |
| 53 mtime = get_long(mtime_str) | |
| 559 | 54 if mtime == 0 or mtime == -1: |
| 500 | 55 print 'Bad ".pyc" file', `name_c` |
| 56 elif mtime <> st[ST_MTIME]: | |
| 57 print 'Out-of-date ".pyc" file', | |
| 58 print `name_c` | |
| 59 | |
| 60 def get_long(s): | |
| 61 if len(s) <> 4: | |
| 62 return -1 | |
| 63 return ord(s[0]) + (ord(s[1])<<8) + (ord(s[2])<<16) + (ord(s[3])<<24) | |
| 64 | |
| 65 main() |
