1
#! /usr/bin/env python3
2
# Check that all ".pyc" files exist and are up-to-date
7
from stat import ST_MTIME
10
# PEP 3147 compatibility (PYC Repository Directories)
11
cache_from_source = (importlib.util.cache_from_source if sys.implementation.cache_tag
12
else lambda path: path + 'c')
17
verbose = (sys.argv[1] == '-v')
18
silent = (sys.argv[1] == '-s')
20
verbose = silent = False
21
MAGIC = importlib.util.MAGIC_NUMBER
23
print('Using MAGIC word', repr(MAGIC))
24
for dirname in sys.path:
26
names = os.listdir(dirname)
28
print('Cannot list directory', repr(dirname))
31
print('Checking ', repr(dirname), '...')
32
for name in sorted(names):
33
if name.endswith('.py'):
34
name = os.path.join(dirname, name)
38
print('Cannot stat', repr(name))
41
print('Check', repr(name), '...')
42
name_c = cache_from_source(name)
44
with open(name_c, 'rb') as f:
48
print('Cannot open', repr(name_c))
50
if magic_str != MAGIC:
51
print('Bad MAGIC word in ".pyc" file', end=' ')
54
mtime = get_long(mtime_str)
56
print('Bad ".pyc" file', repr(name_c))
57
elif mtime != st[ST_MTIME]:
58
print('Out-of-date ".pyc" file', end=' ')
65
return s[0] + (s[1] << 8) + (s[2] << 16) + (s[3] << 24)
68
if __name__ == '__main__':