blob: 1d20377105816bce29f99f58187d3349eb6a72d3 [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
Guido van Rossumbf1710a1992-03-31 19:06:54 +00004import os
Guido van Rossum7045dd01991-08-16 13:28:28 +00005import sys
6
Guido van Rossumd4e5a731992-01-01 19:30:14 +00007# Sabotage 'gl' and 'stdwin' to prevent windows popping up...
8for m in 'gl', 'stdwin', 'fl', 'fm':
9 sys.modules[m] = sys
10
Guido van Rossum7045dd01991-08-16 13:28:28 +000011exceptions = ['importall']
12
13for dir in sys.path:
14 print 'Listing', dir
15 try:
16 names = os.listdir(dir)
17 except os.error:
18 print 'Can\'t list', dir
19 names = []
20 names.sort()
21 for name in names:
22 head, tail = name[:-3], name[-3:]
Guido van Rossumd4e5a731992-01-01 19:30:14 +000023 if tail == '.py' and head not in exceptions:
Guido van Rossum7045dd01991-08-16 13:28:28 +000024 s = 'import ' + head
25 print s
26 try:
27 exec(s + '\n')
Guido van Rossumd4e5a731992-01-01 19:30:14 +000028 except KeyboardInterrupt:
29 del names[:]
30 print '\n[interrupt]'
31 break
Guido van Rossum7045dd01991-08-16 13:28:28 +000032 except:
Guido van Rossumd4e5a731992-01-01 19:30:14 +000033 print 'Sorry:', sys.exc_type + ':',
34 print sys.exc_value