1996-11-27 20:52:01 +01:00
|
|
|
#! /usr/bin/env python
|
1991-12-18 14:38:27 +01:00
|
|
|
# Check that all ".pyc" files exist and are up-to-date
|
1992-03-30 13:15:26 +02:00
|
|
|
# Uses module 'os'
|
1991-12-18 14:38:27 +01:00
|
|
|
|
|
|
|
import sys
|
1992-03-30 13:15:26 +02:00
|
|
|
import os
|
1991-12-18 14:38:27 +01:00
|
|
|
from stat import ST_MTIME
|
1998-10-07 21:45:33 +02:00
|
|
|
import imp
|
1991-12-18 14:38:27 +01:00
|
|
|
|
|
|
|
def main():
|
2001-01-17 09:48:39 +01:00
|
|
|
silent = 0
|
|
|
|
verbose = 0
|
|
|
|
if sys.argv[1:]:
|
|
|
|
if sys.argv[1] == '-v':
|
|
|
|
verbose = 1
|
|
|
|
elif sys.argv[1] == '-s':
|
|
|
|
silent = 1
|
|
|
|
MAGIC = imp.get_magic()
|
|
|
|
if not silent:
|
2004-02-12 18:35:32 +01:00
|
|
|
print 'Using MAGIC word', repr(MAGIC)
|
2001-01-17 09:48:39 +01:00
|
|
|
for dirname in sys.path:
|
|
|
|
try:
|
|
|
|
names = os.listdir(dirname)
|
|
|
|
except os.error:
|
2004-02-12 18:35:32 +01:00
|
|
|
print 'Cannot list directory', repr(dirname)
|
2001-01-17 09:48:39 +01:00
|
|
|
continue
|
|
|
|
if not silent:
|
2004-02-12 18:35:32 +01:00
|
|
|
print 'Checking ', repr(dirname), '...'
|
2001-01-17 09:48:39 +01:00
|
|
|
names.sort()
|
|
|
|
for name in names:
|
|
|
|
if name[-3:] == '.py':
|
|
|
|
name = os.path.join(dirname, name)
|
|
|
|
try:
|
|
|
|
st = os.stat(name)
|
|
|
|
except os.error:
|
2004-02-12 18:35:32 +01:00
|
|
|
print 'Cannot stat', repr(name)
|
2001-01-17 09:48:39 +01:00
|
|
|
continue
|
|
|
|
if verbose:
|
2004-02-12 18:35:32 +01:00
|
|
|
print 'Check', repr(name), '...'
|
2001-01-17 09:48:39 +01:00
|
|
|
name_c = name + 'c'
|
|
|
|
try:
|
|
|
|
f = open(name_c, 'r')
|
|
|
|
except IOError:
|
2004-02-12 18:35:32 +01:00
|
|
|
print 'Cannot open', repr(name_c)
|
2001-01-17 09:48:39 +01:00
|
|
|
continue
|
|
|
|
magic_str = f.read(4)
|
|
|
|
mtime_str = f.read(4)
|
|
|
|
f.close()
|
|
|
|
if magic_str <> MAGIC:
|
|
|
|
print 'Bad MAGIC word in ".pyc" file',
|
2004-02-12 18:35:32 +01:00
|
|
|
print repr(name_c)
|
2001-01-17 09:48:39 +01:00
|
|
|
continue
|
|
|
|
mtime = get_long(mtime_str)
|
|
|
|
if mtime == 0 or mtime == -1:
|
2004-02-12 18:35:32 +01:00
|
|
|
print 'Bad ".pyc" file', repr(name_c)
|
2001-01-17 09:48:39 +01:00
|
|
|
elif mtime <> st[ST_MTIME]:
|
|
|
|
print 'Out-of-date ".pyc" file',
|
2004-02-12 18:35:32 +01:00
|
|
|
print repr(name_c)
|
1991-12-18 14:38:27 +01:00
|
|
|
|
|
|
|
def get_long(s):
|
2001-01-17 09:48:39 +01:00
|
|
|
if len(s) <> 4:
|
|
|
|
return -1
|
|
|
|
return ord(s[0]) + (ord(s[1])<<8) + (ord(s[2])<<16) + (ord(s[3])<<24)
|
1991-12-18 14:38:27 +01:00
|
|
|
|
|
|
|
main()
|