blob: 469e9c6845cc8bf1bfeaed1ca9c21b8b160c0785 [file] [log] [blame]
Guido van Rossum7045dd01991-08-16 13:28:28 +00001# Utility module to import all modules in the path, in the hope
2# that this will update their ".pyc" files.
3
4# First, see if this is the Mac or UNIX
5try:
6 import posix
7 os = posix
8 import path
Guido van Rossumaa3760d1991-12-26 13:05:14 +00009except ImportError:
Guido van Rossum7045dd01991-08-16 13:28:28 +000010 import mac
11 os = mac
12 import macpath
13 path = macpath
14
15import sys
16
Guido van Rossumd4e5a731992-01-01 19:30:14 +000017# Sabotage 'gl' and 'stdwin' to prevent windows popping up...
18for m in 'gl', 'stdwin', 'fl', 'fm':
19 sys.modules[m] = sys
20
Guido van Rossum7045dd01991-08-16 13:28:28 +000021exceptions = ['importall']
22
23for dir in sys.path:
24 print 'Listing', dir
25 try:
26 names = os.listdir(dir)
27 except os.error:
28 print 'Can\'t list', dir
29 names = []
30 names.sort()
31 for name in names:
32 head, tail = name[:-3], name[-3:]
Guido van Rossumd4e5a731992-01-01 19:30:14 +000033 if tail == '.py' and head not in exceptions:
Guido van Rossum7045dd01991-08-16 13:28:28 +000034 s = 'import ' + head
35 print s
36 try:
37 exec(s + '\n')
Guido van Rossumd4e5a731992-01-01 19:30:14 +000038 except KeyboardInterrupt:
39 del names[:]
40 print '\n[interrupt]'
41 break
Guido van Rossum7045dd01991-08-16 13:28:28 +000042 except:
Guido van Rossumd4e5a731992-01-01 19:30:14 +000043 print 'Sorry:', sys.exc_type + ':',
44 print sys.exc_value